diff options
| author | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-07-29 09:43:53 +0000 |
|---|---|---|
| committer | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-07-29 09:43:53 +0000 |
| commit | f7cd0be8cdcedcc34656ced6982dd7abadca01fc (patch) | |
| tree | a6aa538b83fd84824e8a8431bd9c2ecc694dafc3 /src/zabbix_server | |
| parent | e3248ce4bc1b34d8623359d5333cfa9712b5eb73 (diff) | |
- [DEV-196] improved performance of server module
git-svn-id: svn://svn.zabbix.com/trunk@5848 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_server')
| -rw-r--r-- | src/zabbix_server/dbsyncer/dbsyncer.c | 44 | ||||
| -rw-r--r-- | src/zabbix_server/httppoller/httptest.c | 25 | ||||
| -rw-r--r-- | src/zabbix_server/pinger/pinger.c | 33 | ||||
| -rw-r--r-- | src/zabbix_server/poller/checks_agent.c | 5 | ||||
| -rw-r--r-- | src/zabbix_server/poller/poller.c | 303 | ||||
| -rw-r--r-- | src/zabbix_server/server.c | 29 | ||||
| -rw-r--r-- | src/zabbix_server/trapper/trapper.c | 342 | ||||
| -rw-r--r-- | src/zabbix_server/trapper/trapper.h | 14 | ||||
| -rw-r--r-- | src/zabbix_server/zlog.c | 25 |
9 files changed, 477 insertions, 343 deletions
diff --git a/src/zabbix_server/dbsyncer/dbsyncer.c b/src/zabbix_server/dbsyncer/dbsyncer.c index cf28a7db..c341668b 100644 --- a/src/zabbix_server/dbsyncer/dbsyncer.c +++ b/src/zabbix_server/dbsyncer/dbsyncer.c @@ -22,6 +22,7 @@ #include "db.h" #include "log.h" #include "zlog.h" +#include "threads.h" #include "dbcache.h" #include "dbsyncer.h" @@ -43,9 +44,11 @@ ******************************************************************************/ int main_dbsyncer_loop() { - int now; + int now, sleeptime, last_sleeptime = -1, num; double sec; + zabbix_log(LOG_LEVEL_DEBUG, "In main_dbsyncer_loop()"); + zbx_setproctitle("db syncer [connecting to the database]"); DBconnect(ZBX_DB_CONNECT_NORMAL); @@ -55,18 +58,41 @@ int main_dbsyncer_loop() now = time(NULL); sec = zbx_time(); + num = DCsync_history(ZBX_SYNC_PARTIAL); + sec = zbx_time() - sec; + + if (last_sleeptime == -1) + { + sleeptime = now - time(NULL) + CONFIG_DBSYNCER_FREQUENCY; + } + else + { + sleeptime = last_sleeptime; + if (num >= ZBX_SYNC_MAX) + sleeptime--; + else if (num < ZBX_SYNC_MAX / 2) + sleeptime++; + } + + if (sleeptime < 0) + sleeptime = 0; + else if (sleeptime > CONFIG_DBSYNCER_FREQUENCY) + sleeptime = CONFIG_DBSYNCER_FREQUENCY; - DCsync(); + last_sleeptime = sleeptime; - zabbix_log(LOG_LEVEL_DEBUG, "Spent " ZBX_FS_DBL " sec", - zbx_time() - sec); + zabbix_log(LOG_LEVEL_DEBUG, "DB syncer spent " ZBX_FS_DBL " second while processing %d items. " + "Nextsync after %d sec.", + sec, + num, + sleeptime); - zbx_setproctitle("db syncer [sleeping for %d seconds]", - CONFIG_DBSYNCER_FREQUENCY); - zabbix_log(LOG_LEVEL_DEBUG, "Sleeping for %d seconds", - CONFIG_DBSYNCER_FREQUENCY); + if (sleeptime > 0) { + zbx_setproctitle("db syncer [sleeping for %d seconds]", + sleeptime); - sleep(CONFIG_DBSYNCER_FREQUENCY); + sleep(sleeptime); + } } DBclose(); } diff --git a/src/zabbix_server/httppoller/httptest.c b/src/zabbix_server/httppoller/httptest.c index 04bd5713..6b527477 100644 --- a/src/zabbix_server/httppoller/httptest.c +++ b/src/zabbix_server/httppoller/httptest.c @@ -84,17 +84,22 @@ static int process_value(zbx_uint64_t itemid, AGENT_RESULT *value) now = time(NULL); - DBbegin(); - switch (zbx_process) { - case ZBX_PROCESS_SERVER: - process_new_value(&item, value, now); - update_triggers(item.itemid); - break; - case ZBX_PROCESS_PROXY: - proxy_process_new_value(&item, value, now); - break; + if (0 == CONFIG_DBSYNCER_FORKS) + { + DBbegin(); + switch (zbx_process) { + case ZBX_PROCESS_SERVER: + process_new_value(&item, value, now); + update_triggers(item.itemid); + break; + case ZBX_PROCESS_PROXY: + proxy_process_new_value(&item, value, now); + break; + } + DBcommit(); } - DBcommit(); + else + process_new_value(&item, value, now); DBfree_result(result); diff --git a/src/zabbix_server/pinger/pinger.c b/src/zabbix_server/pinger/pinger.c index 2b98cb48..8796347d 100644 --- a/src/zabbix_server/pinger/pinger.c +++ b/src/zabbix_server/pinger/pinger.c @@ -28,6 +28,7 @@ #include "zbxicmpping.h" #include "pinger.h" +#include "dbcache.h" static zbx_process_t zbx_process; static int pinger_num; @@ -79,17 +80,25 @@ static void process_value(char *key, ZBX_FPING_HOST *host, AGENT_RESULT *value, while (NULL != (row = DBfetch(result))) { DBget_item_from_db(&item, row); - DBbegin(); - switch (zbx_process) { - case ZBX_PROCESS_SERVER: + if (0 == CONFIG_DBSYNCER_FORKS) + { + DBbegin(); + switch (zbx_process) { + case ZBX_PROCESS_SERVER: + process_new_value(&item, value, now); + update_triggers(item.itemid); + break; + case ZBX_PROCESS_PROXY: + proxy_process_new_value(&item, value, now); + break; + } + DBcommit(); + } + else + { process_new_value(&item, value, now); - update_triggers(item.itemid); - break; - case ZBX_PROCESS_PROXY: - proxy_process_new_value(&item, value, now); - break; + DCadd_nextcheck(&item, now, NULL); } - DBcommit(); (*items)++; } @@ -118,6 +127,9 @@ static int process_values(ZBX_FPING_HOST *hosts, int hosts_count, int now) zabbix_log(LOG_LEVEL_DEBUG, "In process_values()"); + if (0 != CONFIG_DBSYNCER_FORKS) + DCinit_nextchecks(); + for (i = 0; i < hosts_count; i++) { zabbix_log(LOG_LEVEL_DEBUG, "Host [%s] alive [%d] " ZBX_FS_DBL " sec.", hosts[i].addr, @@ -135,6 +147,9 @@ static int process_values(ZBX_FPING_HOST *hosts, int hosts_count, int now) free_result(&value); } + if (0 != CONFIG_DBSYNCER_FORKS) + DCflush_nextchecks(); + return items; } diff --git a/src/zabbix_server/poller/checks_agent.c b/src/zabbix_server/poller/checks_agent.c index 1ae90662..b6238336 100644 --- a/src/zabbix_server/poller/checks_agent.c +++ b/src/zabbix_server/poller/checks_agent.c @@ -61,21 +61,16 @@ int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) addr, item->key); - zabbix_log(LOG_LEVEL_DEBUG, "Before zbx_tcp_connect"); if (SUCCEED == (ret = zbx_tcp_connect(&s, addr, item->port, 0))) { - zabbix_log(LOG_LEVEL_DEBUG, "After1 zbx_tcp_connect"); zbx_snprintf(packet, sizeof(packet), "%s\n",item->key); zabbix_log(LOG_LEVEL_DEBUG, "Sending [%s]", packet); /* Send requests using old protocol */ if( SUCCEED == (ret = zbx_tcp_send_raw(&s, packet)) ) { - zabbix_log(LOG_LEVEL_DEBUG, "Before read"); - ret = zbx_tcp_recv_ext(&s, &buf, ZBX_TCP_READ_UNTIL_CLOSE); } } - zabbix_log(LOG_LEVEL_DEBUG, "After2 zbx_tcp_connect"); if( SUCCEED == ret ) { diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c index b7ec5b57..666014b5 100644 --- a/src/zabbix_server/poller/poller.c +++ b/src/zabbix_server/poller/poller.c @@ -24,6 +24,7 @@ #include "sysinfo.h" #include "daemon.h" #include "zbxserver.h" +#include "dbcache.h" #include "poller.h" @@ -100,7 +101,7 @@ int get_value(DB_ITEM *item, AGENT_RESULT *result) zabbix_log(LOG_LEVEL_DEBUG, "End get_value()"); return res; } - +/* static int get_minnextcheck(int now) { DB_RESULT result; @@ -108,11 +109,11 @@ static int get_minnextcheck(int now) int res; char istatus[16]; - +*/ /* Host status 0 == MONITORED 1 == NOT MONITORED 2 == UNREACHABLE */ - if(poller_type == ZBX_POLLER_TYPE_UNREACHABLE) +/* if(poller_type == ZBX_POLLER_TYPE_UNREACHABLE) { 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)" @@ -177,49 +178,54 @@ static int get_minnextcheck(int now) return res; } - +*/ /* Update special host's item - "status" */ static void update_key_status(zbx_uint64_t hostid, int host_status, time_t now) { -/* char value_str[MAX_STRING_LEN];*/ AGENT_RESULT agent; - DB_ITEM item; DB_RESULT result; DB_ROW row; - int update; zabbix_log(LOG_LEVEL_DEBUG, "In update_key_status(" ZBX_FS_UI64 ",%d)", - hostid, - host_status); + hostid, + host_status); - result = DBselect("select %s where h.hostid=i.hostid and h.proxy_hostid=0 and h.hostid=" ZBX_FS_UI64 " and i.key_='%s'", - ZBX_SQL_ITEM_SELECT, - hostid, - SERVER_STATUS_KEY); + result = DBselect("select %s where h.hostid=i.hostid and i.status=%d" + " and h.proxy_hostid=0 and i.key_='%s' and h.hostid=" ZBX_FS_UI64, + ZBX_SQL_ITEM_SELECT, + ITEM_STATUS_ACTIVE, + SERVER_STATUS_KEY, + hostid); - while (NULL != (row = DBfetch(result))) { - DBget_item_from_db(&item,row); + while (NULL != (row = DBfetch(result))) + { + DBget_item_from_db(&item, row); /* Do not process new value for status, if previous status is the same */ - update = (item.lastvalue_null==1); - update = update || ((item.value_type == ITEM_VALUE_TYPE_FLOAT) &&(cmp_double(item.lastvalue_dbl, (double)host_status) == 1)); - update = update || ((item.value_type == ITEM_VALUE_TYPE_UINT64) &&(item.lastvalue_uint64 != host_status)); + update = (item.lastvalue_null == 1); + update = update || (item.value_type == ITEM_VALUE_TYPE_FLOAT && cmp_double(item.lastvalue_dbl, (double)host_status) == 1); + update = update || (item.value_type == ITEM_VALUE_TYPE_UINT64 && item.lastvalue_uint64 != host_status); if (update) { init_result(&agent); SET_UI64_RESULT(&agent, host_status); - switch (zbx_process) { - case ZBX_PROCESS_SERVER: - process_new_value(&item, &agent, now); - update_triggers(item.itemid); - break; - case ZBX_PROCESS_PROXY: - proxy_process_new_value(&item, &agent, now); - break; + if (0 == CONFIG_DBSYNCER_FORKS) + { + switch (zbx_process) { + case ZBX_PROCESS_SERVER: + process_new_value(&item, &agent, now); + update_triggers(item.itemid); + break; + case ZBX_PROCESS_PROXY: + proxy_process_new_value(&item, &agent, now); + break; + } } + else + process_new_value(&item, &agent, now); free_result(&agent); } @@ -228,54 +234,34 @@ static void update_key_status(zbx_uint64_t hostid, int host_status, time_t now) DBfree_result(result); } -static void enable_host(DB_ITEM *item, time_t now, char *error) +static void enable_host(DB_ITEM *item, time_t now) { assert(item); - zabbix_log(LOG_LEVEL_WARNING, "Enabling host [%s]", - item->host_name); - zabbix_syslog("Enabling host [%s]", - item->host_name); - switch (zbx_process) { case ZBX_PROCESS_SERVER: - DBupdate_host_availability(item->hostid, HOST_AVAILABLE_TRUE, now, error); + DBupdate_host_availability(item, HOST_AVAILABLE_TRUE, now, NULL); update_key_status(item->hostid, HOST_STATUS_MONITORED, now); /* 0 */ break; case ZBX_PROCESS_PROXY: - DBproxy_update_host_availability(item->hostid, HOST_AVAILABLE_TRUE, now); + DBproxy_update_host_availability(item, HOST_AVAILABLE_TRUE, now); break; } - - item->host_available = HOST_AVAILABLE_TRUE; } static void disable_host(DB_ITEM *item, time_t now, char *error) { assert(item); - zabbix_log(LOG_LEVEL_WARNING, "Host [%s] will be checked after %d seconds", - item->host_name, - CONFIG_UNAVAILABLE_DELAY); - zabbix_syslog("Host [%s] will be checked after %d seconds", - item->host_name, - CONFIG_UNAVAILABLE_DELAY); - switch (zbx_process) { case ZBX_PROCESS_SERVER: - DBupdate_host_availability(item->hostid, HOST_AVAILABLE_FALSE, now, error); + DBupdate_host_availability(item, HOST_AVAILABLE_FALSE, now, error); update_key_status(item->hostid, HOST_AVAILABLE_FALSE, now); /* 2 */ break; case ZBX_PROCESS_PROXY: - DBproxy_update_host_availability(item->hostid, HOST_AVAILABLE_FALSE, now); + DBproxy_update_host_availability(item, HOST_AVAILABLE_FALSE, now); break; } - - item->host_available = HOST_AVAILABLE_FALSE; - - DBexecute("update hosts set disable_until=%d where hostid=" ZBX_FS_UI64, - now + CONFIG_UNAVAILABLE_DELAY, - item->hostid); } /****************************************************************************** @@ -293,14 +279,13 @@ static void disable_host(DB_ITEM *item, time_t now, char *error) * Comments: always SUCCEED * * * ******************************************************************************/ -int get_values(void) +static int get_values(int now) { DB_RESULT result; DB_RESULT result2; DB_ROW row; DB_ROW row2; - time_t now; int delay; int res; DB_ITEM item; @@ -308,14 +293,20 @@ int get_values(void) int stop = 0, items = 0; char *unreachable_hosts = NULL; - char tmp[MAX_STRING_LEN], istatus[16]; + int unreachable_hosts_alloc = 128, + unreachable_hosts_offset = 0; + + char istatus[16]; zabbix_log( LOG_LEVEL_DEBUG, "In get_values()"); + if (0 != CONFIG_DBSYNCER_FORKS) + DCinit_nextchecks(); + now = time(NULL); - zbx_snprintf(tmp,sizeof(tmp)-1,ZBX_FS_UI64,0); - unreachable_hosts=zbx_strdcat(unreachable_hosts,tmp); + unreachable_hosts = zbx_malloc(unreachable_hosts, unreachable_hosts_alloc); + *unreachable_hosts = '\0'; /* Poller for unreachable hosts */ if(poller_type == ZBX_POLLER_TYPE_UNREACHABLE) @@ -327,7 +318,7 @@ int get_values(void) " and i.key_ not in ('%s','%s','%s','%s')" DB_NODE " group by h.hostid", CONFIG_UNREACHABLE_POLLER_FORKS, poller_num-1, - now, + now + POLLER_DELAY, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_HTTPTEST, HOST_STATUS_MONITORED, @@ -352,7 +343,7 @@ int get_values(void) " and " ZBX_SQL_MOD(i.itemid,%d) "=%d and i.key_ not in ('%s','%s','%s','%s')" DB_NODE " order by i.nextcheck", ZBX_SQL_ITEM_SELECT, - now, + now + POLLER_DELAY, istatus, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_HTTPTEST, HOST_STATUS_MONITORED, @@ -406,51 +397,55 @@ int get_values(void) now = time(NULL); - DBbegin(); - - if(res == SUCCEED ) + if (res == SUCCEED) { - switch (zbx_process) { - case ZBX_PROCESS_SERVER: - process_new_value(&item, &agent, now); - break; - case ZBX_PROCESS_PROXY: - proxy_process_new_value(&item, &agent, now); - break; - } - - if (HOST_AVAILABLE_TRUE != item.host_available) { - enable_host(&item, now, agent.msg); + if (HOST_AVAILABLE_TRUE != item.host_available) + { + DBbegin(); + + enable_host(&item, now); stop = 1; + + DBcommit(); } - if (item.host_errors_from != 0) { + + if (item.host_errors_from != 0) + { + DBbegin(); + DBexecute("update hosts set errors_from=0 where hostid=" ZBX_FS_UI64, item.hostid); stop = 1; - } - switch (zbx_process) { - case ZBX_PROCESS_SERVER: - update_triggers(item.itemid); - break; - default: - /* nothing */; + DBcommit(); } - } - else if(res == NOTSUPPORTED || res == AGENT_ERROR) - { - if(item.status == ITEM_STATUS_NOTSUPPORTED) + if (0 == CONFIG_DBSYNCER_FORKS) { - /* It is not correct */ -/* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d, lastclock=%d where itemid=%d",calculate_item_nextcheck(item.itemid, CONFIG_REFRESH_UNSUPPORTED,now), now, item.itemid);*/ - DBexecute("update items set nextcheck=%d, lastclock=%d where itemid=" ZBX_FS_UI64, - CONFIG_REFRESH_UNSUPPORTED+now, - now, - item.itemid); + DBbegin(); + + switch (zbx_process) { + case ZBX_PROCESS_SERVER: + process_new_value(&item, &agent, now); + update_triggers(item.itemid); + break; + case ZBX_PROCESS_PROXY: + proxy_process_new_value(&item, &agent, now); + break; + } + + DBcommit(); } else { + process_new_value(&item, &agent, now); + DCadd_nextcheck(&item, now, NULL); + } + } + else if (res == NOTSUPPORTED || res == AGENT_ERROR) + { + if (item.status != ITEM_STATUS_NOTSUPPORTED) + { zabbix_log(LOG_LEVEL_WARNING, "Parameter [%s] is not supported by agent on host [%s] Old status [%d]", item.key, item.host_name, @@ -458,89 +453,101 @@ int get_values(void) zabbix_syslog("Parameter [%s] is not supported by agent on host [%s]", item.key, item.host_name); + } - switch (zbx_process) { - case ZBX_PROCESS_SERVER: - DBupdate_item_status_to_notsupported(item.itemid, agent.msg); - break; - case ZBX_PROCESS_PROXY: - DBproxy_update_item_status_to_notsupported(item.itemid); - break; - } + if (0 == CONFIG_DBSYNCER_FORKS) + { + DBbegin(); + + DBupdate_item_status_to_notsupported(&item, now, agent.msg); - /* if(HOST_STATUS_UNREACHABLE == item.host_status)*/ - if (HOST_AVAILABLE_TRUE != item.host_available) { - enable_host(&item, now, agent.msg); - stop = 1; - } + DBcommit(); + } + else + DCadd_nextcheck(&item, now, agent.msg); + + if (HOST_AVAILABLE_TRUE != item.host_available) { + DBbegin(); + + enable_host(&item, now); + stop = 1; + + DBcommit(); } } - else if(res == NETWORK_ERROR) + else if (res == NETWORK_ERROR) { + DBbegin(); + /* First error */ - if(item.host_errors_from==0) + if (item.host_errors_from == 0) { zabbix_log( LOG_LEVEL_WARNING, "Host [%s]: first network error, wait for %d seconds", - item.host_name, - CONFIG_UNREACHABLE_DELAY); + item.host_name, + CONFIG_UNREACHABLE_DELAY); zabbix_syslog("Host [%s]: first network error, wait for %d seconds", - item.host_name, - CONFIG_UNREACHABLE_DELAY); + item.host_name, + CONFIG_UNREACHABLE_DELAY); - item.host_errors_from=now; DBexecute("update hosts set errors_from=%d,disable_until=%d where hostid=" ZBX_FS_UI64, - now, - now+CONFIG_UNREACHABLE_DELAY, - item.hostid); + now, + now + CONFIG_UNREACHABLE_DELAY, + item.hostid); + + item.host_errors_from = now; delay = MIN(4*item.delay, 300); - zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] will be checked after %d seconds on host [%s]", - item.key, - delay, - item.host_name); + + zabbix_log(LOG_LEVEL_WARNING, "Parameter [%s] will be checked after %d seconds on host [%s]", + item.key, + delay, + item.host_name); + DBexecute("update items set nextcheck=%d where itemid=" ZBX_FS_UI64, - now + delay, - item.itemid); + now + delay, + item.itemid); } else { - if (now - item.host_errors_from > CONFIG_UNREACHABLE_PERIOD) { + if (now - item.host_errors_from > CONFIG_UNREACHABLE_PERIOD) + { disable_host(&item, now, agent.msg); } - /* Still unavailable, but won't change status to UNAVAILABLE yet */ else { - zabbix_log( LOG_LEVEL_WARNING, "Host [%s]: another network error, wait for %d seconds", - item.host_name, - CONFIG_UNREACHABLE_DELAY); + /* Still unavailable, but won't change status to UNAVAILABLE yet */ + zabbix_log(LOG_LEVEL_WARNING, "Host [%s]: another network error, wait for %d seconds", + item.host_name, + CONFIG_UNREACHABLE_DELAY); zabbix_syslog("Host [%s]: another network error, wait for %d seconds", - item.host_name, - CONFIG_UNREACHABLE_DELAY); + item.host_name, + CONFIG_UNREACHABLE_DELAY); DBexecute("update hosts set disable_until=%d where hostid=" ZBX_FS_UI64, - now+CONFIG_UNREACHABLE_DELAY, - item.hostid); + now + CONFIG_UNREACHABLE_DELAY, + item.hostid); } } - zbx_snprintf(tmp,sizeof(tmp)-1,"," ZBX_FS_UI64,item.hostid); - unreachable_hosts=zbx_strdcat(unreachable_hosts,tmp); + DBcommit(); -/* stop=1;*/ + zbx_snprintf_alloc(&unreachable_hosts, &unreachable_hosts_alloc, &unreachable_hosts_offset, 32, + "%s" ZBX_FS_UI64, + 0 == unreachable_hosts_offset ? "" : ",", + item.hostid); } else { - zabbix_log( LOG_LEVEL_CRIT, "Unknown response code returned."); + zabbix_log(LOG_LEVEL_CRIT, "Unknown response code returned."); assert(0==1); } /* Poller for unreachable hosts */ - if(poller_type == ZBX_POLLER_TYPE_UNREACHABLE) + if (poller_type == ZBX_POLLER_TYPE_UNREACHABLE) { /* We cannot freeit earlier because items has references to the structure */ DBfree_result(result2); } free_result(&agent); - DBcommit(); items++; } @@ -548,7 +555,12 @@ int get_values(void) zbx_free(unreachable_hosts); DBfree_result(result); - zabbix_log( LOG_LEVEL_DEBUG, "End get_values()"); + + if (0 != CONFIG_DBSYNCER_FORKS) + DCflush_nextchecks(); + + zabbix_log(LOG_LEVEL_DEBUG, "End get_values()"); + return items; } @@ -556,7 +568,7 @@ void main_poller_loop(zbx_process_t p, int type, int num) { struct sigaction phan; int now; - int nextcheck, sleeptime; + int /*nextcheck, */sleeptime; int items; double sec; @@ -579,31 +591,32 @@ void main_poller_loop(zbx_process_t p, int type, int num) zbx_setproctitle("poller [getting values]"); now = time(NULL); - sec = zbx_time(); - items = get_values(); + items = get_values(now); sec = zbx_time() - sec; - nextcheck = get_minnextcheck(now); +/* nextcheck = get_minnextcheck(now);*/ - zabbix_log(LOG_LEVEL_DEBUG, "Poller spent " ZBX_FS_DBL " seconds while updating %3d values. Nextcheck: %d Time: %d", + zabbix_log(LOG_LEVEL_DEBUG, "Poller spent " ZBX_FS_DBL " seconds while updating %3d values." + /*" Nextcheck: %d Time: %d"*/, sec, - items, + items/*, nextcheck, - (int)time(NULL)); + (int)time(NULL)*/); - if( FAIL == nextcheck) +/* if( FAIL == nextcheck) { sleeptime=POLLER_DELAY; } else { - sleeptime=nextcheck-time(NULL); + sleeptime=nextcheck-time(NULL);*/ + sleeptime = now - time(NULL) + 1; if(sleeptime<0) { sleeptime=0; } - } +/* }*/ if(sleeptime>0) { if(sleeptime > POLLER_DELAY) diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index 272bdf8d..89982cf7 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -117,7 +117,7 @@ static char shortopts[] = pid_t *threads=NULL; int CONFIG_ALERTER_FORKS = 1; -int CONFIG_DBSYNCER_FORKS = 0; +int CONFIG_DBSYNCER_FORKS = 1; int CONFIG_DISCOVERER_FORKS = 1; int CONFIG_HOUSEKEEPER_FORKS = 1; int CONFIG_NODEWATCHER_FORKS = 1; @@ -195,7 +195,7 @@ void init_config(void) static struct cfg_line cfg[]= { /* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX */ -/* {"StartDBSyncers",&CONFIG_DBSYNCER_FORKS,0,TYPE_INT,PARM_OPT,0,1},*/ + {"StartDBSyncers",&CONFIG_DBSYNCER_FORKS,0,TYPE_INT,PARM_OPT,0,16}, {"StartDiscoverers",&CONFIG_DISCOVERER_FORKS,0,TYPE_INT,PARM_OPT,0,255}, {"StartHTTPPollers",&CONFIG_HTTPPOLLER_FORKS,0,TYPE_INT,PARM_OPT,0,255}, {"StartPingers",&CONFIG_PINGER_FORKS,0,TYPE_INT,PARM_OPT,0,255}, @@ -929,7 +929,7 @@ int main(int argc, char **argv) if(CONFIG_DBSYNCER_FORKS!=0) { - init_database_cache(); + init_database_cache(ZBX_PROCESS_SERVER); } switch (task) { @@ -1073,10 +1073,10 @@ int MAIN_ZABBIX_ENTRY(void) trend(); return 0; #endif - threads = calloc(1+CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS+CONFIG_PINGER_FORKS+CONFIG_ALERTER_FORKS - +CONFIG_HOUSEKEEPER_FORKS+CONFIG_TIMER_FORKS+CONFIG_UNREACHABLE_POLLER_FORKS - +CONFIG_NODEWATCHER_FORKS+CONFIG_HTTPPOLLER_FORKS+CONFIG_DISCOVERER_FORKS+CONFIG_ESCALATOR_FORKS, - sizeof(pid_t)); + threads = calloc(1 + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_ALERTER_FORKS + + CONFIG_HOUSEKEEPER_FORKS + CONFIG_TIMER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS + + CONFIG_NODEWATCHER_FORKS + CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS + CONFIG_DBSYNCER_FORKS + + CONFIG_ESCALATOR_FORKS, sizeof(pid_t)); if(CONFIG_TRAPPERD_FORKS > 0) { @@ -1087,8 +1087,10 @@ int MAIN_ZABBIX_ENTRY(void) } } - for( i=1; - i<=CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS+CONFIG_PINGER_FORKS+CONFIG_ALERTER_FORKS+CONFIG_HOUSEKEEPER_FORKS+CONFIG_TIMER_FORKS+CONFIG_UNREACHABLE_POLLER_FORKS+CONFIG_NODEWATCHER_FORKS+CONFIG_HTTPPOLLER_FORKS+CONFIG_DISCOVERER_FORKS+CONFIG_DBSYNCER_FORKS+CONFIG_ESCALATOR_FORKS; + for ( i = 1; i <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_ALERTER_FORKS + + CONFIG_HOUSEKEEPER_FORKS + CONFIG_TIMER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS + + CONFIG_NODEWATCHER_FORKS + CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS + CONFIG_DBSYNCER_FORKS + + CONFIG_ESCALATOR_FORKS; i++) { if((pid = zbx_fork()) == 0) @@ -1247,10 +1249,13 @@ void zbx_on_exit() if(threads != NULL) { - for(i = 1; i <= CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS+CONFIG_PINGER_FORKS+CONFIG_ALERTER_FORKS+CONFIG_HOUSEKEEPER_FORKS+CONFIG_TIMER_FORKS+CONFIG_UNREACHABLE_POLLER_FORKS+CONFIG_NODEWATCHER_FORKS+CONFIG_HTTPPOLLER_FORKS+CONFIG_DISCOVERER_FORKS+CONFIG_DBSYNCER_FORKS+CONFIG_ESCALATOR_FORKS; i++) + for (i = 1; i <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_ALERTER_FORKS + + CONFIG_HOUSEKEEPER_FORKS + CONFIG_TIMER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS + + CONFIG_NODEWATCHER_FORKS + CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS + CONFIG_DBSYNCER_FORKS + + CONFIG_ESCALATOR_FORKS; i++) { - if(threads[i]) { - kill(threads[i],SIGTERM); + if (threads[i]) { + kill(threads[i], SIGTERM); threads[i] = (ZBX_THREAD_HANDLE)NULL; } } diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c index 621e9f78..22ba5a9b 100644 --- a/src/zabbix_server/trapper/trapper.c +++ b/src/zabbix_server/trapper/trapper.c @@ -27,6 +27,7 @@ #include "zlog.h" #include "zbxjson.h" #include "zbxserver.h" +#include "dbcache.h" #include "../nodewatcher/nodecomms.h" #include "../nodewatcher/nodesender.h" @@ -136,31 +137,41 @@ static void calc_timestamp(char *line,int *timestamp, char *format) * Comments: for trapper server process * * * ******************************************************************************/ -static int process_data(zbx_sock_t *sock, zbx_uint64_t proxy_hostid, time_t now, char *server, char *key, char *value, - char *lastlogsize, char *timestamp, char *source, char *severity) +static void process_mass_data(zbx_sock_t *sock, zbx_uint64_t proxy_hostid, AGENT_VALUE *values, int value_num, int *processed) { AGENT_RESULT agent; DB_RESULT result; DB_ROW row; DB_ITEM item; - char server_esc[MAX_STRING_LEN], key_esc[MAX_STRING_LEN]; - char item_types[32]; + char host_esc[MAX_STRING_LEN], key_esc[MAX_STRING_LEN]; + static char *sql = NULL; + static int sql_allocated = 65536; + int sql_offset = 0, i; - zabbix_log(LOG_LEVEL_DEBUG, "In process_data([%s],[%s],[%s],[%s])", - server, - key, - value, - lastlogsize); + zabbix_log(LOG_LEVEL_DEBUG, "In process_mass_data()"); - DBescape_string(server, server_esc, MAX_STRING_LEN); - DBescape_string(key, key_esc, MAX_STRING_LEN); + if (NULL == sql) + sql = zbx_malloc(sql, sql_allocated); - if (proxy_hostid == 0) { - zbx_snprintf(item_types, sizeof(item_types), "%d,%d", + zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 2048, + "select %s where h.hostid=i.hostid and h.proxy_hostid=" ZBX_FS_UI64 + " and h.status=%d and i.status in (%d,%d)", + ZBX_SQL_ITEM_SELECT, + proxy_hostid, + HOST_STATUS_MONITORED, + ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED); + + if (proxy_hostid == 0) + { + zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, + " and i.type in (%d,%d)", ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE); - } else { - zbx_snprintf(item_types, sizeof(item_types), "%d,%d,%d,%d,%d,%d,%d,%d,%d", + } + else + { + zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 64, + " and i.type in (%d,%d,%d,%d,%d,%d,%d,%d,%d)", ITEM_TYPE_ZABBIX, ITEM_TYPE_SNMPv1, ITEM_TYPE_TRAPPER, @@ -172,112 +183,116 @@ static int process_data(zbx_sock_t *sock, zbx_uint64_t proxy_hostid, time_t now, ITEM_TYPE_EXTERNAL); } - result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and h.proxy_hostid=" ZBX_FS_UI64 - " and i.key_='%s' and i.status in (%d,%d) and i.type in (%s)" DB_NODE, - ZBX_SQL_ITEM_SELECT, - HOST_STATUS_MONITORED, - server_esc, - proxy_hostid, - key_esc, - ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, - item_types, + zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 8, " and ("); + + for (i = 0; i < value_num; i++) + { + DBescape_string(values[i].host_name, host_esc, sizeof(host_esc)); + DBescape_string(values[i].key, key_esc, sizeof(key_esc)); + zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 512, + "(h.host='%s' and i.key_='%s') or ", + host_esc, + key_esc); + } + + sql_offset -= 4; + zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 128, ")" DB_NODE, 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); + result = DBselect("%s", sql); - 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; - } -*/ - } + if (0 != CONFIG_DBSYNCER_FORKS) + DCinit_nextchecks(); - DBget_item_from_db(&item, row); + while (NULL != (row = DBfetch(result))) { + 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; - } + if (item.type == ITEM_TYPE_ZABBIX_ACTIVE && FAIL == zbx_tcp_check_security(sock, item.trapper_hosts, 1)) + continue; - 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); - } + for (i = 0; i < value_num; i++) + { + if (0 == strcmp(item.host_name, values[i].host_name) && 0 == strcmp(item.key, values[i].key)) { +/* zabbix_log(LOG_LEVEL_DEBUG, "Processing [%s@%s: \"%s\"]", + item.key, + item.host_name, + values[i].value);*/ - init_result(&agent); + if (0 == strcmp(values[i].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); - if( SUCCEED == set_result_type(&agent, item.value_type, value)) { - switch (zbx_process) { - case ZBX_PROCESS_SERVER: - process_new_value(&item, &agent, now); - update_triggers(item.itemid); - break; - case ZBX_PROCESS_PROXY: - proxy_process_new_value(&item, &agent, now); - break; + if (0 == CONFIG_DBSYNCER_FORKS) + DBupdate_item_status_to_notsupported(&item, values[i].clock, "Not supported by ZABBIX agent"); + else + DCadd_nextcheck(&item, values[i].clock, "Not supported by ZABBIX agent"); + + (*processed)++; + + } + else + { + if (0 == strncmp(item.key, "log[", 4) || 0 == strncmp(item.key, "eventlog[", 9)) + { + item.lastlogsize = values[i].lastlogsize; + item.timestamp = values[i].timestamp; + + calc_timestamp(values[i].value, &item.timestamp, item.logtimefmt); + + item.eventlog_severity = values[i].severity; + item.eventlog_source = values[i].source; + +/* zabbix_log(LOG_LEVEL_DEBUG, "Value [%s] Lastlogsize [%s] Timestamp [%s]", + values[i].value, + item.lastlogsize, + item.timestamp);*/ + } + + init_result(&agent); + + if (SUCCEED == set_result_type(&agent, item.value_type, values[i].value)) + { + if (0 == CONFIG_DBSYNCER_FORKS) + { + switch (zbx_process) { + case ZBX_PROCESS_SERVER: + process_new_value(&item, &agent, values[i].clock); + update_triggers(item.itemid); + break; + case ZBX_PROCESS_PROXY: + proxy_process_new_value(&item, &agent, values[i].clock); + break; + } + } + else + process_new_value(&item, &agent, values[i].clock); + (*processed)++; + } + else + { + zabbix_log( LOG_LEVEL_WARNING, "Type of received value [%s] is not suitable for [%s@%s]", + values[i].value, + item.key, + item.host_name); + zabbix_syslog("Type of received value [%s] is not suitable for [%s@%s]", + values[i].value, + item.key, + item.host_name); + } + free_result(&agent); + } } - } 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; + if (0 != CONFIG_DBSYNCER_FORKS) + DCflush_nextchecks(); } /****************************************************************************** @@ -315,6 +330,17 @@ int send_result(zbx_sock_t *sock, int result, char *info) return ret; } +static void clean_agent_values(AGENT_VALUE *values, int value_num) +{ + int i; + + for (i = 0; i < value_num; i ++) { + zbx_free(values[i].value); + if (NULL != values[i].source) + zbx_free(values[i].source); + } +} + /****************************************************************************** * * * Function: process_new_values * @@ -335,22 +361,29 @@ static int process_new_values(zbx_sock_t *sock, struct zbx_json_parse *jp, const { struct zbx_json_parse jp_data, jp_row; const char *p; - char host[HOST_HOST_LEN_MAX], key[ITEM_KEY_LEN_MAX], - value[MAX_STRING_LEN], info[MAX_STRING_LEN], lastlogsize[MAX_STRING_LEN], + char /*host[HOST_HOST_LEN_MAX], key[ITEM_KEY_LEN_MAX], + value[MAX_STRING_LEN], */info[MAX_STRING_LEN], /*lastlogsize[MAX_STRING_LEN], timestamp[MAX_STRING_LEN], source[MAX_STRING_LEN], severity[MAX_STRING_LEN], - clock[MAX_STRING_LEN]; + clock[MAX_STRING_LEN], */tmp[MAX_STRING_LEN]; int ret = SUCCEED; - int processed_ok = 0, processed_fail = 0; + int processed = 0, processed_fail = 0; double sec; - time_t now, hosttime = 0, itemtime; + time_t now, hosttime = 0/*, itemtime*/; + +#define VALUES_MAX 256 + static AGENT_VALUE *values = NULL; + int value_num = 0; zabbix_log(LOG_LEVEL_DEBUG, "In process_new_values()"); now = time(NULL); sec = zbx_time(); - if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_CLOCK, clock, sizeof(clock))) - hosttime = atoi(clock); + if (NULL == values) + values = zbx_malloc(values, VALUES_MAX * sizeof(AGENT_VALUE)); + + if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_CLOCK, tmp, sizeof(tmp))) + hosttime = atoi(tmp); /* {"request":"ZBX_SENDER_DATA","data":[{"key":"system.cpu.num",...,...},{...},...]} * ^ @@ -379,41 +412,52 @@ static int process_new_values(zbx_sock_t *sock, struct zbx_json_parse *jp, const */ if (FAIL == (ret = zbx_json_brackets_open(p, &jp_row))) break; - zabbix_log(LOG_LEVEL_DEBUG, "Next \"%.*s\"", +/* zabbix_log(LOG_LEVEL_DEBUG, "Next \"%.*s\"", jp_row.end - jp_row.start + 1, - jp_row.start); - - *host = '\0'; - *key = '\0'; - *value = '\0'; - *lastlogsize = '\0'; - *timestamp = '\0'; - *source = '\0'; - *severity = '\0'; - itemtime = now; - - if (hosttime) - if (SUCCEED == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_CLOCK, clock, sizeof(clock))) - itemtime -= hosttime - atoi(clock); + jp_row.start);*/ + + memset(&values[value_num], 0, sizeof(AGENT_VALUE)); - if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_HOST, host, sizeof(host))) + values[value_num].clock = now; + + if (hosttime && SUCCEED == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_CLOCK, tmp, sizeof(tmp))) + values[value_num].clock -= hosttime - atoi(tmp); + + if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_HOST, values[value_num].host_name, sizeof(values[value_num].host_name))) continue; - if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_KEY, key, sizeof(key))) + if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_KEY, values[value_num].key, sizeof(values[value_num].key))) continue; - if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_VALUE, value, sizeof(value))) + if (FAIL == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_VALUE, tmp, sizeof(tmp))) continue; - zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_LOGLASTSIZE, lastlogsize, sizeof(lastlogsize)); + values[value_num].value = strdup(tmp); - zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_LOGTIMESTAMP, timestamp, sizeof(timestamp)); + if (SUCCEED == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_LOGLASTSIZE, tmp, sizeof(tmp))) + values[value_num].lastlogsize = atoi(tmp); - zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_LOGSOURCE, source, sizeof(source)); + if (SUCCEED == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_LOGTIMESTAMP, tmp, sizeof(tmp))) + values[value_num].timestamp = atoi(tmp); - zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_LOGSEVERITY, severity, sizeof(severity)); + if (SUCCEED == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_LOGSOURCE, tmp, sizeof(tmp))) + values[value_num].source = strdup(tmp); - DBbegin(); + if (SUCCEED == zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_LOGSEVERITY, tmp, sizeof(tmp))) + values[value_num].severity = atoi(tmp); + + value_num ++; + + if (value_num == VALUES_MAX) { + DBbegin(); + process_mass_data(sock, proxy_hostid, values, value_num, &processed); + DBcommit(); + + clean_agent_values(values, value_num); + value_num = 0; + } + +/* DBbegin(); if(SUCCEED == process_data(sock, proxy_hostid, itemtime, host, key, value, lastlogsize, timestamp, source, severity)) { processed_ok ++; @@ -422,16 +466,24 @@ static int process_new_values(zbx_sock_t *sock, struct zbx_json_parse *jp, const { processed_fail ++; } + DBcommit();*/ + } + + if (value_num > 0) { + DBbegin(); + process_mass_data(sock, proxy_hostid, values, value_num, &processed); DBcommit(); } - zbx_snprintf(info,sizeof(info),"Processed %d Failed %d Total %d Seconds spent " ZBX_FS_DBL, - processed_ok, + clean_agent_values(values, value_num); + + zbx_snprintf(info, sizeof(info), "Processed %d Failed %d Total %d Seconds spent " ZBX_FS_DBL, + processed, processed_fail, - processed_ok+processed_fail, - (double)(zbx_time()-sec)); + processed + processed_fail, + zbx_time() - sec); - if(send_result(sock, ret, info) != SUCCEED) + if (send_result(sock, ret, info) != SUCCEED) { zabbix_log( LOG_LEVEL_WARNING, "Error sending result back"); zabbix_syslog("Trapper: error sending result back"); @@ -676,7 +728,7 @@ static int process_trap(zbx_sock_t *sock, char *s, int max_len) zabbix_log( LOG_LEVEL_DEBUG, "Value [%s]", value_string); DBbegin(); - ret=process_data(sock, 0, time(NULL), server, key, value_string, lastlogsize, timestamp, source, severity); +/* ret=process_data(sock, 0, time(NULL), server, key, value_string, lastlogsize, timestamp, source, severity);*/ DBcommit(); if( zbx_tcp_send_raw(sock, SUCCEED == ret ? "OK" : "NOT OK") != SUCCEED) diff --git a/src/zabbix_server/trapper/trapper.h b/src/zabbix_server/trapper/trapper.h index 01a3e91b..5cdc66b5 100644 --- a/src/zabbix_server/trapper/trapper.h +++ b/src/zabbix_server/trapper/trapper.h @@ -23,6 +23,20 @@ #include "common.h" #include "comms.h" +#define AGENT_VALUE struct zbx_agent_value_t + +AGENT_VALUE +{ + int clock; + char host_name[HOST_HOST_LEN_MAX]; + char key[ITEM_KEY_LEN_MAX]; + char *value; + int lastlogsize; + int timestamp; + char *source; + int severity; +}; + int send_result(zbx_sock_t *sock, int result, char *info); void child_trapper_main(zbx_process_t p, zbx_sock_t *s); diff --git a/src/zabbix_server/zlog.c b/src/zabbix_server/zlog.c index e44d10ce..dac1e760 100644 --- a/src/zabbix_server/zlog.c +++ b/src/zabbix_server/zlog.c @@ -66,11 +66,14 @@ 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" DB_NODE, - ZBX_SQL_ITEM_SELECT, - SERVER_ZABBIXLOG_KEY, - ITEM_VALUE_TYPE_STR, - DBnode_local("h.hostid")); + result = DBselect("select %s where h.hostid=i.hostid and h.status=%d and i.status=%d" + " and h.proxy_hostid=0 and i.key_='%s' and i.value_type=%d" DB_NODE, + ZBX_SQL_ITEM_SELECT, + ITEM_STATUS_ACTIVE, + HOST_STATUS_MONITORED, + SERVER_ZABBIXLOG_KEY, + ITEM_VALUE_TYPE_STR, + DBnode_local("h.hostid")); now = time(NULL); @@ -85,10 +88,16 @@ void __zbx_zabbix_syslog(const char *fmt, ...) init_result(&agent); SET_STR_RESULT(&agent, strdup(value_str)); - process_new_value(&item, &agent, now); - free_result(&agent); - update_triggers(item.itemid); + if (0 == CONFIG_DBSYNCER_FORKS) + { + process_new_value(&item, &agent, now); + update_triggers(item.itemid); + } + else + process_new_value(&item, &agent, now); + + free_result(&agent); } DBfree_result(result); |
