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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
** ZABBIX
** Copyright (C) 2000-2005 SIA Zabbix
**
** 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 2 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, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
#include "common.h"
#include "zbxconf.h"
#include "cfg.h"
#include "log.h"
#include "alias.h"
#include "sysinfo.h"
#include "perfstat.h"
#if defined(ZABBIX_DAEMON)
/* use pid file configureation */
# include "daemon.h"
#endif /* ZABBIX_DAEMON */
#if defined(WITH_PLUGINS)
/* use ZABBIX plugins configurations */
# include "zbxplugin.h"
#endif /* WITH_PLUGINS */
#ifdef USE_PID_FILE
static char DEFAULT_PID_FILE[] = "/tmp/zabbix_agentd.pid";
#endif /* USE_PID_FILE */
char *CONFIG_HOSTS_ALLOWED = NULL;
char *CONFIG_HOSTNAME = NULL;
int CONFIG_DISABLE_ACTIVE = 0;
int CONFIG_ENABLE_REMOTE_COMMANDS = 0;
int CONFIG_LISTEN_PORT = 10050;
int CONFIG_SERVER_PORT = 10051;
int CONFIG_REFRESH_ACTIVE_CHECKS = 120;
char *CONFIG_LISTEN_IP = NULL;
int CONFIG_LOG_LEVEL = LOG_LEVEL_INFORMATION;
char CONFIG_LOG_UNRES_SYMB = 0;
int CONFIG_BUFFER_SIZE = 100;
int CONFIG_BUFFER_SEND = 5;
void load_config()
{
struct cfg_line cfg[]=
{
/* PARAMETER ,VAR ,FUNC, TYPE(0i,1s), MANDATORY, MIN, MAX
*/
{"Server", &CONFIG_HOSTS_ALLOWED, 0,TYPE_STRING, PARM_MAND, 0,0},
{"Hostname", &CONFIG_HOSTNAME, 0,TYPE_STRING, PARM_OPT, 0,0},
{"BufferSize", &CONFIG_BUFFER_SIZE, 0,TYPE_INT, PARM_OPT, 1,65535},
{"BufferSend", &CONFIG_BUFFER_SEND, 0,TYPE_INT, PARM_OPT, 1,3600},
#ifdef USE_PID_FILE
{"PidFile", &APP_PID_FILE, 0,TYPE_STRING, PARM_OPT, 0,0},
#endif /* USE_PID_FILE */
{"LogFile", &CONFIG_LOG_FILE, 0,TYPE_STRING, PARM_OPT, 0,0},
{"LogFileSize", &CONFIG_LOG_FILE_SIZE, 0,TYPE_INT, PARM_OPT, 0,1024},
{"DisableActive", &CONFIG_DISABLE_ACTIVE, 0,TYPE_INT, PARM_OPT, 0,1},
{"Timeout", &CONFIG_TIMEOUT, 0,TYPE_INT, PARM_OPT, 1,30},
{"ListenPort", &CONFIG_LISTEN_PORT, 0,TYPE_INT, PARM_OPT, 1024,32767},
{"ServerPort", &CONFIG_SERVER_PORT, 0,TYPE_INT, PARM_OPT, 1024,32767},
{"ListenIP", &CONFIG_LISTEN_IP, 0,TYPE_STRING, PARM_OPT, 0,0},
{"DebugLevel", &CONFIG_LOG_LEVEL, 0,TYPE_INT, PARM_OPT, 0,5},
{"StartAgents", &CONFIG_ZABBIX_FORKS, 0,TYPE_INT, PARM_OPT, 1,16},
{"RefreshActiveChecks", &CONFIG_REFRESH_ACTIVE_CHECKS, 0,TYPE_INT, PARM_OPT,60,3600},
{"AllowRoot", &CONFIG_ALLOW_ROOT, 0,TYPE_INT, PARM_OPT,0,1},
{"LogUnresolvedSymbols",&CONFIG_LOG_UNRES_SYMB, 0, TYPE_STRING,PARM_OPT,0,1},
{0}
};
AGENT_RESULT result;
char **value = NULL;
memset(&result, 0, sizeof(AGENT_RESULT));
parse_cfg_file(CONFIG_FILE, cfg);
#ifdef USE_PID_FILE
if(APP_PID_FILE == NULL)
{
APP_PID_FILE = DEFAULT_PID_FILE;
}
#endif /* USE_PID_FILE */
if(CONFIG_HOSTNAME == NULL)
{
if(SUCCEED == process("system.hostname", 0, &result))
{
if( NULL != (value = GET_STR_RESULT(&result)) )
{
CONFIG_HOSTNAME = strdup(*value);
}
}
free_result(&result);
if(CONFIG_HOSTNAME == NULL)
{
zabbix_log( LOG_LEVEL_CRIT, "Hostname is not defined");
exit(1);
}
}
}
static int add_parameter(char *key)
{
char *command;
command = strstr(key,",");
if(NULL == command)
{
return FAIL;
}
command[0]=0;
command++;
add_user_parameter(key, command);
return SUCCEED;
}
void load_user_parameters(void)
{
struct cfg_line cfg[]=
{
/* PARAMETER, VAR, FUNC, TYPE(0i,1s), MANDATORY,MIN,MAX
*/
{"EnableRemoteCommands",&CONFIG_ENABLE_REMOTE_COMMANDS, 0,TYPE_INT, PARM_OPT,0,1},
{"Alias", 0, &add_alias_from_config, TYPE_STRING,PARM_OPT,0,0},
{"UserParameter", 0, &add_parameter, 0, 0, 0, 0},
#if defined(_WINDOWS)
{"PerfCounter", 0, &add_perfs_from_config, TYPE_STRING,PARM_OPT,0,0},
#endif /* _WINDOWS */
#if defined(WITH_PLUGINS)
{"Plugin", 0, &add_plugin, TYPE_STRING,PARM_OPT,0,0},
#endif /* ZABBIX_DAEMON */
{0}
};
parse_cfg_file(CONFIG_FILE,cfg);
}
|