summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-12-04 11:10:23 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-12-04 11:10:23 +0000
commitb8677042875ced11a84258e57642fa75e85a022c (patch)
tree120f7b0f197cac72079aae1f5a6b8db674ec3047 /src
parent560c32cc84776bc518a625dbc92acd08920e3fc1 (diff)
downloadzabbix-b8677042875ced11a84258e57642fa75e85a022c.tar.gz
zabbix-b8677042875ced11a84258e57642fa75e85a022c.tar.xz
zabbix-b8677042875ced11a84258e57642fa75e85a022c.zip
- automatic recovery of unsupported items (Alexei)
- added config.refresh_unsupported (Alexei) git-svn-id: svn://svn.zabbix.com/trunk@2386 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r--src/libs/zbxcommon/misc.c28
-rw-r--r--src/zabbix_server/functions.c38
-rw-r--r--src/zabbix_server/poller/poller.c53
-rw-r--r--src/zabbix_server/poller/poller.h1
-rw-r--r--src/zabbix_server/server.c19
5 files changed, 95 insertions, 44 deletions
diff --git a/src/libs/zbxcommon/misc.c b/src/libs/zbxcommon/misc.c
index 3ec62b47..f73de3a2 100644
--- a/src/libs/zbxcommon/misc.c
+++ b/src/libs/zbxcommon/misc.c
@@ -4,6 +4,34 @@
/******************************************************************************
* *
+ * Function: calculate_item_nextcheck *
+ * *
+ * Purpose: calculate nextcheck timespamp for item *
+ * *
+ * Parameters: delay - item's refresh rate in sec *
+ * now - current timestamp *
+ * *
+ * Return value: nextcheck value *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: Old algorithm: now+delay *
+ * New one: preserve period, if delay==5, nextcheck = 0,5,10,15,... *
+ * *
+ ******************************************************************************/
+int calculate_item_nextcheck(int delay, int now)
+{
+ int i;
+
+ i=delay*(int)(now/delay);
+
+ while(i<=now) i+=delay;
+
+ return i;
+}
+
+/******************************************************************************
+ * *
* Function: cmp_double *
* *
* Purpose: compares two float values *
diff --git a/src/zabbix_server/functions.c b/src/zabbix_server/functions.c
index feb83ccc..776e0380 100644
--- a/src/zabbix_server/functions.c
+++ b/src/zabbix_server/functions.c
@@ -54,34 +54,6 @@ extern int autoregister(char *server);
/******************************************************************************
* *
- * Function: calculate_item_nextcheck *
- * *
- * Purpose: calculate nextcheck timespamp for item *
- * *
- * Parameters: delay - item's refresh rate in sec *
- * now - current timestamp *
- * *
- * Return value: nextcheck value *
- * *
- * Author: Alexei Vladishev *
- * *
- * Comments: Old algorithm: now+delay *
- * New one: preserve period, if delay==5, nextcheck = 0,5,10,15,... *
- * *
- ******************************************************************************/
-int calculate_item_nextcheck(int delay, int now)
-{
- int i;
-
- i=delay*(int)(now/delay);
-
- while(i<=now) i+=delay;
-
- return i;
-}
-
-/******************************************************************************
- * *
* Function: update_functions *
* *
* Purpose: re-calculate and updates values of functions related to the item *
@@ -761,6 +733,16 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now)
}
DBexecute(sql);
+/* 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]", item->key, item->host );
+ zabbix_syslog("Parameter [%s] became supported by agent on host [%s]", item->key, item->host );
+ item->status = ITEM_STATUS_ACTIVE;
+ snprintf(sql,sizeof(sql)-1,"update items set status=%d where itemid=%d", ITEM_STATUS_ACTIVE, item->itemid);
+ DBexecute(sql);
+ }
+
return ret;
}
diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c
index 08a85a51..4ff51fe6 100644
--- a/src/zabbix_server/poller/poller.c
+++ b/src/zabbix_server/poller/poller.c
@@ -110,8 +110,16 @@ static int get_minnextcheck(int now)
/* Host status 0 == MONITORED
1 == NOT MONITORED
- 2 == UNREACHABLE */
- snprintf(sql,sizeof(sql)-1,"select count(*),min(nextcheck) from items i,hosts h where ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<%d)) and h.hostid=i.hostid and i.status=%d and i.type not in (%d,%d) and i.itemid%%%d=%d and i.key_ not in ('%s','%s','%s','%s')", HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE,HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, CONFIG_SUCKERD_FORKS-5,server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ 2 == UNREACHABLE */
+ if(CONFIG_REFRESH_UNSUPPORTED != 0)
+ {
+ snprintf(sql,sizeof(sql)-1,"select count(*),min(nextcheck) from items i,hosts h where ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<%d)) and h.hostid=i.hostid and i.status in (%d,%d) and i.type not in (%d,%d) and i.itemid%%%d=%d and i.key_ not in ('%s','%s','%s','%s')", HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE,HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, CONFIG_SUCKERD_FORKS-5,server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ }
+ else
+ {
+ snprintf(sql,sizeof(sql)-1,"select count(*),min(nextcheck) from items i,hosts h where ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<%d)) and h.hostid=i.hostid and i.status in (%d) and i.type not in (%d,%d) and i.itemid%%%d=%d and i.key_ not in ('%s','%s','%s','%s')", HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE,HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, CONFIG_SUCKERD_FORKS-5,server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ }
+
result = DBselect(sql);
if( DBnum_rows(result) == 0)
@@ -202,7 +210,14 @@ int get_values(void)
now = time(NULL);
- snprintf(sql,sizeof(sql)-1,"select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.hostid,h.status,i.value_type,h.network_errors,i.snmp_port,i.delta,i.prevorgvalue,i.lastclock,i.units,i.multiplier,i.snmpv3_securityname,i.snmpv3_securitylevel,i.snmpv3_authpassphrase,i.snmpv3_privpassphrase,i.formula,h.available from items i,hosts h where i.nextcheck<=%d and i.status=%d and i.type not in (%d,%d) and ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<=%d)) and h.hostid=i.hostid and i.itemid%%%d=%d and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, CONFIG_SUCKERD_FORKS-5,server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ if(CONFIG_REFRESH_UNSUPPORTED != 0)
+ {
+ snprintf(sql,sizeof(sql)-1,"select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.hostid,h.status,i.value_type,h.network_errors,i.snmp_port,i.delta,i.prevorgvalue,i.lastclock,i.units,i.multiplier,i.snmpv3_securityname,i.snmpv3_securitylevel,i.snmpv3_authpassphrase,i.snmpv3_privpassphrase,i.formula,h.available from items i,hosts h where i.nextcheck<=%d and i.status in (%d,%d) and i.type not in (%d,%d) and ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<=%d)) and h.hostid=i.hostid and i.itemid%%%d=%d and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", now, ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, CONFIG_SUCKERD_FORKS-5,server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ }
+ else
+ {
+ snprintf(sql,sizeof(sql)-1,"select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.hostid,h.status,i.value_type,h.network_errors,i.snmp_port,i.delta,i.prevorgvalue,i.lastclock,i.units,i.multiplier,i.snmpv3_securityname,i.snmpv3_securitylevel,i.snmpv3_authpassphrase,i.snmpv3_privpassphrase,i.formula,h.available from items i,hosts h where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<=%d)) and h.hostid=i.hostid and i.itemid%%%d=%d and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, CONFIG_SUCKERD_FORKS-5,server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ }
result = DBselect(sql);
for(stop=i=0;i<DBnum_rows(result)&&stop==0;i++)
@@ -239,19 +254,27 @@ int get_values(void)
}
else if(res == NOTSUPPORTED)
{
- zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] is not supported by agent on host [%s]", item.key, item.host );
- zabbix_syslog("Parameter [%s] is not supported by agent on host [%s]", item.key, item.host );
- DBupdate_item_status_to_notsupported(item.itemid, agent.str);
-/* if(HOST_STATUS_UNREACHABLE == item.host_status)*/
- if(HOST_AVAILABLE_TRUE != item.host_available)
+ if(item.status == ITEM_STATUS_NOTSUPPORTED)
{
- item.host_available=HOST_AVAILABLE_TRUE;
- zabbix_log( LOG_LEVEL_WARNING, "Enabling host [%s]", item.host );
- zabbix_syslog("Enabling host [%s]", item.host );
- DBupdate_host_availability(item.hostid,HOST_AVAILABLE_TRUE,now,agent.msg);
- update_key_status(item.hostid,HOST_STATUS_MONITORED);
-
- stop=1;
+ snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d, lastclock=%d where itemid=%d",calculate_item_nextcheck(CONFIG_REFRESH_UNSUPPORTED,now), now, item.itemid);
+ DBexecute(sql);
+ }
+ else
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] is not supported by agent on host [%s]", item.key, item.host );
+ zabbix_syslog("Parameter [%s] is not supported by agent on host [%s]", item.key, item.host );
+ DBupdate_item_status_to_notsupported(item.itemid, agent.str);
+ /* if(HOST_STATUS_UNREACHABLE == item.host_status)*/
+ if(HOST_AVAILABLE_TRUE != item.host_available)
+ {
+ item.host_available=HOST_AVAILABLE_TRUE;
+ zabbix_log( LOG_LEVEL_WARNING, "Enabling host [%s]", item.host );
+ zabbix_syslog("Enabling host [%s]", item.host );
+ DBupdate_host_availability(item.hostid,HOST_AVAILABLE_TRUE,now,agent.msg);
+ update_key_status(item.hostid,HOST_STATUS_MONITORED);
+
+ stop=1;
+ }
}
}
else if(res == NETWORK_ERROR)
diff --git a/src/zabbix_server/poller/poller.h b/src/zabbix_server/poller/poller.h
index 5b39602a..9c828bb6 100644
--- a/src/zabbix_server/poller/poller.h
+++ b/src/zabbix_server/poller/poller.h
@@ -25,6 +25,7 @@ extern int server_num;
extern int CONFIG_TIMEOUT;
extern int CONFIG_SUCKERD_FORKS;
+extern int CONFIG_REFRESH_UNSUPPORTED;
void main_poller_loop();
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index 1885effb..41128924 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -92,6 +92,9 @@ char *CONFIG_DBPASSWORD = NULL;
char *CONFIG_DBSOCKET = NULL;
int CONFIG_DBPORT = 3306;
+/* From table config */
+int CONFIG_REFRESH_UNSUPPORTED = 0;
+
/******************************************************************************
* *
* Function: uninit *
@@ -329,6 +332,9 @@ void init_config(void)
{0}
};
+ char sql[MAX_STRING_LEN];
+ DB_RESULT *result;
+
if(CONFIG_FILE == NULL)
{
CONFIG_FILE=strdup("/etc/zabbix/zabbix_server.conf");
@@ -353,6 +359,16 @@ void init_config(void)
{
CONFIG_FPING_LOCATION=strdup("/usr/sbin/fping");
}
+
+ DBconnect();
+
+ snprintf(sql,sizeof(sql)-1,"select refresh_usupported from config");
+ result = DBselect(sql);
+
+ if(DBnum_rows(result)==1)
+ {
+ CONFIG_REFRESH_UNSUPPORTED = atoi(DBget_field(result,0,0));
+ }
}
void trend(void)
@@ -498,7 +514,8 @@ int main(int argc, char **argv)
zabbix_log( LOG_LEVEL_WARNING, "Starting zabbix_server. ZABBIX %s.", ZABBIX_VERSION);
/* Need to set trigger status to UNKNOWN since last run */
- DBconnect();
+/* DBconnect() already made in init_config() */
+/* DBconnect();*/
DBupdate_triggers_status_after_restart();
/*#define CALC_TREND*/