diff options
author | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-02-15 17:17:59 +0000 |
---|---|---|
committer | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-02-15 17:17:59 +0000 |
commit | 02edd0c48946e1a487ed3fb035cd3af104ba5a5d (patch) | |
tree | 58603e6a2f088794b8cbc71773d851a005dcdfc5 | |
parent | af96ef3f63267e56a7bf5e208efa6b4aa12e409e (diff) | |
download | zabbix-02edd0c48946e1a487ed3fb035cd3af104ba5a5d.tar.gz zabbix-02edd0c48946e1a487ed3fb035cd3af104ba5a5d.tar.xz zabbix-02edd0c48946e1a487ed3fb035cd3af104ba5a5d.zip |
- [DEV-109] Server changes - Trapper
git-svn-id: svn://svn.zabbix.com/trunk@5353 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r-- | include/common.h | 4 | ||||
-rw-r--r-- | src/zabbix_server/actions.c | 4 | ||||
-rw-r--r-- | src/zabbix_server/evalfunc.c | 4 | ||||
-rw-r--r-- | src/zabbix_server/functions.c | 231 | ||||
-rw-r--r-- | src/zabbix_server/functions.h | 2 | ||||
-rw-r--r-- | src/zabbix_server/operations.c | 12 | ||||
-rw-r--r-- | src/zabbix_server/poller/poller.c | 8 | ||||
-rw-r--r-- | src/zabbix_server/server.c | 4 | ||||
-rw-r--r-- | src/zabbix_server/trapper/trapper.c | 213 | ||||
-rw-r--r-- | src/zabbix_server/zlog.c | 4 |
10 files changed, 233 insertions, 253 deletions
diff --git a/include/common.h b/include/common.h index d79f5fd7..c6e5dd17 100644 --- a/include/common.h +++ b/include/common.h @@ -508,9 +508,9 @@ void *zbx_realloc(void *src, size_t size); #define zbx_fclose(f) { if(f){ fclose(f); f = NULL; } } /*#define ZBX_COND_NODEID " %s>=100000000000000*%d and %s<=(100000000000000*%d+99999999999999) "*/ -#define ZBX_COND_NODEID " %s>=%d00000000000000 and %s<=%d99999999999999 " +/*#define ZBX_COND_NODEID " %s>=%d00000000000000 and %s<=%d99999999999999 " #define LOCAL_NODE(fieldid) fieldid, CONFIG_NODEID, fieldid, CONFIG_NODEID -#define ZBX_NODE(fieldid,nodeid) fieldid, nodeid, fieldid, nodeid +#define ZBX_NODE(fieldid,nodeid) fieldid, nodeid, fieldid, nodeid*/ #define MIN_ZABBIX_PORT 1024u #define MAX_ZABBIX_PORT 65535u diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c index 13467dbb..258bf7d0 100644 --- a/src/zabbix_server/actions.c +++ b/src/zabbix_server/actions.c @@ -755,10 +755,10 @@ void process_actions(DB_EVENT *event) (event->source == EVENT_SOURCE_TRIGGERS)?"TRIGGERS":"DISCOVERY", event->eventid); - result = DBselect("select actionid,evaltype,status,eventsource from actions where status=%d and eventsource=%d and" ZBX_COND_NODEID, + result = DBselect("select actionid,evaltype,status,eventsource from actions where status=%d and eventsource=%d" DB_NODE, ACTION_STATUS_ACTIVE, event->source, - LOCAL_NODE("actionid")); + DBnode_local("actionid")); while((row=DBfetch(result))) { diff --git a/src/zabbix_server/evalfunc.c b/src/zabbix_server/evalfunc.c index 848ef013..73b6b85b 100644 --- a/src/zabbix_server/evalfunc.c +++ b/src/zabbix_server/evalfunc.c @@ -1792,11 +1792,11 @@ int evaluate_function2(char *value,char *host,char *key,char *function,char *par DBescape_string(host, host_esc, MAX_STRING_LEN); DBescape_string(key, key_esc, MAX_STRING_LEN); - result = DBselect("select %s where h.host='%s' and h.hostid=i.hostid and i.key_='%s' and" ZBX_COND_NODEID, + result = DBselect("select %s where h.host='%s' and h.hostid=i.hostid and i.key_='%s'" DB_NODE, ZBX_SQL_ITEM_SELECT, host_esc, key_esc, - LOCAL_NODE("h.hostid")); + DBnode_local("h.hostid")); row = DBfetch(result); diff --git a/src/zabbix_server/functions.c b/src/zabbix_server/functions.c index 8379586e..d1c962c8 100644 --- a/src/zabbix_server/functions.c +++ b/src/zabbix_server/functions.c @@ -173,237 +173,6 @@ void update_triggers(zbx_uint64_t itemid) itemid); } -void calc_timestamp(char *line,int *timestamp, char *format) -{ - int hh=0,mm=0,ss=0,yyyy=0,dd=0,MM=0; - int hhc=0,mmc=0,ssc=0,yyyyc=0,ddc=0,MMc=0; - int i,num; - struct tm tm; - time_t t; - - zabbix_log( LOG_LEVEL_DEBUG, "In calc_timestamp()"); - - hh=mm=ss=yyyy=dd=MM=0; - - for(i=0;(format[i]!=0)&&(line[i]!=0);i++) - { - if(isdigit(line[i])==0) continue; - num=(int)line[i]-48; - - switch ((char) format[i]) { - case 'h': - hh=10*hh+num; - hhc++; - break; - case 'm': - mm=10*mm+num; - mmc++; - break; - case 's': - ss=10*ss+num; - ssc++; - break; - case 'y': - yyyy=10*yyyy+num; - yyyyc++; - break; - case 'd': - dd=10*dd+num; - ddc++; - break; - case 'M': - MM=10*MM+num; - MMc++; - break; - } - } - - zabbix_log( LOG_LEVEL_DEBUG, "hh [%d] mm [%d] ss [%d] yyyy [%d] dd [%d] MM [%d]", - hh, - mm, - ss, - yyyy, - dd, - MM); - - /* Seconds can be ignored. No ssc here. */ - if(hhc!=0&&mmc!=0&&yyyyc!=0&&ddc!=0&&MMc!=0) - { - tm.tm_sec=ss; - tm.tm_min=mm; - tm.tm_hour=hh; - tm.tm_mday=dd; - tm.tm_mon=MM-1; - tm.tm_year=yyyy-1900; - - t=mktime(&tm); - if(t>0) - { - *timestamp=t; - } - } - - zabbix_log( LOG_LEVEL_DEBUG, "End timestamp [%d]", - *timestamp); -} - -/****************************************************************************** - * * - * Function: process_data * - * * - * Purpose: process new item value * - * * - * Parameters: sockfd - descriptor of agent-server socket connection * - * server - server name * - * key - item's key * - * value - new value of server:key * - * lastlogsize - if key=log[*], last size of log file * - * * - * Return value: SUCCEED - new value processed sucesfully * - * FAIL - otherwise * - * * - * Author: Alexei Vladishev * - * * - * Comments: for trapper server process * - * * - ******************************************************************************/ -int process_data(zbx_sock_t *sock,char *server,char *key,char *value,char *lastlogsize, char *timestamp, - char *source, char *severity) -{ - AGENT_RESULT agent; - - DB_RESULT result; - DB_ROW row; - DB_ITEM item; - - char server_esc[MAX_STRING_LEN]; - char key_esc[MAX_STRING_LEN]; - - zabbix_log( LOG_LEVEL_DEBUG, "In process_data([%s],[%s],[%s],[%s])", - server, - key, - value, - lastlogsize); - - init_result(&agent); - - DBescape_string(server, server_esc, MAX_STRING_LEN); - DBescape_string(key, key_esc, MAX_STRING_LEN); - - result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s'" - " and i.status in (%d,%d) and i.type in (%d,%d)" DB_NODE, - ZBX_SQL_ITEM_SELECT, - HOST_STATUS_MONITORED, - server_esc, - key_esc, - ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, - ITEM_TYPE_TRAPPER, - ITEM_TYPE_ZABBIX_ACTIVE, - DBnode_local("h.hostid")); - - row=DBfetch(result); - - if(!row) - { - DBfree_result(result); - return FAIL; -/* - zabbix_log( LOG_LEVEL_DEBUG, "Before checking autoregistration for [%s]", - server); - - if(autoregister(server) == SUCCEED) - { - DBfree_result(result); - - result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d) and" ZBX_COND_NODEID, - ZBX_SQL_ITEM_SELECT, - HOST_STATUS_MONITORED, - server_esc, - key_esc, - ITEM_STATUS_ACTIVE, - ITEM_TYPE_TRAPPER, - ITEM_TYPE_ZABBIX_ACTIVE, - LOCAL_NODE("h.hostid")); - row = DBfetch(result); - if(!row) - { - DBfree_result(result); - return FAIL; - } - } - else - { - DBfree_result(result); - return FAIL; - } -*/ - } - - DBget_item_from_db(&item,row); - - if( (item.type==ITEM_TYPE_ZABBIX_ACTIVE) && (zbx_tcp_check_security(sock,item.trapper_hosts,1) == FAIL)) - { - DBfree_result(result); - return FAIL; - } - - zabbix_log( LOG_LEVEL_DEBUG, "Processing [%s]", - value); - - if(strcmp(value,"ZBX_NOTSUPPORTED") ==0) - { - zabbix_log( LOG_LEVEL_WARNING, "Active parameter [%s] is not supported by agent on host [%s]", - item.key, - item.host_name); - zabbix_syslog("Active parameter [%s] is not supported by agent on host [%s]", - item.key, - item.host_name); - DBupdate_item_status_to_notsupported(item.itemid, "Not supported by ZABBIX agent"); - } - else - { - if( (strncmp(item.key,"log[",4)==0) || - (strncmp(item.key,"eventlog[",9)==0) - ) - { - item.lastlogsize=atoi(lastlogsize); - item.timestamp=atoi(timestamp); - - calc_timestamp(value,&item.timestamp,item.logtimefmt); - - item.eventlog_severity=atoi(severity); - item.eventlog_source=source; - zabbix_log(LOG_LEVEL_DEBUG, "Value [%s] Lastlogsize [%s] Timestamp [%s]", - value, - lastlogsize, - timestamp); - } - - if(set_result_type(&agent, item.value_type, value) == SUCCEED) - { - process_new_value(&item,&agent); - update_triggers(item.itemid); - } - else - { - zabbix_log( LOG_LEVEL_WARNING, "Type of received value [%s] is not suitable for [%s@%s]", - value, - item.key, - item.host_name); - zabbix_syslog("Type of received value [%s] is not suitable for [%s@%s]", - value, - item.key, - item.host_name); - } - } - - DBfree_result(result); - - free_result(&agent); - - return SUCCEED; -} - /****************************************************************************** * * * Function: add_history * diff --git a/src/zabbix_server/functions.h b/src/zabbix_server/functions.h index 73c179c7..f88ce066 100644 --- a/src/zabbix_server/functions.h +++ b/src/zabbix_server/functions.h @@ -27,8 +27,6 @@ void update_triggers (zbx_uint64_t itemid); void update_functions(DB_ITEM *item); -int process_data(zbx_sock_t *sock,char *server,char *key, char *value,char *lastlogsize,char *timestamp, - char *source, char *severity); void process_new_value(DB_ITEM *item, AGENT_RESULT *value); void proxy_process_new_value(DB_ITEM *item, AGENT_RESULT *value); diff --git a/src/zabbix_server/operations.c b/src/zabbix_server/operations.c index b4ae1996..26d5dcab 100644 --- a/src/zabbix_server/operations.c +++ b/src/zabbix_server/operations.c @@ -221,9 +221,9 @@ static void run_remote_command(char* host_name, char* command) host_name, command); - result = DBselect("select distinct host,ip,useip,port,dns from hosts where host='%s' and " ZBX_COND_NODEID, + result = DBselect("select distinct host,ip,useip,port,dns from hosts where host='%s'" DB_NODE, host_name, - LOCAL_NODE("hostid")); + DBnode_local("hostid")); row = DBfetch(result); if(row) { @@ -377,9 +377,9 @@ void op_run_commands(DB_EVENT *event, DB_OPERATION *operation) if(alias == '\0' || command == '\0') continue; if(is_group) { - result = DBselect("select distinct h.host from hosts_groups hg,hosts h, groups g where hg.hostid=h.hostid and hg.groupid=g.groupid and g.name='%s' and" ZBX_COND_NODEID, + result = DBselect("select distinct h.host from hosts_groups hg,hosts h, groups g where hg.hostid=h.hostid and hg.groupid=g.groupid and g.name='%s'" DB_NODE, alias, - LOCAL_NODE("h.hostid")); + DBnode_local("h.hostid")); while((row=DBfetch(result))) { run_remote_command(row[0], command); @@ -513,9 +513,9 @@ static zbx_uint64_t add_discovered_host(zbx_uint64_t dhostid) DBescape_string(host, host_esc, sizeof(host_esc)); - result2 = DBselect("select hostid from hosts where ip='%s' and " ZBX_COND_NODEID, + result2 = DBselect("select hostid from hosts where ip='%s'" DB_NODE, ip, - LOCAL_NODE("hostid")); + DBnode_local("hostid")); row2 = DBfetch(result2); if(!row2 || DBis_null(row2[0]) == SUCCEED) { diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c index 1c4cd3d4..d39e2837 100644 --- a/src/zabbix_server/poller/poller.c +++ b/src/zabbix_server/poller/poller.c @@ -124,8 +124,8 @@ static int get_minnextcheck(int now) result = DBselect("select count(*),min(nextcheck) as nextcheck from items i,hosts h" " where " ZBX_SQL_MOD(h.hostid,%d) "=%d and i.nextcheck<=%d and i.status in (%d)" " and i.type not in (%d,%d,%d) and h.status=%d and h.disable_until<=%d" - " and h.errors_from!=0 and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s')" - DB_NODE " order by nextcheck", + " and h.errors_from!=0 and h.hostid=i.hostid and h.proxyid=0" + " and i.key_ not in ('%s','%s','%s','%s')" DB_NODE " order by nextcheck", CONFIG_UNREACHABLE_POLLER_FORKS, poller_num-1, now, @@ -142,7 +142,7 @@ static int get_minnextcheck(int now) { result = DBselect("select count(*),min(nextcheck) from items i,hosts h" " where h.status=%d and h.disable_until<%d and h.errors_from=0" - " and h.hostid=i.hostid and i.status in (%d,%d) and i.type not in (%d,%d,%d)" + " and h.hostid=i.hostid and h.proxyid=0 and i.status in (%d,%d) and i.type not in (%d,%d,%d)" " and " ZBX_SQL_MOD(i.itemid,%d) "=%d and i.key_ not in ('%s','%s','%s','%s')" DB_NODE, HOST_STATUS_MONITORED, now, @@ -157,7 +157,7 @@ static int get_minnextcheck(int now) { result = DBselect("select count(*),min(nextcheck) from items i,hosts h" " where h.status=%d and h.disable_until<%d and h.errors_from=0" - " and h.hostid=i.hostid and i.status in (%d) and i.type not in (%d,%d,%d)" + " and h.hostid=i.hostid and h.proxyid=0 and i.status in (%d) and i.type not in (%d,%d,%d)" " and " ZBX_SQL_MOD(i.itemid,%d) "=%d and i.key_ not in ('%s','%s','%s','%s')" DB_NODE, HOST_STATUS_MONITORED, now, diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index 7eb56a4a..14dddd71 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -1017,8 +1017,8 @@ int MAIN_ZABBIX_ENTRY(void) DBconnect(ZBX_DB_CONNECT_EXIT); - result = DBselect("select refresh_unsupported from config where " ZBX_COND_NODEID, - LOCAL_NODE("configid")); + result = DBselect("select refresh_unsupported from config where 1=1" DB_NODE, + DBnode_local("configid")); row = DBfetch(result); if( (row != NULL) && DBis_null(row[0]) != SUCCEED) diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c index 49bd1e5f..d094b4ec 100644 --- a/src/zabbix_server/trapper/trapper.c +++ b/src/zabbix_server/trapper/trapper.c @@ -43,6 +43,219 @@ static zbx_process_t zbx_process; +static void calc_timestamp(char *line,int *timestamp, char *format) +{ + int hh=0,mm=0,ss=0,yyyy=0,dd=0,MM=0; + int hhc=0,mmc=0,ssc=0,yyyyc=0,ddc=0,MMc=0; + int i,num; + struct tm tm; + time_t t; + + zabbix_log( LOG_LEVEL_DEBUG, "In calc_timestamp()"); + + hh=mm=ss=yyyy=dd=MM=0; + + for(i=0;(format[i]!=0)&&(line[i]!=0);i++) + { + if(isdigit(line[i])==0) continue; + num=(int)line[i]-48; + + switch ((char) format[i]) { + case 'h': + hh=10*hh+num; + hhc++; + break; + case 'm': + mm=10*mm+num; + mmc++; + break; + case 's': + ss=10*ss+num; + ssc++; + break; + case 'y': + yyyy=10*yyyy+num; + yyyyc++; + break; + case 'd': + dd=10*dd+num; + ddc++; + break; + case 'M': + MM=10*MM+num; + MMc++; + break; + } + } + + zabbix_log( LOG_LEVEL_DEBUG, "hh [%d] mm [%d] ss [%d] yyyy [%d] dd [%d] MM [%d]", + hh, + mm, + ss, + yyyy, + dd, + MM); + + /* Seconds can be ignored. No ssc here. */ + if(hhc!=0&&mmc!=0&&yyyyc!=0&&ddc!=0&&MMc!=0) + { + tm.tm_sec=ss; + tm.tm_min=mm; + tm.tm_hour=hh; + tm.tm_mday=dd; + tm.tm_mon=MM-1; + tm.tm_year=yyyy-1900; + + t=mktime(&tm); + if(t>0) + { + *timestamp=t; + } + } + + zabbix_log( LOG_LEVEL_DEBUG, "End timestamp [%d]", + *timestamp); +} + +/****************************************************************************** + * * + * Function: process_data * + * * + * Purpose: process new item value * + * * + * Parameters: sockfd - descriptor of agent-server socket connection * + * server - server name * + * key - item's key * + * value - new value of server:key * + * lastlogsize - if key=log[*], last size of log file * + * * + * Return value: SUCCEED - new value processed sucesfully * + * FAIL - otherwise * + * * + * Author: Alexei Vladishev * + * * + * Comments: for trapper server process * + * * + ******************************************************************************/ +static int process_data(zbx_sock_t *sock,char *server,char *key,char *value,char *lastlogsize, char *timestamp, + char *source, char *severity) +{ + AGENT_RESULT agent; + DB_RESULT result; + DB_ROW row; + DB_ITEM item; + char server_esc[MAX_STRING_LEN], key_esc[MAX_STRING_LEN]; + + zabbix_log(LOG_LEVEL_DEBUG, "In process_data([%s],[%s],[%s],[%s])", + server, + key, + value, + lastlogsize); + + DBescape_string(server, server_esc, MAX_STRING_LEN); + DBescape_string(key, key_esc, MAX_STRING_LEN); + + result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and h.proxyid=0" + " and i.key_='%s' and i.status in (%d,%d) and i.type in (%d,%d)" DB_NODE, + ZBX_SQL_ITEM_SELECT, + HOST_STATUS_MONITORED, + server_esc, + key_esc, + ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, + ITEM_TYPE_TRAPPER, + ITEM_TYPE_ZABBIX_ACTIVE, + DBnode_local("h.hostid")); + + if (NULL == (row = DBfetch(result))) { + DBfree_result(result); + return FAIL; +/* + zabbix_log( LOG_LEVEL_DEBUG, "Before checking autoregistration for [%s]", + server); + + if(autoregister(server) == SUCCEED) + { + DBfree_result(result); + + result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d) and" ZBX_COND_NODEID, + ZBX_SQL_ITEM_SELECT, + HOST_STATUS_MONITORED, + server_esc, + key_esc, + ITEM_STATUS_ACTIVE, + ITEM_TYPE_TRAPPER, + ITEM_TYPE_ZABBIX_ACTIVE, + LOCAL_NODE("h.hostid")); + row = DBfetch(result); + if(!row) + { + DBfree_result(result); + return FAIL; + } + } + else + { + DBfree_result(result); + return FAIL; + } +*/ + } + + DBget_item_from_db(&item, row); + + if (item.type == ITEM_TYPE_ZABBIX_ACTIVE && FAIL == zbx_tcp_check_security(sock, item.trapper_hosts, 1)) { + DBfree_result(result); + return FAIL; + } + + zabbix_log(LOG_LEVEL_DEBUG, "Processing [%s]", + value); + + if (0 == strcmp(value, "ZBX_NOTSUPPORTED")) { + zabbix_log( LOG_LEVEL_WARNING, "Active parameter [%s] is not supported by agent on host [%s]", + item.key, + item.host_name); + zabbix_syslog("Active parameter [%s] is not supported by agent on host [%s]", + item.key, + item.host_name); + DBupdate_item_status_to_notsupported(item.itemid, "Not supported by ZABBIX agent"); + } else { + if (0 == strncmp(item.key, "log[", 4) || 0 == strncmp(item.key, "eventlog[", 9)) { + item.lastlogsize = atoi(lastlogsize); + item.timestamp = atoi(timestamp); + + calc_timestamp(value, &item.timestamp, item.logtimefmt); + + item.eventlog_severity = atoi(severity); + item.eventlog_source = source; + zabbix_log(LOG_LEVEL_DEBUG, "Value [%s] Lastlogsize [%s] Timestamp [%s]", + value, + lastlogsize, + timestamp); + } + + init_result(&agent); + + if( SUCCEED == set_result_type(&agent, item.value_type, value)) { + process_new_value(&item, &agent); + update_triggers(item.itemid); + } else { + zabbix_log( LOG_LEVEL_WARNING, "Type of received value [%s] is not suitable for [%s@%s]", + value, + item.key, + item.host_name); + zabbix_syslog("Type of received value [%s] is not suitable for [%s@%s]", + value, + item.key, + item.host_name); + } + free_result(&agent); + } + DBfree_result(result); + + return SUCCEED; +} + /****************************************************************************** * * * Function: send_result * diff --git a/src/zabbix_server/zlog.c b/src/zabbix_server/zlog.c index a3071662..52a9b170 100644 --- a/src/zabbix_server/zlog.c +++ b/src/zabbix_server/zlog.c @@ -65,11 +65,11 @@ void __zbx_zabbix_syslog(const char *fmt, ...) /* This is made to disable writing to database for watchdog */ if(CONFIG_ENABLE_LOG == 0) return; - result = DBselect("select %s where h.hostid=i.hostid and i.key_='%s' and i.value_type=%d and" ZBX_COND_NODEID, + result = DBselect("select %s where h.hostid=i.hostid and i.key_='%s' and i.value_type=%d" DB_NODE, ZBX_SQL_ITEM_SELECT, SERVER_ZABBIXLOG_KEY, ITEM_VALUE_TYPE_STR, - LOCAL_NODE("h.hostid")); + DBnode_local("h.hostid")); while((row=DBfetch(result))) { |