diff options
| author | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-08-19 14:46:46 +0000 |
|---|---|---|
| committer | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-08-19 14:46:46 +0000 |
| commit | 0da47bd8beaf0d5797fb7275c30931270ad64262 (patch) | |
| tree | f135f252f47219e8dc1800b6b238846f4277a577 | |
| parent | e4a407bb62085b1103d10380e350e2ef72bc5bdf (diff) | |
| download | zabbix-0da47bd8beaf0d5797fb7275c30931270ad64262.tar.gz zabbix-0da47bd8beaf0d5797fb7275c30931270ad64262.tar.xz zabbix-0da47bd8beaf0d5797fb7275c30931270ad64262.zip | |
- [ZBX-406] added error messages if fping is not installed
git-svn-id: svn://svn.zabbix.com/trunk@5930 97f52cf1-0a1b-0410-bd0e-c28be96e8082
| -rw-r--r-- | ChangeLog | 4 | ||||
| -rw-r--r-- | include/zbxicmpping.h | 2 | ||||
| -rw-r--r-- | misc/conf/zabbix_proxy.conf | 7 | ||||
| -rw-r--r-- | misc/conf/zabbix_server.conf | 3 | ||||
| -rw-r--r-- | src/libs/zbxdbcache/dbcache.c | 11 | ||||
| -rw-r--r-- | src/libs/zbxdbcache/nextchecks.c | 2 | ||||
| -rw-r--r-- | src/libs/zbxicmpping/icmpping.c | 184 | ||||
| -rw-r--r-- | src/zabbix_proxy/proxy.c | 6 | ||||
| -rw-r--r-- | src/zabbix_server/discoverer/discoverer.c | 4 | ||||
| -rw-r--r-- | src/zabbix_server/pinger/pinger.c | 206 | ||||
| -rw-r--r-- | src/zabbix_server/server.c | 6 |
11 files changed, 271 insertions, 164 deletions
@@ -1,3 +1,7 @@ +Changes for 1.5.5 + + - [ZBX-406] added error messages if fping is not installed (Sasha) + Changes for 1.5.4 - [DEV-203] fixed probem with permissions of server's shared memory (Sasha) diff --git a/include/zbxicmpping.h b/include/zbxicmpping.h index f50db556..d86c20ef 100644 --- a/include/zbxicmpping.h +++ b/include/zbxicmpping.h @@ -29,4 +29,4 @@ ZBX_FPING_HOST double sec; }; -int do_ping(ZBX_FPING_HOST *hosts, int hosts_count); +int do_ping(ZBX_FPING_HOST *hosts, int hosts_count, char *error, int max_error_len); diff --git a/misc/conf/zabbix_proxy.conf b/misc/conf/zabbix_proxy.conf index ac23ce68..7363cd37 100644 --- a/misc/conf/zabbix_proxy.conf +++ b/misc/conf/zabbix_proxy.conf @@ -137,6 +137,13 @@ AlertScriptsPath=/home/zabbix/bin/ # Make sure that fping binary has root permissions and SUID flag set #FpingLocation=/usr/sbin/fping +# Location of fping6. Default is /usr/sbin/fping6 +# Make sure that fping binary has root permissions and SUID flag set +#Fping6Location=/usr/sbin/fping6 + +# Temporary directory. Default is /tmp +#TmpDir=/tmp + # Frequency of ICMP pings (item keys 'icmpping' and 'icmppingsec'). Defauls is 60 seconds. #PingerFrequency=60 diff --git a/misc/conf/zabbix_server.conf b/misc/conf/zabbix_server.conf index dfc17860..323ee071 100644 --- a/misc/conf/zabbix_server.conf +++ b/misc/conf/zabbix_server.conf @@ -121,6 +121,9 @@ AlertScriptsPath=/home/zabbix/bin/ # Make sure that fping binary has root permissions and SUID flag set #Fping6Location=/usr/sbin/fping6 +# Temporary directory. Default is /tmp +#TmpDir=/tmp + # Frequency of ICMP pings (item keys 'icmpping' and 'icmppingsec'). Defauls is 60 seconds. #PingerFrequency=60 diff --git a/src/libs/zbxdbcache/dbcache.c b/src/libs/zbxdbcache/dbcache.c index 98785742..a98ed813 100644 --- a/src/libs/zbxdbcache/dbcache.c +++ b/src/libs/zbxdbcache/dbcache.c @@ -328,10 +328,7 @@ static void DCmass_update_item(ZBX_DC_HISTORY *history, int history_num) } } - zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 128, " where itemid=" ZBX_FS_UI64 ";\n", - item.itemid); - -/* Update item status if required */ + /* Update item status if required */ if (item.status == ITEM_STATUS_NOTSUPPORTED) { zabbix_log(LOG_LEVEL_WARNING, "Parameter [%s] became supported by agent on host [%s]", @@ -341,11 +338,13 @@ static void DCmass_update_item(ZBX_DC_HISTORY *history, int history_num) item.key, item.host_name); - zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 128, - "update items set status=%d,error='' where itemid=" ZBX_FS_UI64 ";\n", + zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 128, ",status=%d,error=''", ITEM_STATUS_ACTIVE, item.itemid); } + + zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 128, " where itemid=" ZBX_FS_UI64 ";\n", + item.itemid); } DBfree_result(result); diff --git a/src/libs/zbxdbcache/nextchecks.c b/src/libs/zbxdbcache/nextchecks.c index ba389598..c0c9b855 100644 --- a/src/libs/zbxdbcache/nextchecks.c +++ b/src/libs/zbxdbcache/nextchecks.c @@ -107,7 +107,7 @@ void DCadd_nextcheck(DB_ITEM *item, time_t now, time_t timediff, const char *err nextchecks = zbx_realloc(nextchecks, nextcheck_allocated * sizeof(ZBX_DC_NEXTCHECK)); } - nextcheck = calculate_item_nextcheck(item->itemid, item->type, item->delay, item->delay_flex, now - timediff) + timediff; + nextcheck = NULL == error_msg ? calculate_item_nextcheck(item->itemid, item->type, item->delay, item->delay_flex, now - timediff) + timediff : now; index = DCget_nextcheck_nearestindex(nextcheck); memmove(&nextchecks[index + 1], &nextchecks[index], sizeof(ZBX_DC_NEXTCHECK) * (nextcheck_num - index)); diff --git a/src/libs/zbxicmpping/icmpping.c b/src/libs/zbxicmpping/icmpping.c index 983bb16c..64dfa9ed 100644 --- a/src/libs/zbxicmpping/icmpping.c +++ b/src/libs/zbxicmpping/icmpping.c @@ -27,87 +27,90 @@ extern char *CONFIG_FPING_LOCATION; #ifdef HAVE_IPV6 extern char *CONFIG_FPING6_LOCATION; #endif /* HAVE_IPV6 */ +extern char *CONFIG_TMPDIR; -/****************************************************************************** - * * - * Function: do_ping * - * * - * Purpose: ping hosts listed in the host files * - * * - * Parameters: * - * * - * Return value: => 0 - successfully processed items * - * FAIL - otherwise * - * * - * Author: Alexei Vladishev * - * * - * Comments: use external binary 'fping' to avoid superuser priviledges * - * * - ******************************************************************************/ -int do_ping(ZBX_FPING_HOST *hosts, int hosts_count) +#ifdef HAVE_IPV6 +static int get_address_family(const char *addr, int *family, char *error, int max_error_len) +{ + struct addrinfo hints, *ai = NULL; + int err, res = NOTSUPPORTED; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_flags = AI_NUMERICHOST; + hints.ai_socktype = SOCK_STREAM; + + if (0 != (err = getaddrinfo(addr, NULL, &hints, &ai))) + { + zbx_snprintf(error, max_error_len, "%s: [%d] %s", addr, err, gai_strerror(err)); + goto out; + } + + if (ai->ai_family != PF_INET && ai->ai_family != PF_INET6) + { + zbx_snprintf(error, max_error_len, "%s: Unsupported address family", addr); + goto out; + } + + *family = (int)ai->ai_family; + + res = SUCCEED; +out: + if (NULL != ai) + freeaddrinfo(ai); + + return res; +} +#endif /* HAVE_IPV6 */ + +static int process_ping(ZBX_FPING_HOST *hosts, int hosts_count, char *error, int max_error_len) { FILE *f; - char filename[MAX_STRING_LEN]; - char tmp[MAX_STRING_LEN]; - int i, res = FAIL; - char *c, source_ip[64]; + char filename[MAX_STRING_LEN], tmp[MAX_STRING_LEN], + *c, source_ip[64]; + int i; ZBX_FPING_HOST *host; #ifdef HAVE_IPV6 - struct addrinfo hints, *ai = NULL; char *fping; - int e; + int family; #endif - zabbix_log(LOG_LEVEL_DEBUG, "In do_ping() [hosts_count:%d]", - hosts_count); - - zbx_snprintf(filename, sizeof(filename), "/tmp/zabbix_server_%li.pinger", - zbx_get_thread_id()); + assert(hosts); - if (NULL == (f = fopen(filename, "w"))) { - zabbix_log(LOG_LEVEL_ERR, "Cannot open file [%s] [%s]", - filename, - strerror(errno)); - zabbix_syslog("Cannot open file [%s] [%s]", - filename, - strerror(errno)); - return FAIL; - } - - for (i = 0; i < hosts_count; i++) - fprintf(f, "%s\n", hosts[i].addr); - - fclose(f); + zabbix_log(LOG_LEVEL_DEBUG, "In process_ping() [hosts_count:%d]", + hosts_count); if (NULL != CONFIG_SOURCE_IP) zbx_snprintf(source_ip, sizeof(source_ip), "-S%s ", CONFIG_SOURCE_IP); else *source_ip = '\0'; + zbx_snprintf(filename, sizeof(filename), "%s/zabbix_server_%li.pinger", + CONFIG_TMPDIR, + zbx_get_thread_id()); + + if (access(CONFIG_FPING_LOCATION, F_OK|X_OK) == -1) + { + zbx_snprintf(error, max_error_len, "%s: [%d] %s", CONFIG_FPING_LOCATION, errno, strerror(errno)); + return NOTSUPPORTED; + } + #ifdef HAVE_IPV6 + if (access(CONFIG_FPING6_LOCATION, F_OK|X_OK) == -1) + { + zbx_snprintf(error, max_error_len, "%s: [%d] %s", CONFIG_FPING6_LOCATION, errno, strerror(errno)); + return NOTSUPPORTED; + } + if (NULL != CONFIG_SOURCE_IP) { - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_flags = AI_NUMERICHOST; - hints.ai_socktype = SOCK_STREAM; - - if (0 != (e = getaddrinfo(CONFIG_SOURCE_IP, NULL, &hints, &ai))) - { - zabbix_log(LOG_LEVEL_WARNING, "Cannot resolve address [%s], error %d: %s", - CONFIG_SOURCE_IP, e, gai_strerror(e)); - goto out; - } + if (NOTSUPPORTED == get_address_family(CONFIG_SOURCE_IP, &family, error, max_error_len)) + return NOTSUPPORTED; - if (ai->ai_family == PF_INET) + if (family == PF_INET) fping = CONFIG_FPING_LOCATION; - else if (ai->ai_family == PF_INET6) - fping = CONFIG_FPING6_LOCATION; else - { - zabbix_log(LOG_LEVEL_WARNING, "Unsupported address family [%s]", CONFIG_SOURCE_IP); - goto out; - } + fping = CONFIG_FPING6_LOCATION; zbx_snprintf(tmp, sizeof(tmp), "%s %s-c3 2>/dev/null <%s", fping, @@ -127,14 +130,24 @@ int do_ping(ZBX_FPING_HOST *hosts, int hosts_count) filename); #endif /* HAVE_IPV6 */ + if (NULL == (f = fopen(filename, "w"))) { + zbx_snprintf(error, max_error_len, "%s: [%d] %s", filename, errno, strerror(errno)); + return NOTSUPPORTED; + } + + for (i = 0; i < hosts_count; i++) + fprintf(f, "%s\n", hosts[i].addr); + + fclose(f); + + zabbix_log(LOG_LEVEL_DEBUG, "%s", tmp); + if (0 == (f = popen(tmp, "r"))) { - zabbix_log(LOG_LEVEL_ERR, "Cannot execute [%s] [%s]", - CONFIG_FPING_LOCATION, - strerror(errno)); - zabbix_syslog("Cannot execute [%s] [%s]", - CONFIG_FPING_LOCATION, - strerror(errno)); - goto out; + zbx_snprintf(error, max_error_len, "%s: [%d] %s", tmp, errno, strerror(errno)); + + unlink(filename); + + return NOTSUPPORTED; } while (NULL != fgets(tmp, sizeof(tmp), f)) { @@ -165,17 +178,38 @@ int do_ping(ZBX_FPING_HOST *hosts, int hosts_count) } pclose(f); - res = SUCCEED; -out: unlink(filename); -#ifdef HAVE_IPV6 - if (NULL != ai) - freeaddrinfo(ai); -#endif + zabbix_log(LOG_LEVEL_DEBUG, "End of process_ping()"); + + return SUCCEED; +} + +/****************************************************************************** + * * + * Function: do_ping * + * * + * Purpose: ping hosts listed in the host files * + * * + * Parameters: * + * * + * Return value: => 0 - successfully processed items * + * FAIL - otherwise * + * * + * Author: Alexei Vladishev * + * * + * Comments: use external binary 'fping' to avoid superuser priviledges * + * * + ******************************************************************************/ +int do_ping(ZBX_FPING_HOST *hosts, int hosts_count, char *error, int max_error_len) +{ + int res; - zabbix_log(LOG_LEVEL_DEBUG, "End of do_ping()"); + if (NOTSUPPORTED == (res = process_ping(hosts, hosts_count, error, max_error_len))) + { + zabbix_log(LOG_LEVEL_ERR, "%s", error); + zabbix_syslog("%s", error); + } return res; } - diff --git a/src/zabbix_proxy/proxy.c b/src/zabbix_proxy/proxy.c index 7d86280a..784b577f 100644 --- a/src/zabbix_proxy/proxy.c +++ b/src/zabbix_proxy/proxy.c @@ -142,6 +142,7 @@ int CONFIG_UNAVAILABLE_DELAY = 60; int CONFIG_LOG_LEVEL = LOG_LEVEL_WARNING; char *CONFIG_ALERT_SCRIPTS_PATH = NULL; char *CONFIG_EXTERNALSCRIPTS = NULL; +char *CONFIG_TMPDIR = NULL; char *CONFIG_FPING_LOCATION = NULL; #ifdef HAVE_IPV6 char *CONFIG_FPING6_LOCATION = NULL; @@ -218,6 +219,7 @@ void init_config(void) /* {"SenderFrequency",&CONFIG_SENDER_FREQUENCY,0,TYPE_INT,PARM_OPT,5,3600},*/ {"PingerFrequency",&CONFIG_PINGER_FREQUENCY,0,TYPE_INT,PARM_OPT,1,3600}, + {"TmpDir",&CONFIG_TMPDIR,0,TYPE_STRING,PARM_OPT,0,0}, {"FpingLocation",&CONFIG_FPING_LOCATION,0,TYPE_STRING,PARM_OPT,0,0}, #ifdef HAVE_IPV6 {"Fping6Location",&CONFIG_FPING6_LOCATION,0,TYPE_STRING,PARM_OPT,0,0}, @@ -281,6 +283,10 @@ void init_config(void) { CONFIG_ALERT_SCRIPTS_PATH=strdup("/home/zabbix/bin"); } + if(CONFIG_TMPDIR == NULL) + { + CONFIG_TMPDIR=strdup("/tmp"); + } if(CONFIG_FPING_LOCATION == NULL) { CONFIG_FPING_LOCATION=strdup("/usr/sbin/fping"); diff --git a/src/zabbix_server/discoverer/discoverer.c b/src/zabbix_server/discoverer/discoverer.c index 20dfef88..3813db0a 100644 --- a/src/zabbix_server/discoverer/discoverer.c +++ b/src/zabbix_server/discoverer/discoverer.c @@ -523,7 +523,7 @@ static void proxy_update_host(zbx_uint64_t druleid, char *ip, int status, int no static int discover_service(DB_DCHECK *check, char *ip, int port) { int ret = SUCCEED; - char key[MAX_STRING_LEN]; + char key[MAX_STRING_LEN], error[ITEM_ERROR_LEN_MAX]; AGENT_RESULT value; DB_ITEM item; ZBX_FPING_HOST host; @@ -667,7 +667,7 @@ static int discover_service(DB_DCHECK *check, char *ip, int port) strscpy(host.addr, ip); host.useip = 1; - if (SUCCEED == do_ping(&host, 1)) { + if (SUCCEED == do_ping(&host, 1, error, sizeof(error))) { if (0 == host.alive) ret = FAIL; } else diff --git a/src/zabbix_server/pinger/pinger.c b/src/zabbix_server/pinger/pinger.c index efb5e618..dce6ef67 100644 --- a/src/zabbix_server/pinger/pinger.c +++ b/src/zabbix_server/pinger/pinger.c @@ -33,6 +33,9 @@ static zbx_process_t zbx_process; static int pinger_num; +static ZBX_FPING_HOST *hosts = NULL; +static int hosts_allocated = 4; + /****************************************************************************** * * * Function: process_value * @@ -51,12 +54,13 @@ static int pinger_num; * Comments: can be done in process_data() * * * ******************************************************************************/ -static void process_value(char *key, ZBX_FPING_HOST *host, zbx_uint64_t *value_ui64, double *value_dbl, int now, int *items) +static void process_value(char *key, ZBX_FPING_HOST *host, zbx_uint64_t *value_ui64, double *value_dbl, int now, int *items, int ping_result, const char *error) { DB_RESULT result; DB_ROW row; DB_ITEM item; AGENT_RESULT value; + char istatus[16]; assert(value_ui64 || value_dbl); @@ -64,8 +68,16 @@ static void process_value(char *key, ZBX_FPING_HOST *host, zbx_uint64_t *value_u key, host->addr); + if (0 != CONFIG_REFRESH_UNSUPPORTED) + zbx_snprintf(istatus, sizeof(istatus), "%d,%d", + ITEM_STATUS_ACTIVE, + ITEM_STATUS_NOTSUPPORTED); + else + zbx_snprintf(istatus, sizeof(istatus), "%d", + ITEM_STATUS_ACTIVE); + result = DBselect("select %s where " ZBX_SQL_MOD(h.hostid,%d) "=%d and h.status=%d and h.hostid=i.hostid" - " and h.proxy_hostid=0 and h.useip=%d and h.%s='%s' and i.key_='%s' and i.status=%d" + " and h.proxy_hostid=0 and h.useip=%d and h.%s='%s' and i.key_='%s' and i.status in (%s)" " and i.type=%d and i.nextcheck<=%d" DB_NODE, ZBX_SQL_ITEM_SELECT, CONFIG_PINGER_FORKS, @@ -75,7 +87,7 @@ static void process_value(char *key, ZBX_FPING_HOST *host, zbx_uint64_t *value_u host->useip ? "ip" : "dns", host->addr, key, - ITEM_STATUS_ACTIVE, + istatus, ITEM_TYPE_SIMPLE, now, DBnode_local("h.hostid")); @@ -83,45 +95,61 @@ static void process_value(char *key, ZBX_FPING_HOST *host, zbx_uint64_t *value_u while (NULL != (row = DBfetch(result))) { DBget_item_from_db(&item, row); - init_result(&value); - - if (NULL != value_ui64) + if (ping_result == NOTSUPPORTED) { - SET_UI64_RESULT(&value, *value_ui64); - } - else - { - SET_DBL_RESULT(&value, *value_dbl); - } + if (0 == CONFIG_DBSYNCER_FORKS) + { + DBbegin(); + + DBupdate_item_status_to_notsupported(&item, now, error); - 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 + DCadd_nextcheck(&item, now, 0, error); } else { - switch (zbx_process) { - case ZBX_PROCESS_SERVER: - process_new_value(&item, &value, now); - break; - case ZBX_PROCESS_PROXY: - proxy_process_new_value(&item, &value, now); - break; + init_result(&value); + + if (NULL != value_ui64) + { + SET_UI64_RESULT(&value, *value_ui64); + } + else + { + SET_DBL_RESULT(&value, *value_dbl); } - DCadd_nextcheck(&item, now, 0, NULL); - } - free_result(&value); + 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 + { + switch (zbx_process) { + case ZBX_PROCESS_SERVER: + process_new_value(&item, &value, now); + break; + case ZBX_PROCESS_PROXY: + proxy_process_new_value(&item, &value, now); + break; + } + DCadd_nextcheck(&item, now, 0, NULL); + } + + free_result(&value); + } (*items)++; } @@ -145,21 +173,31 @@ static void process_value(char *key, ZBX_FPING_HOST *host, zbx_uint64_t *value_u ******************************************************************************/ static int process_values(ZBX_FPING_HOST *hosts, int hosts_count, int now) { - int i, items = 0; + int i, items = 0, ping_result; + char error[ITEM_ERROR_LEN_MAX]; zabbix_log(LOG_LEVEL_DEBUG, "In process_values()"); + zbx_setproctitle("pinger [pinging hosts]"); + + ping_result = do_ping(hosts, hosts_count, error, sizeof(error)); + if (0 != CONFIG_DBSYNCER_FORKS) DCinit_nextchecks(); for (i = 0; i < hosts_count; i++) { - zabbix_log(LOG_LEVEL_DEBUG, "Host [%s] alive [" ZBX_FS_UI64 "] " ZBX_FS_DBL " sec.", - hosts[i].addr, - hosts[i].alive, - hosts[i].sec); + if (ping_result == NOTSUPPORTED) + zabbix_log(LOG_LEVEL_DEBUG, "Host [%s] %s", + hosts[i].addr, + error); + else + zabbix_log(LOG_LEVEL_DEBUG, "Host [%s] alive [" ZBX_FS_UI64 "] " ZBX_FS_DBL " sec.", + hosts[i].addr, + hosts[i].alive, + hosts[i].sec); - process_value(SERVER_ICMPPING_KEY, &hosts[i], &hosts[i].alive, NULL, now, &items); - process_value(SERVER_ICMPPINGSEC_KEY, &hosts[i], NULL, &hosts[i].sec, now, &items); + process_value(SERVER_ICMPPING_KEY, &hosts[i], &hosts[i].alive, NULL, now, &items, ping_result, error); + process_value(SERVER_ICMPPINGSEC_KEY, &hosts[i], NULL, &hosts[i].sec, now, &items, ping_result, error); } if (0 != CONFIG_DBSYNCER_FORKS) @@ -184,78 +222,82 @@ static int process_values(ZBX_FPING_HOST *hosts, int hosts_count, int now) * Comments: * * * ******************************************************************************/ -static int get_pinger_hosts(ZBX_FPING_HOST **hosts, int *hosts_allocated, int now) +static int get_pinger_hosts(int now) { DB_RESULT result; DB_ROW row; - ZBX_FPING_HOST *host; int hosts_count = 0; + char istatus[16]; zabbix_log(LOG_LEVEL_DEBUG, "In get_pinger_hosts()"); + if (0 != CONFIG_REFRESH_UNSUPPORTED) + zbx_snprintf(istatus, sizeof(istatus), "%d,%d", + ITEM_STATUS_ACTIVE, + ITEM_STATUS_NOTSUPPORTED); + else + zbx_snprintf(istatus, sizeof(istatus), "%d", + ITEM_STATUS_ACTIVE); + /* Select hosts monitored by IP */ result = DBselect("select distinct h.ip from hosts h,items i where " ZBX_SQL_MOD(h.hostid,%d) "=%d" " and i.hostid=h.hostid and h.proxy_hostid=0 and h.status=%d and i.key_ in ('%s','%s')" - " and i.type=%d and i.status=%d and h.useip=1 and i.nextcheck<=%d" DB_NODE, + " and i.type=%d and i.status in (%s) and h.useip=1 and i.nextcheck<=%d" DB_NODE, CONFIG_PINGER_FORKS, pinger_num - 1, HOST_STATUS_MONITORED, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, - ITEM_STATUS_ACTIVE, + istatus, now, DBnode_local("h.hostid")); while (NULL != (row = DBfetch(result))) { - if (hosts_count == *hosts_allocated) { - *hosts_allocated *= 2; - *hosts = zbx_realloc(*hosts, *hosts_allocated * sizeof(ZBX_FPING_HOST)); + if (hosts_count == hosts_allocated) { + hosts_allocated *= 2; + hosts = zbx_realloc(hosts, hosts_allocated * sizeof(ZBX_FPING_HOST)); } - host = &(*hosts)[hosts_count]; + memset(&hosts[hosts_count], '\0', sizeof(ZBX_FPING_HOST)); + strscpy(hosts[hosts_count].addr, row[0]); + hosts[hosts_count].useip = 1; - memset(host, '\0', sizeof(ZBX_FPING_HOST)); - strscpy(host->addr, row[0]); - host->useip = 1; + zabbix_log(LOG_LEVEL_DEBUG, "IP [%s]", hosts[hosts_count].addr); hosts_count++; - - zabbix_log(LOG_LEVEL_DEBUG, "IP [%s]", host->addr); } DBfree_result(result); /* Select hosts monitored by hostname */ result = DBselect("select distinct h.dns from hosts h,items i where " ZBX_SQL_MOD(h.hostid,%d) "=%d" " and i.hostid=h.hostid and h.proxy_hostid=0 and h.status=%d and i.key_ in ('%s','%s')" - " and i.type=%d and i.status=%d and h.useip=0 and i.nextcheck<=%d" DB_NODE, + " and i.type=%d and i.status in (%s) and h.useip=0 and i.nextcheck<=%d" DB_NODE, CONFIG_PINGER_FORKS, pinger_num - 1, HOST_STATUS_MONITORED, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, - ITEM_STATUS_ACTIVE, + istatus, now, DBnode_local("h.hostid")); while (NULL != (row = DBfetch(result))) { - if (hosts_count == *hosts_allocated) { - *hosts_allocated *= 2; - *hosts = zbx_realloc(*hosts, *hosts_allocated * sizeof(ZBX_FPING_HOST)); + if (hosts_count == hosts_allocated) { + hosts_allocated *= 2; + hosts = zbx_realloc(hosts, hosts_allocated * sizeof(ZBX_FPING_HOST)); } - host = &(*hosts)[hosts_count]; + memset(&hosts[hosts_count], '\0', sizeof(ZBX_FPING_HOST)); + strscpy(hosts[hosts_count].addr, row[0]); + hosts[hosts_count].useip = 0; - memset(host, '\0', sizeof(ZBX_FPING_HOST)); - strscpy(host->addr, row[0]); - host->useip = 0; + zabbix_log(LOG_LEVEL_DEBUG, "DNS name [%s]", hosts[hosts_count].addr); hosts_count++; - - zabbix_log(LOG_LEVEL_DEBUG, "DNS name [%s]", host->addr); } DBfree_result(result); - zabbix_log(LOG_LEVEL_DEBUG, "End of get_pinger_hosts()"); + zabbix_log(LOG_LEVEL_DEBUG, "End of get_pinger_hosts():%d", hosts_count); return hosts_count; } @@ -280,18 +322,27 @@ static int get_minnextcheck() DB_RESULT result; DB_ROW row; int res; + char istatus[16]; zabbix_log(LOG_LEVEL_DEBUG, "In get_minnextcheck()"); + if (0 != CONFIG_REFRESH_UNSUPPORTED) + zbx_snprintf(istatus, sizeof(istatus), "%d,%d", + ITEM_STATUS_ACTIVE, + ITEM_STATUS_NOTSUPPORTED); + else + zbx_snprintf(istatus, sizeof(istatus), "%d", + ITEM_STATUS_ACTIVE); + result = DBselect("select count(*),min(i.nextcheck) from items i,hosts h where " ZBX_SQL_MOD(h.hostid,%d) "=%d" " and h.status=%d and h.hostid=i.hostid and h.proxy_hostid=0 and i.key_ in ('%s','%s')" - " and i.type=%d and i.status=%d" DB_NODE, + " and i.type=%d and i.status in (%s)" DB_NODE, CONFIG_PINGER_FORKS, pinger_num - 1, HOST_STATUS_MONITORED, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, - ITEM_STATUS_ACTIVE, + istatus, DBnode_local("h.hostid")); if (NULL == (row = DBfetch(result)) || DBis_null(row[0]) == SUCCEED || DBis_null(row[1]) == SUCCEED) @@ -333,8 +384,7 @@ static int get_minnextcheck() void main_pinger_loop(zbx_process_t p, int num) { int now, nextcheck, sleeptime; - ZBX_FPING_HOST *hosts = NULL; - int hosts_allocated = 8, hosts_count, items; + int hosts_count, items; double sec; zabbix_log(LOG_LEVEL_DEBUG, "In main_pinger_loop(num:%d)", @@ -348,18 +398,15 @@ void main_pinger_loop(zbx_process_t p, int num) zbx_setproctitle("pinger [connecting to the database]"); DBconnect(ZBX_DB_CONNECT_NORMAL); - - for (;;) { + + for (;;) + { now = time(NULL); sec = zbx_time(); items = 0; - if (0 < (hosts_count = get_pinger_hosts(&hosts, &hosts_allocated, now))) { - zbx_setproctitle("pinger [pinging hosts]"); - - if (SUCCEED == do_ping(hosts, hosts_count)) - items = process_values(hosts, hosts_count, now); - } + if (0 < (hosts_count = get_pinger_hosts(now))) + items = process_values(hosts, hosts_count, now); sec = zbx_time() - sec; @@ -367,7 +414,8 @@ void main_pinger_loop(zbx_process_t p, int num) if (FAIL == nextcheck) sleeptime = CONFIG_PINGER_FREQUENCY; - else { + else + { sleeptime = nextcheck - time(NULL); if (sleeptime < 0) sleeptime = 0; diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index c7dbf141..ecdb0f69 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -147,6 +147,7 @@ int CONFIG_UNAVAILABLE_DELAY = 60; int CONFIG_LOG_LEVEL = LOG_LEVEL_WARNING; char *CONFIG_ALERT_SCRIPTS_PATH = NULL; char *CONFIG_EXTERNALSCRIPTS = NULL; +char *CONFIG_TMPDIR = NULL; char *CONFIG_FPING_LOCATION = NULL; #ifdef HAVE_IPV6 char *CONFIG_FPING6_LOCATION = NULL; @@ -206,6 +207,7 @@ void init_config(void) {"HousekeepingFrequency",&CONFIG_HOUSEKEEPING_FREQUENCY,0,TYPE_INT,PARM_OPT,1,24}, {"SenderFrequency",&CONFIG_SENDER_FREQUENCY,0,TYPE_INT,PARM_OPT,5,3600}, {"PingerFrequency",&CONFIG_PINGER_FREQUENCY,0,TYPE_INT,PARM_OPT,1,3600}, + {"TmpDir",&CONFIG_TMPDIR,0,TYPE_STRING,PARM_OPT,0,0}, {"FpingLocation",&CONFIG_FPING_LOCATION,0,TYPE_STRING,PARM_OPT,0,0}, #ifdef HAVE_IPV6 {"Fping6Location",&CONFIG_FPING6_LOCATION,0,TYPE_STRING,PARM_OPT,0,0}, @@ -257,6 +259,10 @@ void init_config(void) { CONFIG_ALERT_SCRIPTS_PATH=strdup("/home/zabbix/bin"); } + if(CONFIG_TMPDIR == NULL) + { + CONFIG_TMPDIR=strdup("/tmp"); + } if(CONFIG_FPING_LOCATION == NULL) { CONFIG_FPING_LOCATION=strdup("/usr/sbin/fping"); |
