diff options
author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-10-27 14:53:50 +0000 |
---|---|---|
committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-10-27 14:53:50 +0000 |
commit | 6428289e52e3d49d04f46440334becdb4dd50eb7 (patch) | |
tree | 76c5bd74e671b0951fac6850cebbd67da6866e6c /src/zabbix_agent | |
parent | bf1417f0196f1ada1616e1e53e04a55117dc06d4 (diff) | |
download | zabbix-6428289e52e3d49d04f46440334becdb4dd50eb7.tar.gz zabbix-6428289e52e3d49d04f46440334becdb4dd50eb7.tar.xz zabbix-6428289e52e3d49d04f46440334becdb4dd50eb7.zip |
- developed new interface for test functions. Result returns with srtuct. (Eugene)
- recreated process() function. (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@2227 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_agent')
-rw-r--r-- | src/zabbix_agent/active.c | 12 | ||||
-rw-r--r-- | src/zabbix_agent/zabbix_agent.c | 33 | ||||
-rw-r--r-- | src/zabbix_agent/zabbix_agentd.c | 34 |
3 files changed, 46 insertions, 33 deletions
diff --git a/src/zabbix_agent/active.c b/src/zabbix_agent/active.c index 44f8c477..525affbc 100644 --- a/src/zabbix_agent/active.c +++ b/src/zabbix_agent/active.c @@ -426,6 +426,8 @@ int process_active_checks(char *server, int port) char c[MAX_STRING_LEN]; char *filename; + AGENT_RESULT result; + now=time(NULL); for(i=0;;i++) @@ -467,7 +469,15 @@ int process_active_checks(char *server, int port) else { lastlogsize[0]=0; - process(metrics[i].key, value, 0); + + process(metrics[i].key, 0, &result); + if(result.type & AR_DOUBLE) + snprintf(value, MAX_STRING_LEN-1, "%f", result.dbl); + 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); /* snprintf(shortname, MAX_STRING_LEN-1,"%s:%s",CONFIG_HOSTNAME,metrics[i].key); zabbix_log( LOG_LEVEL_DEBUG, "%s",shortname); */ diff --git a/src/zabbix_agent/zabbix_agent.c b/src/zabbix_agent/zabbix_agent.c index 996f5c93..ec4e71b0 100644 --- a/src/zabbix_agent/zabbix_agent.c +++ b/src/zabbix_agent/zabbix_agent.c @@ -19,25 +19,6 @@ #include "config.h" -#include <stdlib.h> -#include <stdio.h> - -#include <unistd.h> -#include <signal.h> - -#include <errno.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> - -/* For bcopy */ -#include <string.h> - -/* For config file operations */ -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - #include "common.h" #include "cfg.h" #include "log.h" @@ -95,6 +76,7 @@ int main() { char s[MAX_STRING_LEN]; char value[MAX_STRING_LEN]; + AGENT_RESULT result; #ifdef TEST_PARAMETERS init_metrics(); @@ -123,8 +105,16 @@ int main() } fgets(s,MAX_STRING_LEN,stdin); - process(s,value,0); - + + process(s, 0, &result); + if(result.type & AR_DOUBLE) + snprintf(value, MAX_STRING_LEN-1, "%f", result.dbl); + 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); @@ -133,3 +123,4 @@ int main() return SUCCEED; } + diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c index 1226abf0..fd8cccef 100644 --- a/src/zabbix_agent/zabbix_agentd.c +++ b/src/zabbix_agent/zabbix_agentd.c @@ -239,8 +239,7 @@ void print_supported() void init_config(void) { - char tmp[MAX_STRING_LEN]; - + AGENT_RESULT result; struct cfg_line cfg[]= { /* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX @@ -277,11 +276,16 @@ void init_config(void) if(CONFIG_HOSTNAME == NULL) { - if(SUCCEED == process("system[hostname]",tmp, 0)) + if(SUCCEED == process("system[hostname]", 0, &result)) { - CONFIG_HOSTNAME=strdup(tmp); + if(result.type & AR_STRING) + { + CONFIG_HOSTNAME=strdup(result.str); + } + free_result(&result); } - else + + if(CONFIG_HOSTNAME == NULL) { zabbix_log( LOG_LEVEL_CRIT, "Hostname is not defined"); exit(1); @@ -298,10 +302,11 @@ void process_child(int sockfd) { ssize_t nread; char line[MAX_STRING_LEN]; - char result[MAX_STRING_LEN]; + char value[MAX_STRING_LEN]; int i; - static struct sigaction phan; + static struct sigaction phan; + AGENT_RESULT result; phan.sa_handler = &signal_handler; /* set up sig handler using sigaction() */ sigemptyset(&phan.sa_mask); @@ -332,10 +337,17 @@ void process_child(int sockfd) zabbix_log( LOG_LEVEL_DEBUG, "Got line:%s", line); - process(line,result,0); - - zabbix_log( LOG_LEVEL_DEBUG, "Sending back:%s", result); - i=write(sockfd,result,strlen(result)); + process(line, 0, &result); + if(result.type & AR_DOUBLE) + snprintf(value, MAX_STRING_LEN-1, "%f", result.dbl); + 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); + + zabbix_log( LOG_LEVEL_DEBUG, "Sending back:%s", value); + i=write(sockfd, value, strlen(value)); if(i == -1) { zabbix_log( LOG_LEVEL_WARNING, "Error writing to socket [%s]", |