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
|
/*
** 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 "config.h"
#include "common.h"
#include "cfg.h"
#include "log.h"
#include "sysinfo.h"
#include "security.h"
#include "zabbix_agent.h"
static char *CONFIG_HOSTS_ALLOWED = NULL;
static int CONFIG_TIMEOUT = AGENT_TIMEOUT;
int CONFIG_ENABLE_REMOTE_COMMANDS = 0;
void signal_handler( int sig )
{
if( SIGALRM == sig )
{
signal( SIGALRM, signal_handler );
}
if( SIGQUIT == sig || SIGINT == sig || SIGTERM == sig )
{
}
exit( FAIL );
}
int add_parameter(char *value)
{
char *value2;
value2=strstr(value,",");
if(NULL == value2)
{
return FAIL;
}
value2[0]=0;
value2++;
add_user_parameter(value, value2);
return SUCCEED;
}
void init_config(void)
{
struct cfg_line cfg[]=
{
/* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX
*/
{"Server",&CONFIG_HOSTS_ALLOWED,0,TYPE_STRING,PARM_MAND,0,0},
{"Timeout",&CONFIG_TIMEOUT,0,TYPE_INT,PARM_OPT,1,30},
{"UserParameter",0,&add_parameter,0,0,0,0},
{0}
};
parse_cfg_file("/etc/zabbix/zabbix_agent.conf",cfg);
}
int main()
{
char s[MAX_STRING_LEN];
char value[MAX_STRING_LEN];
AGENT_RESULT result;
memset(&result, 0, sizeof(AGENT_RESULT));
#ifdef TEST_PARAMETERS
init_metrics();
/* init_config();*/
test_parameters();
return SUCCEED;
#endif
signal( SIGINT, signal_handler );
signal( SIGQUIT, signal_handler );
signal( SIGTERM, signal_handler );
signal( SIGALRM, signal_handler );
/* Must be before init_config() */
init_metrics();
init_config();
/* Do not create debug files */
zabbix_open_log(LOG_TYPE_SYSLOG,LOG_LEVEL_EMPTY,NULL);
alarm(CONFIG_TIMEOUT);
if(check_security(0,CONFIG_HOSTS_ALLOWED,0) == FAIL)
{
exit(FAIL);
}
fgets(s,MAX_STRING_LEN,stdin);
process(s, 0, &result);
if(result.type & AR_DOUBLE)
snprintf(value, MAX_STRING_LEN-1, "%f", result.dbl);
else if(result.type & AR_UINT64)
snprintf(value, MAX_STRING_LEN-1, ZBX_FS_UI64, result.ui64);
else if(result.type & AR_STRING)
snprintf(value, MAX_STRING_LEN-1, "%s", result.str);
else if(result.type & AR_MESSAGE)
snprintf(value, MAX_STRING_LEN-1, "%s", result.msg);
free_result(&result);
printf("%s\n",value);
fflush(stdout);
alarm(0);
return SUCCEED;
}
|