summaryrefslogtreecommitdiffstats
path: root/src/zabbix_agent
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-02-05 16:33:53 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-02-05 16:33:53 +0000
commitb06870a3d08c9db78c11ddabadd14c500ee8bfbb (patch)
tree1963514a3a0528bd6a522992254fcc1294bddc33 /src/zabbix_agent
parent2262f9ba9db7d6a54c411488d7fd44a0755c7c0b (diff)
downloadzabbix-b06870a3d08c9db78c11ddabadd14c500ee8bfbb.tar.gz
zabbix-b06870a3d08c9db78c11ddabadd14c500ee8bfbb.tar.xz
zabbix-b06870a3d08c9db78c11ddabadd14c500ee8bfbb.zip
- support for unlimited number of user parameters (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@1651 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_agent')
-rw-r--r--src/zabbix_agent/sysinfo.c64
-rw-r--r--src/zabbix_agent/sysinfo.h1
-rw-r--r--src/zabbix_agent/zabbix_agent.c2
-rw-r--r--src/zabbix_agent/zabbix_agentd.c2
4 files changed, 56 insertions, 13 deletions
diff --git a/src/zabbix_agent/sysinfo.c b/src/zabbix_agent/sysinfo.c
index 6903fcdb..25283cc2 100644
--- a/src/zabbix_agent/sysinfo.c
+++ b/src/zabbix_agent/sysinfo.c
@@ -127,7 +127,10 @@
void forward_request(char *proxy,char *command,int port,char *value);
-COMMAND commands[AGENT_MAX_USER_COMMANDS]=
+/*COMMAND commands[AGENT_MAX_USER_COMMANDS]=*/
+COMMAND *commands=NULL;
+
+COMMAND agent_commands[]=
/* KEY FUNCTION (if double) FUNCTION (if string) PARAM*/
{
{"kern[maxfiles]" ,KERNEL_MAXFILES, 0, 0},
@@ -251,39 +254,62 @@ COMMAND commands[AGENT_MAX_USER_COMMANDS]=
{0}
};
+void add_metric(char *key, void *function,void *function_str,char *parameter )
+{
+
+ int i;
+
+ for(i=0;;i++)
+ {
+ if(commands[i].key == NULL)
+ {
+
+ commands[i].key=strdup(key);
+ if(parameter == NULL)
+ {
+ commands[i].parameter=NULL;
+ }
+ else
+ {
+ commands[i].parameter=strdup(parameter);
+ }
+ commands[i].function=function;
+ commands[i].function_str=function_str;
+
+ commands=realloc(commands,(i+2)*sizeof(COMMAND));
+ commands[i+1].key=NULL;
+ break;
+ }
+ }
+}
+
void add_user_parameter(char *key,char *command)
{
int i;
- for(i=0;i<AGENT_MAX_USER_COMMANDS;i++)
+ for(i=0;;i++)
{
if( commands[i].key == 0)
{
commands[i].key=strdup(key);
-
commands[i].function=0;
-
commands[i].function_str=&EXECUTE_STR;
-
commands[i].parameter=strdup(command);
- commands[i+1].key = 0;
-
+ commands=realloc(commands,(i+2)*sizeof(COMMAND));
+ commands[i+1].key=NULL;
+
break;
}
/* Replace existing parameters */
if(strcmp(commands[i].key, key) == 0)
{
- /* Can we free this? I don't know/ */
-/* free(commands[i].key);
- free(commands[i].key);*/
+ free(commands[i].key);
+ if(commands[i].parameter!=NULL) free(commands[i].parameter);
commands[i].key=strdup(key);
-
commands[i].function=0;
-
commands[i].function_str=&EXECUTE_STR;
-
commands[i].parameter=strdup(command);
break;
@@ -291,6 +317,18 @@ void add_user_parameter(char *key,char *command)
}
}
+void init_metrics()
+{
+ int i;
+
+ commands=malloc(sizeof(COMMAND));
+ commands[0].key=NULL;
+
+ for(i=0;agent_commands[i].key!=0;i++)
+ {
+ add_metric(agent_commands[i].key, agent_commands[i].function, agent_commands[i].function_str, agent_commands[i].parameter);
+ }
+}
void escape_string(char *from, char *to, int maxlen)
{
diff --git a/src/zabbix_agent/sysinfo.h b/src/zabbix_agent/sysinfo.h
index 3f6d888c..bacd9cce 100644
--- a/src/zabbix_agent/sysinfo.h
+++ b/src/zabbix_agent/sysinfo.h
@@ -39,6 +39,7 @@ COMMAND
void process(char *command, char *value);
+void init_metrics();
void add_user_parameter(char *key,char *command);
void test_parameters(void);
diff --git a/src/zabbix_agent/zabbix_agent.c b/src/zabbix_agent/zabbix_agent.c
index ed716a12..8fcdac2d 100644
--- a/src/zabbix_agent/zabbix_agent.c
+++ b/src/zabbix_agent/zabbix_agent.c
@@ -107,6 +107,8 @@ int main()
signal( SIGTERM, signal_handler );
signal( SIGALRM, signal_handler );
+/* Must be before init_config() */
+ init_metrics();
init_config();
/* Do not create debug files */
diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c
index 503349b3..af7cad1c 100644
--- a/src/zabbix_agent/zabbix_agentd.c
+++ b/src/zabbix_agent/zabbix_agentd.c
@@ -430,6 +430,8 @@ int main(int argc, char **argv)
break;
}
+/* Must be before init_config() */
+ init_metrics();
init_config();
daemon_init();