summaryrefslogtreecommitdiffstats
path: root/src/zabbix_server/server.c
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-06-12 19:33:21 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-06-12 19:33:21 +0000
commit06e27fe2d16497bb5021d9ed61b15a2d67b5d75e (patch)
treef23ff42ba3f7c373f719cc39bc8f200239a18fbc /src/zabbix_server/server.c
parent1a3f892331761a35caf1671092d95280bb26ca58 (diff)
downloadzabbix-06e27fe2d16497bb5021d9ed61b15a2d67b5d75e.tar.gz
zabbix-06e27fe2d16497bb5021d9ed61b15a2d67b5d75e.tar.xz
zabbix-06e27fe2d16497bb5021d9ed61b15a2d67b5d75e.zip
Minor changes.
git-svn-id: svn://svn.zabbix.com/trunk@1879 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_server/server.c')
-rw-r--r--src/zabbix_server/server.c290
1 files changed, 6 insertions, 284 deletions
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index 0ce0c267..ee3bd635 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -36,6 +36,10 @@
/* getopt() */
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
#include "cfg.h"
#include "pid.h"
#include "db.h"
@@ -49,17 +53,13 @@
#include "alerter/alerter.h"
#include "escalator/escalator.h"
#include "pinger/pinger.h"
+#include "poller/poller.h"
#include "housekeeper/housekeeper.h"
#include "trapper/trapper.h"
-#include "checks_agent.h"
-#include "checks_internal.h"
-#include "checks_simple.h"
-#include "checks_snmp.h"
-
#define LISTENQ 1024
-static pid_t *pids=NULL;
+pid_t *pids=NULL;
static int server_num=0;
@@ -275,119 +275,6 @@ void init_config(void)
}
}
-int get_value(double *result,char *result_str,DB_ITEM *item, char *error, int max_error_len)
-{
- int res=FAIL;
-
- struct sigaction phan;
-
- phan.sa_handler = &signal_handler;
- sigemptyset(&phan.sa_mask);
- phan.sa_flags = 0;
- sigaction(SIGALRM, &phan, NULL);
-
- alarm(CONFIG_TIMEOUT);
-
- if(item->type == ITEM_TYPE_ZABBIX)
- {
- res=get_value_agent(result,result_str,item,error,max_error_len);
- }
- else if( (item->type == ITEM_TYPE_SNMPv1) || (item->type == ITEM_TYPE_SNMPv2c))
- {
-#ifdef HAVE_SNMP
- res=get_value_snmp(result,result_str,item,error, max_error_len);
-#else
- zabbix_log(LOG_LEVEL_WARNING, "Support of SNMP parameters was no compiled in");
- zabbix_syslog("Support of SNMP parameters was no compiled in. Cannot process [%s:%s]", item->host, item->key);
- res=NOTSUPPORTED;
-#endif
- }
- else if(item->type == ITEM_TYPE_SIMPLE)
- {
- res=get_value_simple(result,result_str,item,error,max_error_len);
- }
- else if(item->type == ITEM_TYPE_INTERNAL)
- {
- res=get_value_internal(result,result_str,item,error,max_error_len);
- }
- else
- {
- zabbix_log(LOG_LEVEL_WARNING, "Not supported item type:%d",item->type);
- zabbix_syslog("Not supported item type:%d",item->type);
- res=NOTSUPPORTED;
- }
- alarm(0);
- /* Delete EOL characters from result string */
- delete_reol(result_str);
- return res;
-}
-
-int get_minnextcheck(int now)
-{
- char sql[MAX_STRING_LEN];
-
- DB_RESULT *result;
-
- int res;
-
-/* 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);
- result = DBselect(sql);
-
- if( DBnum_rows(result) == 0)
- {
- zabbix_log(LOG_LEVEL_DEBUG, "No items to update for minnextcheck.");
- res = FAIL;
- }
- else
- {
- if( atoi(DBget_field(result,0,0)) == 0)
- {
- res = FAIL;
- }
- else
- {
- res = atoi(DBget_field(result,0,1));
- }
- }
- DBfree_result(result);
-
- return res;
-}
-
-/* Update special host's item - "status" */
-void update_key_status(int hostid,int host_status)
-{
- char sql[MAX_STRING_LEN];
- char value_str[MAX_STRING_LEN];
-
- DB_ITEM item;
- DB_RESULT *result;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In update_key_status()");
-
- 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 h.hostid=i.hostid and h.hostid=%d and i.key_='%s'", hostid,SERVER_STATUS_KEY);
- result = DBselect(sql);
-
- if( DBnum_rows(result) == 0)
- {
- zabbix_log( LOG_LEVEL_DEBUG, "No items to update.");
- }
- else
- {
- DBget_item_from_db(&item,result,0);
-
- snprintf(value_str,sizeof(value_str)-1,"%d",host_status);
-
- process_new_value(&item,value_str);
- update_triggers(item.itemid);
- }
-
- DBfree_result(result);
-}
-
void trend(void)
{
char sql[MAX_STRING_LEN];
@@ -413,118 +300,6 @@ void trend(void)
DBfree_result(result2);
}
-int get_values(void)
-{
- double value;
- char value_str[MAX_STRING_LEN];
- char sql[MAX_STRING_LEN];
-
- char error[MAX_STRING_LEN];
-
- DB_RESULT *result;
-
- int i;
- int now;
- int res;
- DB_ITEM item;
-
- error[0]=0;
-
- 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);
- result = DBselect(sql);
-
- for(i=0;i<DBnum_rows(result);i++)
- {
- DBget_item_from_db(&item,result, i);
-
- res = get_value(&value,value_str,&item,error,sizeof(error));
- zabbix_log( LOG_LEVEL_DEBUG, "GOT VALUE [%s]", value_str );
-
- if(res == SUCCEED )
- {
- process_new_value(&item,value_str);
-
- if(item.host_network_errors>0)
- {
- snprintf(sql,sizeof(sql)-1,"update hosts set network_errors=0,error='' where hostid=%d and network_errors>0", item.hostid);
- DBexecute(sql);
- }
-
-/* 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,error);
- update_key_status(item.hostid,HOST_STATUS_MONITORED);
-
-/* Why this break??? Trigger needs to be updated anyway!
- break;*/
- }
- update_triggers(item.itemid);
- }
- 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, error);
-/* 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,error);
- update_key_status(item.hostid,HOST_STATUS_MONITORED);
-
- break;
- }
- }
- else if(res == NETWORK_ERROR)
- {
- item.host_network_errors++;
- if(item.host_network_errors>=3)
- {
- zabbix_log( LOG_LEVEL_WARNING, "Host [%s] will be checked after [%d] seconds", item.host, DELAY_ON_NETWORK_FAILURE );
- zabbix_syslog("Host [%s] will be checked after [%d] seconds", item.host, DELAY_ON_NETWORK_FAILURE );
- DBupdate_host_availability(item.hostid,HOST_AVAILABLE_FALSE,now,error);
- update_key_status(item.hostid,HOST_AVAILABLE_FALSE);
-
- snprintf(sql,sizeof(sql)-1,"update hosts set network_errors=3 where hostid=%d", item.hostid);
- DBexecute(sql);
- }
- else
- {
- snprintf(sql,sizeof(sql)-1,"update hosts set network_errors=%d where hostid=%d", item.host_network_errors, item.hostid);
- DBexecute(sql);
- }
-
- break;
- }
-/* Possibly, other logic required? */
- else if(res == AGENT_ERROR)
- {
- zabbix_log( LOG_LEVEL_WARNING, "Getting value of [%s] from host [%s] failed (ZBX_ERROR)", item.key, item.host );
- zabbix_syslog("Getting value of [%s] from host [%s] failed (ZBX_ERROR)", item.key, item.host );
- zabbix_log( LOG_LEVEL_WARNING, "The value is not stored in database.");
-
- break;
- }
- else
- {
- zabbix_log( LOG_LEVEL_WARNING, "Getting value of [%s] from host [%s] failed", item.key, item.host );
- zabbix_syslog("Getting value of [%s] from host [%s] failed", item.key, item.host );
- zabbix_log( LOG_LEVEL_WARNING, "The value is not stored in database.");
- }
- }
-
- DBfree_result(result);
- return SUCCEED;
-}
-
int main_nodata_loop()
{
char sql[MAX_STRING_LEN];
@@ -574,59 +349,6 @@ int main_nodata_loop()
}
}
-int main_poller_loop()
-{
- int now;
- int nextcheck,sleeptime;
-
- DBconnect();
-
- for(;;)
- {
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("poller [getting values]");
-#endif
- now=time(NULL);
- get_values();
-
- zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds while updating values", (int)time(NULL)-now );
-
- nextcheck=get_minnextcheck(now);
- zabbix_log( LOG_LEVEL_DEBUG, "Nextcheck:%d Time:%d", nextcheck, (int)time(NULL) );
-
- if( FAIL == nextcheck)
- {
- sleeptime=SUCKER_DELAY;
- }
- else
- {
- sleeptime=nextcheck-time(NULL);
- if(sleeptime<0)
- {
- sleeptime=0;
- }
- }
- if(sleeptime>0)
- {
- if(sleeptime > SUCKER_DELAY)
- {
- sleeptime = SUCKER_DELAY;
- }
- zabbix_log( LOG_LEVEL_DEBUG, "Sleeping for %d seconds",
- sleeptime );
-#ifdef HAVE_FUNCTION_SETPROCTITLE
- setproctitle("poller [sleeping for %d seconds]",
- sleeptime);
-#endif
- sleep( sleeptime );
- }
- else
- {
- zabbix_log( LOG_LEVEL_DEBUG, "No sleeping" );
- }
- }
-}
-
int tcp_listen(const char *host, int port, socklen_t *addrlenp)
{
int sockfd;