diff options
-rw-r--r-- | include/functions.c | 48 | ||||
-rw-r--r-- | include/functions.h | 1 | ||||
-rw-r--r-- | src/zabbix_server/trapper.c | 36 |
3 files changed, 71 insertions, 14 deletions
diff --git a/include/functions.c b/include/functions.c index f5652122..459c2ace 100644 --- a/include/functions.c +++ b/include/functions.c @@ -2203,6 +2203,54 @@ 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) +{ + char sql[MAX_STRING_LEN]; + char s[MAX_STRING_LEN]; + + 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_ACTIVE_CHECK); + + result = DBselect(sql); + + for(i=0;i<DBnum_rows(result);i++) + { + snprintf(s,sizeof(s)-1,"%s:%s\n",DBget_field(result,i,0),DBget_field(result,i,1)); + if( write(s,c,strlen(c)) == -1 ) + { + switch (errno) + { + case EINTR: + zabbix_log( LOG_LEVEL_WARNING, "Timeout while sending data to [%s]",server ); + break; + default: + zabbix_log( LOG_LEVEL_WARNING, "Error while sending data to [%s] [%s]",server, strerror(errno)); + } + close(s); + return FAIL; + } + } + DBfree_result(result); + + snprintf(s,sizeof(s)-1,"%s\n","ZBX_EOF"); + if( write(s,c,strlen(c)) == -1 ) + { + switch (errno) + { + case EINTR: + zabbix_log( LOG_LEVEL_WARNING, "Timeout while sending data to [%s]",server ); + break; + default: + zabbix_log( LOG_LEVEL_WARNING, "Error while sending data to [%s] [%s]",server, strerror(errno)); + } + close(s); + return FAIL; + } + return SUCCEED; +} + +/* For zabbix_trapper(d) */ /* int process_data(char *server,char *key, double value)*/ int process_data(int sockfd,char *server,char *key,char *value) { diff --git a/include/functions.h b/include/functions.h index deb2afd5..0c7d3d37 100644 --- a/include/functions.h +++ b/include/functions.h @@ -31,6 +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); #ifdef ZABBIX_THREADS void update_triggers_thread(MYSQL *database, int itemid); diff --git a/src/zabbix_server/trapper.c b/src/zabbix_server/trapper.c index 463ef4c3..d3b56bf7 100644 --- a/src/zabbix_server/trapper.c +++ b/src/zabbix_server/trapper.c @@ -65,26 +65,34 @@ int process_trap(int sockfd,char *s) for( p=s+strlen(s)-1; p>s && ( *p=='\r' || *p =='\n' || *p == ' ' ); --p ); p[1]=0; - server=(char *)strtok(s,":"); - if(NULL == server) +/* Request for list of active checks */ + if(strcmp(s,"ZBX_GET_ACTIVE_CHECKS") == 0) { - return FAIL; + ret=send_list_of_active_check(sockfd); } - - key=(char *)strtok(NULL,":"); - if(NULL == key) +/* Process information sent by zabbix_sender */ + else { - return FAIL; - } + server=(char *)strtok(s,":"); + if(NULL == server) + { + return FAIL; + } - value_string=(char *)strtok(NULL,":"); - if(NULL == value_string) - { - return FAIL; - } + key=(char *)strtok(NULL,":"); + if(NULL == key) + { + return FAIL; + } - ret=process_data(sockfd,server,key,value_string); + value_string=(char *)strtok(NULL,":"); + if(NULL == value_string) + { + return FAIL; + } + ret=process_data(sockfd,server,key,value_string); + } return ret; } |