summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2003-06-14 16:22:45 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2003-06-14 16:22:45 +0000
commitb1cf4f71fb1e55fe840887e09aac2317e0c3ea9e (patch)
tree1668a232aa21054718d335d7c502ce1e3474a8a6
parent8c3d33e23b104dd6ecf0c5ab08f01cfc1a7b9d52 (diff)
downloadzabbix-b1cf4f71fb1e55fe840887e09aac2317e0c3ea9e.tar.gz
zabbix-b1cf4f71fb1e55fe840887e09aac2317e0c3ea9e.tar.xz
zabbix-b1cf4f71fb1e55fe840887e09aac2317e0c3ea9e.zip
Improvements for pinger.
git-svn-id: svn://svn.zabbix.com/trunk@829 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--include/db.h3
-rw-r--r--misc/conf/zabbix_suckerd.conf6
-rw-r--r--src/zabbix_sucker/Makefile.in2
-rw-r--r--src/zabbix_sucker/alerter.c2
-rw-r--r--src/zabbix_sucker/alerter.h2
-rw-r--r--src/zabbix_sucker/pinger.c17
-rw-r--r--src/zabbix_sucker/pinger.h4
-rw-r--r--src/zabbix_sucker/zabbix_sucker.c24
8 files changed, 34 insertions, 26 deletions
diff --git a/include/db.h b/include/db.h
index 7bade2c3..04da7b75 100644
--- a/include/db.h
+++ b/include/db.h
@@ -34,6 +34,7 @@
#include "libpq-fe.h"
#endif
+#define DB_HOST struct host_type
#define DB_ITEM struct item_type
#define DB_TRIGGER struct trigger_type
#define DB_ACTION struct action_type
@@ -52,7 +53,7 @@
#define DBfree_result PQclear
#endif
-DB_ITEM
+DB_HOST
{
int hostid;
char *host;
diff --git a/misc/conf/zabbix_suckerd.conf b/misc/conf/zabbix_suckerd.conf
index 8e6c658a..62c00b50 100644
--- a/misc/conf/zabbix_suckerd.conf
+++ b/misc/conf/zabbix_suckerd.conf
@@ -5,9 +5,9 @@
############ GENERAL PARAMETERS #################
# Number of pre-forked instances of zabbix_suckerd
-# Default value is 4
-# This parameter must be between 4 and 255
-StartSuckers=4
+# Default value is 5
+# This parameter must be between 5 and 255
+StartSuckers=5
# How often Zabbix will perform housekeeping procedure
# (in hours)
diff --git a/src/zabbix_sucker/Makefile.in b/src/zabbix_sucker/Makefile.in
index eb6614e1..d1b36c19 100644
--- a/src/zabbix_sucker/Makefile.in
+++ b/src/zabbix_sucker/Makefile.in
@@ -5,7 +5,7 @@ LIBS = @LIBS@ @MYSQL_LFLAGS@ @PGSQL_LFLAGS@ @SNMP_LFLAGS@
all:
- @CC@ -o ../../bin/zabbix_suckerd @CFLAGS@ -I../../include $(INCLUDE) zabbix_sucker.c ../../include/db.c ../../include/functions.c ../../include/expression.c ../../include/cfg.c ../../include/log.c ../../include/security.c ../zabbix_agent/sysinfo.c alerter.c -Wall $(LIBS)
+ @CC@ -o ../../bin/zabbix_suckerd @CFLAGS@ -I../../include $(INCLUDE) zabbix_sucker.c ../../include/db.c ../../include/functions.c ../../include/expression.c ../../include/cfg.c ../../include/log.c ../../include/security.c ../zabbix_agent/sysinfo.c alerter.c pinger.c -Wall $(LIBS)
clean:
rm -fv *.o
diff --git a/src/zabbix_sucker/alerter.c b/src/zabbix_sucker/alerter.c
index dae3e629..f4af1bf2 100644
--- a/src/zabbix_sucker/alerter.c
+++ b/src/zabbix_sucker/alerter.c
@@ -121,7 +121,7 @@ int send_alert(DB_ALERT *alert,DB_MEDIATYPE *mediatype)
return res;
}
-int alerter_loop()
+int main_alerter_loop()
{
char sql[MAX_STRING_LEN+1];
diff --git a/src/zabbix_sucker/alerter.h b/src/zabbix_sucker/alerter.h
index 6e6e2db3..2b87b600 100644
--- a/src/zabbix_sucker/alerter.h
+++ b/src/zabbix_sucker/alerter.h
@@ -30,6 +30,6 @@ extern char *CONFIG_ALERT_SCRIPTS_PATH;
extern void signal_handler( int sig );
-int alerter_loop();
+int main_alerter_loop();
#endif
diff --git a/src/zabbix_sucker/pinger.c b/src/zabbix_sucker/pinger.c
index 568f4008..12c83d61 100644
--- a/src/zabbix_sucker/pinger.c
+++ b/src/zabbix_sucker/pinger.c
@@ -55,7 +55,7 @@ int create_host_file(void)
{
char sql[MAX_STRING_LEN+1];
FILE *f;
- int now;
+ int i,now;
DB_HOST host;
DB_RESULT *result;
@@ -65,9 +65,8 @@ int create_host_file(void)
if( f == NULL)
{
zabbix_log( LOG_LEVEL_CRIT, "Cannot hosts file [%s] [%s]",
- "/tmp/zabbix_agentd.pinger", strerror(errno));
- uninit();
- exit(-1);
+ "/tmp/zabbix_suckerd.pinger", strerror(errno));
+ return FAIL;
}
now=time(NULL);
@@ -82,19 +81,21 @@ int create_host_file(void)
if(HOST_USE_IP == host.useip)
{
- fprintf(f,"%d",host.ip);
+ fprintf(f,"%s\n",host.ip);
}
else
{
- fprintf(f,"%d",host.host);
+ fprintf(f,"%s\n",host.host);
}
}
DBfree_result(result);
fclose(f);
+
+ return SUCCEED;
}
-int pinger_loop(void)
+int main_pinger_loop(void)
{
for(;;)
{
@@ -103,8 +104,6 @@ int pinger_loop(void)
#endif
DBconnect(CONFIG_DBHOST, CONFIG_DBNAME, CONFIG_DBUSER, CONFIG_DBPASSWORD, CONFIG_DBSOCKET);
- now=time(NULL);
-
create_host_file();
/* do_ping();
diff --git a/src/zabbix_sucker/pinger.h b/src/zabbix_sucker/pinger.h
index a5853d83..8233ff3d 100644
--- a/src/zabbix_sucker/pinger.h
+++ b/src/zabbix_sucker/pinger.h
@@ -20,7 +20,7 @@
#ifndef ZABBIX_PINGER_H
#define ZABBIX_PINGER_H
-extern int CONFIG_SENDER_FREQUENCY;
+extern int CONFIG_PINGER_FREQUENCY;
extern char *CONFIG_DBHOST;
extern char *CONFIG_DBNAME;
extern char *CONFIG_DBUSER;
@@ -30,6 +30,6 @@ extern char *CONFIG_ALERT_SCRIPTS_PATH;
extern void signal_handler( int sig );
-int pinger_loop();
+int main_pinger_loop();
#endif
diff --git a/src/zabbix_sucker/zabbix_sucker.c b/src/zabbix_sucker/zabbix_sucker.c
index a5a5fc09..adade1a7 100644
--- a/src/zabbix_sucker/zabbix_sucker.c
+++ b/src/zabbix_sucker/zabbix_sucker.c
@@ -62,6 +62,7 @@
#include "log.h"
#include "alerter.h"
+#include "pinger.h"
#include "../zabbix_agent/sysinfo.h"
@@ -74,6 +75,7 @@ int CONFIG_NOTIMEWAIT =0;
int CONFIG_TIMEOUT =SUCKER_TIMEOUT;
int CONFIG_HOUSEKEEPING_FREQUENCY = 1;
int CONFIG_SENDER_FREQUENCY = 30;
+int CONFIG_PINGER_FREQUENCY = 60;
int CONFIG_DISABLE_HOUSEKEEPING = 0;
int CONFIG_LOG_LEVEL = LOG_LEVEL_WARNING;
char *CONFIG_PID_FILE = NULL;
@@ -233,9 +235,10 @@ void init_config(void)
static struct cfg_line cfg[]=
{
/* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX */
- {"StartSuckers",&CONFIG_SUCKERD_FORKS,0,TYPE_INT,PARM_OPT,4,255},
+ {"StartSuckers",&CONFIG_SUCKERD_FORKS,0,TYPE_INT,PARM_OPT,5,255},
{"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,10,3600},
{"Timeout",&CONFIG_TIMEOUT,0,TYPE_INT,PARM_OPT,1,30},
{"NoTimeWait",&CONFIG_NOTIMEWAIT,0,TYPE_INT,PARM_OPT,0,1},
{"DisableHousekeeping",&CONFIG_DISABLE_HOUSEKEEPING,0,TYPE_INT,PARM_OPT,0,1},
@@ -679,9 +682,9 @@ int get_minnextcheck(int now)
1 == NOT MONITORED
2 == UNREACHABLE */
#ifdef TESTTEST
- sprintf(sql,"select count(*),min(nextcheck) from items i,hosts h where (h.status=0 or (h.status=2 and h.disable_until<%d)) and h.hostid=i.hostid and i.status=0 and i.type not in (%d) and h.hostid%%%d=%d and i.key_<>'%s'", now, ITEM_TYPE_TRAPPER, CONFIG_SUCKERD_FORKS-3,sucker_num-3,SERVER_STATUS_KEY);
+ sprintf(sql,"select count(*),min(nextcheck) from items i,hosts h where (h.status=0 or (h.status=2 and h.disable_until<%d)) and h.hostid=i.hostid and i.status=0 and i.type not in (%d) and h.hostid%%%d=%d and i.key_<>'%s'", now, ITEM_TYPE_TRAPPER, CONFIG_SUCKERD_FORKS-4,sucker_num-4,SERVER_STATUS_KEY);
#else
- sprintf(sql,"select count(*),min(nextcheck) from items i,hosts h where (h.status=0 or (h.status=2 and h.disable_until<%d)) and h.hostid=i.hostid and i.status=%d and i.type not in (%d) and i.itemid%%%d=%d and i.key_<>'%s'", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, CONFIG_SUCKERD_FORKS-3,sucker_num-3,SERVER_STATUS_KEY);
+ sprintf(sql,"select count(*),min(nextcheck) from items i,hosts h where (h.status=0 or (h.status=2 and h.disable_until<%d)) and h.hostid=i.hostid and i.status=%d and i.type not in (%d) and i.itemid%%%d=%d and i.key_<>'%s'", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, CONFIG_SUCKERD_FORKS-4,sucker_num-4,SERVER_STATUS_KEY);
#endif
result = DBselect(sql);
@@ -792,9 +795,9 @@ int get_values(void)
now = time(NULL);
#ifdef TESTTEST
- sprintf(sql,"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,i.snmp_port from items i,hosts h where i.nextcheck<=%d and i.status=0 and (h.status=0 or (h.status=2 and h.disable_until<=%d)) and h.hostid=i.hostid and h.hostid%%%d=%d and i.key_<>'%s' order by i.nextcheck", now, now, CONFIG_SUCKERD_FORKS-3,sucker_num-3,SERVER_STATUS_KEY);
+ sprintf(sql,"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,i.snmp_port from items i,hosts h where i.nextcheck<=%d and i.status=0 and (h.status=0 or (h.status=2 and h.disable_until<=%d)) and h.hostid=i.hostid and h.hostid%%%d=%d and i.key_<>'%s' order by i.nextcheck", now, now, CONFIG_SUCKERD_FORKS-4,sucker_num-4,SERVER_STATUS_KEY);
#else
- sprintf(sql,"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 from items i,hosts h where i.nextcheck<=%d and i.status=%d and i.type not in (%d) and (h.status=0 or (h.status=2 and h.disable_until<=%d)) and h.hostid=i.hostid and i.itemid%%%d=%d and i.key_<>'%s' order by i.nextcheck", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, now, CONFIG_SUCKERD_FORKS-3,sucker_num-3,SERVER_STATUS_KEY);
+ sprintf(sql,"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 from items i,hosts h where i.nextcheck<=%d and i.status=%d and i.type not in (%d) and (h.status=0 or (h.status=2 and h.disable_until<=%d)) and h.hostid=i.hostid and i.itemid%%%d=%d and i.key_<>'%s' order by i.nextcheck", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, now, CONFIG_SUCKERD_FORKS-4,sucker_num-4,SERVER_STATUS_KEY);
#endif
result = DBselect(sql);
@@ -1253,13 +1256,18 @@ int main(int argc, char **argv)
else if(sucker_num == 1)
{
/* Second instance of zabbix_suckerd sends alerts to users */
- alerter_loop();
- }
+ main_alerter_loop();
+ }
else if(sucker_num == 2)
{
/* Third instance of zabbix_suckerd periodically re-calculates 'nodata' functions */
main_nodata_loop();
- }
+ }
+ else if(sucker_num == 3)
+ {
+/* Fourth instance of zabbix_suckerd periodically pings hosts */
+ main_pinger_loop();
+ }
else
{
main_sucker_loop();