summaryrefslogtreecommitdiff
path: root/src/bin/conf.c
blob: f60be691fe71610046d361909b93f658e604260b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright © 2013 Guillaume Friloux <kuri@efl.so>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/**
 * @file conf.c
 * @brief Manages configuration loading
 * @author Guillaume Friloux <kuri@efl.so>
 * @version 1.0
 *
 * Manages configuration loading
 */
#include "conf.h"

/**
 * @fn int conf_load(void)
 * @brief This function will init libconf and ask to load our configuration
 *  file
 *
 * @return 0
 */
int conf_load(void)
{
	struct libconfig myconf;

	strcpy(global_ESserver, "http://192.168.2.84:9200/logstash/events/");
	strcpy(global_rulesdir, "/etc/smman/rules.d/");
	strcpy(global_conf, "/etc/smman/smman.conf");
	strcpy(global_type, "syslog");
	gethostname(global_host, sizeof(global_host));

	einadom_rules    = eina_log_domain_register("smman_rules"   , EINA_COLOR_LIGHTRED);
	einadom_spy      = eina_log_domain_register("smman_spy"     , EINA_COLOR_LIGHTRED);
	einadom_logfiles = eina_log_domain_register("smman_logfiles", EINA_COLOR_LIGHTRED);
	einadom_send     = eina_log_domain_register("smman_send"    , EINA_COLOR_LIGHTRED);
	einadom_conf     = eina_log_domain_register("smman_conf"    , EINA_COLOR_LIGHTRED);

	libconfig_init(global_conf, &myconf);
	libconfig_load(&myconf);

	libconfig_list(&myconf, conf_load_var);

	libconfig_free(&myconf);
	return(0);
}

/**
 * @fn int conf_load_var(char *variable, char *value)
 * @brief This function is a callback for libconf, and receives a variable +
 *  its value found in a configuration file
 *
 * @param variable (char *) Variable's name
 * @param value (char *) Variable's value
 *
 * @return 0
 */
int conf_load_var(char *variable, char *value)
{
	if( !strcmp(variable, "server") )
	{
		EINA_LOG_DOM_DBG(einadom_conf, "Setting ES server to %s", variable);
		strcpy(global_ESserver, value);
	}
	else if( !strcmp(variable, "host") )
	{
		EINA_LOG_DOM_DBG(einadom_conf, "Setting default hostname to %s", variable);
		strcpy(global_host, value);
	}
	else if( !strcmp(variable, "type") )
	{
		EINA_LOG_DOM_DBG(einadom_conf, "Setting default type to %s", variable);
		strcpy(global_type, value);
	}
	else
	{
		EINA_LOG_DOM_ERR(einadom_conf, "Unknown config variable %s", variable);
	}

	return(0);
}