diff options
author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-05-01 07:16:48 +0000 |
---|---|---|
committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-05-01 07:16:48 +0000 |
commit | 4cb48b6cf45cf7d7000cd76ea3634a21e1042c54 (patch) | |
tree | 974d66a31fd9bc7f07bda2ca3567e0b8f84e92d0 | |
parent | 7d54eb242f408269546d2e9c48ee23ce4f58f5bf (diff) | |
download | zabbix-4cb48b6cf45cf7d7000cd76ea3634a21e1042c54.tar.gz zabbix-4cb48b6cf45cf7d7000cd76ea3634a21e1042c54.tar.xz zabbix-4cb48b6cf45cf7d7000cd76ea3634a21e1042c54.zip |
More support for active checks.
git-svn-id: svn://svn.zabbix.com/trunk@1739 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r-- | include/functions.c | 4 | ||||
-rw-r--r-- | include/functions.h | 2 | ||||
-rw-r--r-- | misc/conf/zabbix_agentd.conf | 6 | ||||
-rw-r--r-- | src/zabbix_agent/active.c | 69 | ||||
-rw-r--r-- | src/zabbix_agent/active.h | 3 | ||||
-rw-r--r-- | src/zabbix_agent/zabbix_agentd.c | 28 | ||||
-rw-r--r-- | src/zabbix_server/server.c | 1 | ||||
-rw-r--r-- | src/zabbix_server/trapper.c | 8 |
8 files changed, 95 insertions, 26 deletions
diff --git a/include/functions.c b/include/functions.c index c10bad26..4e58758e 100644 --- a/include/functions.c +++ b/include/functions.c @@ -2203,7 +2203,7 @@ int get_lastvalue(char *value,char *host,char *key,char *function,char *paramete } /* For zabbix_trapper(d) */ -int send_list_of_active_checks(int sockfd) +int send_list_of_active_checks(int sockfd, char *host) { char sql[MAX_STRING_LEN]; char s[MAX_STRING_LEN]; @@ -2213,7 +2213,7 @@ int send_list_of_active_checks(int sockfd) zabbix_log( LOG_LEVEL_DEBUG, "In send_list_of_active_checks()"); - snprintf(sql,sizeof(sql)-1,"select i.key_,i.delay from items i,hosts h where i.hostid=h.hostid and h.status=%d and i.status=%d and i.type=%d", HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, ITEM_TYPE_ZABBIX_ACTIVE); + snprintf(sql,sizeof(sql)-1,"select i.key_,i.delay from items i,hosts h where i.hostid=h.hostid and h.status=%d and i.status=%d and i.type=%d and h.host='%s'", HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, ITEM_TYPE_ZABBIX_ACTIVE, host); result = DBselect(sql); diff --git a/include/functions.h b/include/functions.h index 0c7d3d37..1100259e 100644 --- a/include/functions.h +++ b/include/functions.h @@ -31,7 +31,7 @@ void update_triggers (int itemid); int get_lastvalue(char *value,char *host,char *key,char *function,char *parameter); int process_data(int sockfd,char *server,char *key, char *value); void process_new_value(DB_ITEM *item,char *value); -int send_list_of_active_checks(int sockfd); +int send_list_of_active_checks(int sockfd, char *host); #ifdef ZABBIX_THREADS void update_triggers_thread(MYSQL *database, int itemid); diff --git a/misc/conf/zabbix_agentd.conf b/misc/conf/zabbix_agentd.conf index 784bed50..0cb5c273 100644 --- a/misc/conf/zabbix_agentd.conf +++ b/misc/conf/zabbix_agentd.conf @@ -3,10 +3,14 @@ ############ GENERAL PARAMETERS ################# -# IP address of ZABBIX server. No spaces allowed. +# List of comma delimited IP addresses of ZABBIX servers. No spaces allowed. Server=127.0.0.1 +# Unique hostname. Required for active checks. + +Hostname=localhost + # Listen port. Default is 10050 #ListenPort=10050 diff --git a/src/zabbix_agent/active.c b/src/zabbix_agent/active.c index c58745a4..a7dbb7ff 100644 --- a/src/zabbix_agent/active.c +++ b/src/zabbix_agent/active.c @@ -27,6 +27,8 @@ #include <unistd.h> #include <signal.h> +#include <time.h> + #include <errno.h> #include <sys/socket.h> #include <netinet/in.h> @@ -59,6 +61,30 @@ METRIC *metrics=NULL; +int get_min_nextcheck() +{ + int i; + int min=-1; + int nodata=0; + + for(i=0;;i++) + { + if(metrics[i].key == NULL) break; + + nodata=1; + if( (metrics[i].nextcheck < min) || (min == -1)) + { + min=metrics[i].nextcheck; + } + } + + if(nodata==0) + { + return FAIL; + } + return min; +} + void add_check(char *key, int refresh) { @@ -71,6 +97,7 @@ void add_check(char *key, int refresh) metrics[i].key=strdup(key); metrics[i].refresh=refresh; + metrics[i].nextcheck=0; metrics[i].status=ITEM_STATUS_ACTIVE; metrics=realloc(metrics,(i+2)*sizeof(METRIC)); @@ -166,7 +193,7 @@ int get_active_checks(char *server, int port, char *error, int max_error_len) return NETWORK_ERROR; } - snprintf(c,sizeof(c)-1,"%s\n","ZBX_GET_ACTIVE_CHECKS"); + snprintf(c,sizeof(c)-1,"%s\n%s\n","ZBX_GET_ACTIVE_CHECKS",CONFIG_HOSTNAME); zabbix_log(LOG_LEVEL_WARNING, "Sending [%s]", c); if( write(s,c,strlen(c)) == -1 ) { @@ -314,26 +341,31 @@ int send_value(char *server,int port,char *shortname,char *value) void process_active_checks() { char value[MAX_STRING_LEN]; - int i; + int i, now; char shortname[MAX_STRING_LEN]; + now=time(NULL); for(i=0;;i++) { if(metrics[i].key == NULL) break; + if(metrics[i].nextcheck>now) continue; process(metrics[i].key, value); - snprintf(shortname, MAX_STRING_LEN-1,"%s:%s","a0",metrics[i].key); + snprintf(shortname, MAX_STRING_LEN-1,"%s:%s",CONFIG_HOSTNAME,metrics[i].key); zabbix_log( LOG_LEVEL_WARNING, "%s",shortname); send_value("127.0.0.1",10051,shortname,value); + + metrics[i].nextcheck=time(NULL)+metrics[i].refresh; } } void child_active_main(int i,char *server, int port) { char error[MAX_STRING_LEN]; + int sleeptime, nextcheck; zabbix_log( LOG_LEVEL_WARNING, "zabbix_agentd %ld started",(long)getpid()); @@ -351,6 +383,37 @@ void child_active_main(int i,char *server, int port) #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("sleeping for 10 seconds"); #endif + nextcheck=get_min_nextcheck(); + if( FAIL == nextcheck) + { + sleeptime=60; + } + else + { + sleeptime=nextcheck-time(NULL); + if(sleeptime<0) + { + sleeptime=0; + } + } + if(sleeptime>0) + { + if(sleeptime > 60) + { + sleeptime = 60; + } + zabbix_log( LOG_LEVEL_WARNING, "Sleeping for %d seconds", + sleeptime ); +#ifdef HAVE_FUNCTION_SETPROCTITLE + setproctitle("sucker [sleeping for %d seconds]", + sleeptime); +#endif + sleep( sleeptime ); + } + else + { + zabbix_log( LOG_LEVEL_DEBUG, "No sleeping" ); + } // sleep(1); } } diff --git a/src/zabbix_agent/active.h b/src/zabbix_agent/active.h index f4c71c2b..642a199b 100644 --- a/src/zabbix_agent/active.h +++ b/src/zabbix_agent/active.h @@ -20,11 +20,14 @@ #ifndef ZABBIX_ACTIVE_H #define ZABBIX_ACTIVE_H +extern char *CONFIG_HOSTNAME; + #define METRIC struct metric_type METRIC { char *key; int refresh; + int nextcheck; int status; }; diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c index b5e36676..5361750e 100644 --- a/src/zabbix_agent/zabbix_agentd.c +++ b/src/zabbix_agent/zabbix_agentd.c @@ -66,18 +66,18 @@ int parent=0; /* Number of processed requests */ int stats_request=0; -static char *CONFIG_HOSTS_ALLOWED = NULL; -static char *CONFIG_FILE = NULL; -static char *CONFIG_PID_FILE = NULL; -static char *CONFIG_LOG_FILE = NULL; -/*static char *CONFIG_STAT_FILE = NULL;*/ -static int CONFIG_AGENTD_FORKS = AGENTD_FORKS; -static int CONFIG_NOTIMEWAIT = 0; -static int CONFIG_TIMEOUT = AGENT_TIMEOUT; -static int CONFIG_LISTEN_PORT = 10050; -static int CONFIG_SERVER_PORT = 10051; -static char *CONFIG_LISTEN_IP = NULL; -static int CONFIG_LOG_LEVEL = LOG_LEVEL_WARNING; +char *CONFIG_HOSTS_ALLOWED = NULL; +char *CONFIG_HOSTNAME = NULL; +char *CONFIG_FILE = NULL; +char *CONFIG_PID_FILE = NULL; +char *CONFIG_LOG_FILE = NULL; +int CONFIG_AGENTD_FORKS = AGENTD_FORKS; +int CONFIG_NOTIMEWAIT = 0; +int CONFIG_TIMEOUT = AGENT_TIMEOUT; +int CONFIG_LISTEN_PORT = 10050; +int CONFIG_SERVER_PORT = 10051; +char *CONFIG_LISTEN_IP = NULL; +int CONFIG_LOG_LEVEL = LOG_LEVEL_WARNING; void uninit(void) { @@ -231,6 +231,7 @@ void init_config(void) /* 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_MAND,0,0}, {"PidFile",&CONFIG_PID_FILE,0,TYPE_STRING,PARM_OPT,0,0}, {"LogFile",&CONFIG_LOG_FILE,0,TYPE_STRING,PARM_OPT,0,0}, /* {"StatFile",&CONFIG_STAT_FILE,0,TYPE_STRING,PARM_OPT,0,0},*/ @@ -480,9 +481,6 @@ int main(int argc, char **argv) /* Initialize thread for active checks */ pids[CONFIG_AGENTD_FORKS-1] = child_active_make(CONFIG_AGENTD_FORKS-1, CONFIG_HOSTS_ALLOWED, CONFIG_SERVER_PORT); - // DELETE THIS LINE - child_active_make(CONFIG_AGENTD_FORKS-1, CONFIG_HOSTS_ALLOWED, CONFIG_SERVER_PORT); - child_active_make(CONFIG_AGENTD_FORKS-1, CONFIG_HOSTS_ALLOWED, CONFIG_SERVER_PORT); parent=1; diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index 82edf395..74f23c26 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -53,7 +53,6 @@ #include "alerter.h" #include "pinger.h" #include "housekeeper.h" -#include "housekeeper.h" #include "trapper.h" #include "checks_agent.h" diff --git a/src/zabbix_server/trapper.c b/src/zabbix_server/trapper.c index 0e7f91d0..06745511 100644 --- a/src/zabbix_server/trapper.c +++ b/src/zabbix_server/trapper.c @@ -57,7 +57,7 @@ int process_trap(int sockfd,char *s) { - char *p; + char *p,*line,*host; char *server,*key,*value_string; char result[MAX_STRING_LEN]; @@ -69,9 +69,11 @@ int process_trap(int sockfd,char *s) zabbix_log( LOG_LEVEL_DEBUG, "Trapper got [%s]", s); /* Request for list of active checks */ - if(strcmp(s,"ZBX_GET_ACTIVE_CHECKS") == 0) + if(strncmp(s,"ZBX_GET_ACTIVE_CHECKS", strlen("ZBX_GET_ACTIVE_CHECKS")) == 0) { - ret=send_list_of_active_checks(sockfd); + line=strtok(s,"\n"); + host=strtok(NULL,"\n"); + ret=send_list_of_active_checks(sockfd, host); } /* Process information sent by zabbix_sender */ else |