summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--configure.in13
-rw-r--r--create/schema/schema.sql36
-rw-r--r--include/common.h12
-rw-r--r--include/db.h26
-rw-r--r--src/zabbix_server/Makefile.am2
-rw-r--r--src/zabbix_server/discoverer/Makefile.am5
-rw-r--r--src/zabbix_server/discoverer/discoverer.c423
-rw-r--r--src/zabbix_server/discoverer/discoverer.h28
-rw-r--r--src/zabbix_server/server.c22
-rw-r--r--upgrades/dbpatches/1.3/mysql/patch/dchecks.sql7
-rw-r--r--upgrades/dbpatches/1.3/mysql/patch/dhosts.sql9
-rw-r--r--upgrades/dbpatches/1.3/mysql/patch/drules.sql14
-rw-r--r--upgrades/dbpatches/1.3/mysql/patch/dservices.sql10
-rw-r--r--upgrades/dbpatches/1.3/postgresql/patch/dchecks.sql7
-rw-r--r--upgrades/dbpatches/1.3/postgresql/patch/dhosts.sql9
-rw-r--r--upgrades/dbpatches/1.3/postgresql/patch/drules.sql14
-rw-r--r--upgrades/dbpatches/1.3/postgresql/patch/dservices.sql10
18 files changed, 640 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 277d4c12..22c9609e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
Changes for 1.3.4:
+ - new tables drules,dchecks,dhosts,dservices (Alexei)
+ - basic support of auto-discovery (Alexei)
+ - new Server parameter StartDiscoverers (Alexei)
- fixed "system.cpu.util[]" (Eugene)
- removed housekeeper warnings from front-end (Alexei)
- HTTP poller won't verify SSL certificates to enable self-signed (Alexei)
diff --git a/configure.in b/configure.in
index b91be8c9..504d8606 100644
--- a/configure.in
+++ b/configure.in
@@ -764,16 +764,17 @@ AC_OUTPUT([
src/zabbix_agent/Makefile
src/zabbix_get/Makefile
src/zabbix_sender/Makefile
- src/zabbix_server/pinger/Makefile
- src/zabbix_server/housekeeper/Makefile
- src/zabbix_server/alerter/Makefile
src/zabbix_server/Makefile
- src/zabbix_server/trapper/Makefile
+ src/zabbix_server/alerter/Makefile
+ src/zabbix_server/discoverer/Makefile
+ src/zabbix_server/housekeeper/Makefile
+ src/zabbix_server/httppoller/Makefile
+ src/zabbix_server/nodewatcher/Makefile
+ src/zabbix_server/pinger/Makefile
src/zabbix_server/poller/Makefile
src/zabbix_server/timer/Makefile
- src/zabbix_server/nodewatcher/Makefile
+ src/zabbix_server/trapper/Makefile
src/zabbix_server/utils/Makefile
- src/zabbix_server/httppoller/Makefile
src/zabbix_server/watchdog/Makefile
])
diff --git a/create/schema/schema.sql b/create/schema/schema.sql
index 769ce938..29a62cf4 100644
--- a/create/schema/schema.sql
+++ b/create/schema/schema.sql
@@ -21,6 +21,42 @@
-- Do not use spaces
--
+TABLE|drules|druleid|ZBX_SYNC
+FIELD |druleid |t_id |'0' |NOT NULL |ZBX_SYNC
+FIELD |name |t_varchar(255) |'' |NOT NULL |ZBX_SYNC
+FIELD |ipfirst |t_varchar(15) |'' |NOT NULL |ZBX_SYNC
+FIELD |iplast |t_varchar(15) |'' |NOT NULL |ZBX_SYNC
+FIELD |delay |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |nextcheck |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |status |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |upevent |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |downevent |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |svcupevent |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |svcdownevent |t_integer |'0' |NOT NULL |ZBX_SYNC
+
+TABLE|dchecks|dcheckid|ZBX_SYNC
+FIELD |dcheckid |t_id |'0' |NOT NULL |ZBX_SYNC
+FIELD |druleid |t_id |'0' |NOT NULL |ZBX_SYNC
+FIELD |type |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |ports |t_varchar(255) |'0' |NOT NULL |ZBX_SYNC
+
+TABLE|dhosts|dhostid|ZBX_SYNC
+FIELD |dhostid |t_id |'0' |NOT NULL |ZBX_SYNC
+FIELD |druleid |t_id |'0' |NOT NULL |ZBX_SYNC
+FIELD |ip |t_varchar(15) |'' |NOT NULL |ZBX_SYNC
+FIELD |status |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |lastup |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |lastdown |t_integer |'0' |NOT NULL |ZBX_SYNC
+
+TABLE|dservices|dserviceid|ZBX_SYNC
+FIELD |dserviceid |t_id |'0' |NOT NULL |ZBX_SYNC
+FIELD |dhostid |t_id |'0' |NOT NULL |ZBX_SYNC
+FIELD |type |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |port |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |status |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |lastup |t_integer |'0' |NOT NULL |ZBX_SYNC
+FIELD |lastdown |t_integer |'0' |NOT NULL |ZBX_SYNC
+
TABLE|ids|nodeid,table_name,field_name|
FIELD |nodeid |t_integer |'0' |NOT NULL |0
FIELD |table_name |t_varchar(64) |'' |NOT NULL |0
diff --git a/include/common.h b/include/common.h
index 5aba6814..64a26731 100644
--- a/include/common.h
+++ b/include/common.h
@@ -144,6 +144,12 @@ typedef enum
HTTPTEST_STATE_BUSY
} zbx_httptest_state_type_t;
+/* Service supported by discoverer */
+typedef enum
+{
+ SSH = 0
+} zbx_dservice_type_t;
+
/* Item snmpv3 security levels */
#define ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV 0
@@ -235,8 +241,12 @@ typedef enum
#define HTTPTEST_STATUS_MONITORED 0
#define HTTPTEST_STATUS_NOT_MONITORED 1
+/* DIscovery rule */
+#define DRULE_STATUS_MONITORED 0
+#define DRULE_STATUS_NOT_MONITORED 1
+
/* Host statuses */
-#define HOST_STATUS_MONITORED 0
+#define HOST_STATUS_MONITORED 0
#define HOST_STATUS_NOT_MONITORED 1
/*#define HOST_STATUS_UNREACHABLE 2*/
#define HOST_STATUS_TEMPLATE 3
diff --git a/include/db.h b/include/db.h
index 809464e8..f0055756 100644
--- a/include/db.h
+++ b/include/db.h
@@ -45,6 +45,8 @@ extern int CONFIG_MASTER_NODEID;
#define DB_ACTION struct zbx_action_type
#define DB_ALERT struct zbx_alert_type
#define DB_CONDITION struct zbx_condition_type
+#define DB_DRULE struct zbx_drule_type
+#define DB_DCHECK struct zbx_dcheck_type
#define DB_EVENT struct zbx_event_type
#define DB_FUNCTION struct zbx_function_type
#define DB_GRAPH struct zbx_graph_type
@@ -107,6 +109,30 @@ extern int CONFIG_MASTER_NODEID;
#define ZBX_MAX_SQL_LEN 65535
+DB_DRULE
+{
+ zbx_uint64_t druleid;
+ char *ipfirst;
+ char *iplast;
+ int delay;
+ int nextcheck;
+ char *name;
+ int status;
+ int upevent;
+ int downevent;
+ int svcupevent;
+ int svndownevent;
+};
+
+DB_DCHECK
+{
+ zbx_uint64_t dcheckid;
+ zbx_uint64_t druleid;
+ int type;
+ char *ports;
+ int status;
+};
+
DB_EVENT
{
zbx_uint64_t eventid;
diff --git a/src/zabbix_server/Makefile.am b/src/zabbix_server/Makefile.am
index 0f47d026..03801008 100644
--- a/src/zabbix_server/Makefile.am
+++ b/src/zabbix_server/Makefile.am
@@ -2,6 +2,7 @@
SUBDIRS = \
alerter \
+ discoverer \
housekeeper \
pinger \
poller \
@@ -29,6 +30,7 @@ endif
zabbix_server_LDADD = \
alerter/libzbxalerter.a \
+ discoverer/libzbxdiscoverer.a \
pinger/libzbxpinger.a \
poller/libzbxpoller.a \
housekeeper/libzbxhousekeeper.a \
diff --git a/src/zabbix_server/discoverer/Makefile.am b/src/zabbix_server/discoverer/Makefile.am
new file mode 100644
index 00000000..aae20ad6
--- /dev/null
+++ b/src/zabbix_server/discoverer/Makefile.am
@@ -0,0 +1,5 @@
+## Process this file with automake to produce Makefile.in
+
+noinst_LIBRARIES = libzbxdiscoverer.a
+
+libzbxdiscoverer_a_SOURCES = discoverer.c discoverer.h
diff --git a/src/zabbix_server/discoverer/discoverer.c b/src/zabbix_server/discoverer/discoverer.c
new file mode 100644
index 00000000..0b98ad73
--- /dev/null
+++ b/src/zabbix_server/discoverer/discoverer.c
@@ -0,0 +1,423 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "common.h"
+
+#include "cfg.h"
+#include "pid.h"
+#include "db.h"
+#include "log.h"
+#include "sysinfo.h"
+#include "zlog.h"
+
+#include "daemon.h"
+#include "discoverer.h"
+
+#define SERVICE_UP 0
+#define SERVICE_DOWN 1
+
+int discoverer_num;
+
+/******************************************************************************
+ * *
+ * Function: register_host *
+ * *
+ * Purpose: register host if one does not exist *
+ * *
+ * Parameters: host ip address *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static zbx_uint64_t register_service(DB_DRULE *rule,DB_DCHECK *check,zbx_uint64_t dhostid,char *ip,int port)
+{
+ DB_RESULT result;
+ DB_ROW row;
+ zbx_uint64_t dserviceid = 0;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In register_service(ip:%s,port:%d)",
+ ip,
+ port);
+
+ result = DBselect("select dserviceid from dservices where dhostid=" ZBX_FS_UI64 " and type=%d and port=%d",
+ dhostid,
+ check->type,
+ port);
+ row=DBfetch(result);
+ if(!row || DBis_null(row[0])==SUCCEED)
+ {
+ /* Add host only if service is up */
+ if(check->status == SERVICE_UP)
+ {
+ dserviceid = DBget_maxid("dservices","dserviceid");
+ DBexecute("insert into dservices (dhostid,dserviceid,type,port) values (" ZBX_FS_UI64 "," ZBX_FS_UI64 ",%d,%d)",
+ dhostid,
+ dserviceid,
+ check->type,
+ port);
+ zabbix_log(LOG_LEVEL_WARNING, "New service discovered on port %d", port);
+ }
+ }
+ else
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "Service is already in database");
+ ZBX_STR2UINT64(dserviceid,row[0]);
+ }
+ DBfree_result(result);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End register_service()");
+
+ return dserviceid;
+}
+
+/******************************************************************************
+ * *
+ * Function: register_host *
+ * *
+ * Purpose: register host if one does not exist *
+ * *
+ * Parameters: host ip address *
+ * *
+ * Return value: dhostid or 0 if we didn't add host *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static zbx_uint64_t register_host(DB_DCHECK *check, zbx_uint64_t druleid, char *ip)
+{
+ DB_RESULT result;
+ DB_ROW row;
+ zbx_uint64_t dhostid = 0;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In register_host(ip:%s)",
+ ip);
+
+ result = DBselect("select dhostid from dhosts where ip='%s' and " ZBX_COND_NODEID,
+ ip,
+ LOCAL_NODE("dhostid"));
+ row=DBfetch(result);
+ if(!row || DBis_null(row[0])==SUCCEED)
+ {
+ /* Add host only if service is up */
+ if(check->status == SERVICE_UP)
+ {
+ dhostid = DBget_maxid("dhosts","dhostid");
+ DBexecute("insert into dhosts (dhostid,druleid,ip) values (" ZBX_FS_UI64 "," ZBX_FS_UI64 ",'%s')",
+ dhostid,
+ druleid,
+ ip);
+ zabbix_log(LOG_LEVEL_WARNING, "New host discovered at %s", ip);
+ }
+ }
+ else
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "Host is already in database");
+ ZBX_STR2UINT64(dhostid,row[0]);
+ }
+ DBfree_result(result);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End register_host()");
+
+ return dhostid;
+}
+
+/******************************************************************************
+ * *
+ * Function: update_service *
+ * *
+ * Purpose: process new service status *
+ * *
+ * Parameters: service - service info *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static void update_service(DB_DRULE *rule, DB_DCHECK *check, char *ip, int port)
+{
+ DB_RESULT result;
+ DB_ROW row;
+ zbx_uint64_t dhostid;
+ zbx_uint64_t dserviceid = 0;
+ int now;
+
+ zabbix_log(LOG_LEVEL_WARNING, "In update_check(ip:%s, port:%d, status:%s)",
+ ip, port, (check->status==SERVICE_UP?"up":"down"));
+
+ /* Register host if is not registered yet */
+ dhostid = register_host(check,rule->druleid,ip);
+
+ if(dhostid>0)
+ {
+ /* Register service if is not registered yet */
+ dserviceid = register_service(rule,check,dhostid,ip,port);
+ }
+
+ if(dserviceid == 0)
+ {
+ /* Service wasn't registered because we do not add down service */
+ return;
+ }
+
+ now = time(NULL);
+ if(check->status == SERVICE_UP)
+ {
+ /* Update host status */
+ DBexecute("update dhosts set status=%d, lastup=%d, lastdown=0 where (status=%d or (lastup=0 and lastdown=0)) and dhostid=" ZBX_FS_UI64,
+ SERVICE_UP,
+ now,
+ SERVICE_DOWN,
+ dhostid);
+ /* Update service status */
+ DBexecute("update dservices set status=%d, lastup=%d, lastdown=0 where (status=%d or (lastup=0 and lastdown=0)) and dserviceid=" ZBX_FS_UI64,
+ SERVICE_UP,
+ now,
+ SERVICE_DOWN,
+ dserviceid);
+ }
+ /* SERVICE_DOWN */
+ else
+ {
+ /* Update host status */
+ DBexecute("update dhosts set status=%d, lastup=0, lastdown=%d where (status=%d or (lastup=0 and lastdown=0)) and dhostid=" ZBX_FS_UI64,
+ SERVICE_DOWN,
+ now,
+ SERVICE_UP,
+ dhostid);
+ /* Update service status */
+ DBexecute("update dservices set status=%d, lastup=0, lastdown=%d where (status=%d or (lastup=0 and lastdown=0)) and dserviceid=" ZBX_FS_UI64,
+ SERVICE_DOWN,
+ now,
+ SERVICE_UP,
+ dserviceid);
+ }
+}
+
+/******************************************************************************
+ * *
+ * Function: discover_service *
+ * *
+ * Purpose: check if service is avaiable and update database *
+ * *
+ * Parameters: service typ,e ip address, port number *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int discover_service(zbx_dservice_type_t type, char *ip, int port)
+{
+ int ret = SUCCEED;
+ char key[MAX_STRING_LEN];
+ AGENT_RESULT value;
+ struct sigaction phan;
+
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In discover_service(ip:%s, port:%d, type:%d)",
+ ip, port, type);
+
+ init_result(&value);
+
+ switch(type) {
+ case SSH:
+ zabbix_log(LOG_LEVEL_DEBUG, "Checking SSH");
+ zbx_snprintf(key,sizeof(key)-1,"net.tcp.service[ssh,%s,%d]", ip, port);
+ break;
+ default:
+ ret = FAIL;
+ break;
+ }
+
+ if(ret == SUCCEED)
+ {
+ phan.sa_handler = &child_signal_handler;
+ sigemptyset(&phan.sa_mask);
+ phan.sa_flags = 0;
+ sigaction(SIGALRM, &phan, NULL);
+ alarm(10);
+
+ if(process(key, 0, &value) == SUCCEED)
+ {
+ if(GET_UI64_RESULT(&value))
+ {
+ if(value.ui64 == 0) ret = FAIL;
+ }
+ else ret = FAIL;
+ }
+ else ret = FAIL;
+ alarm(0);
+ }
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End discover_service()");
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Function: process_service *
+ * *
+ * Purpose: check if service is avaiable and update database *
+ * *
+ * Parameters: service - service info *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static void process_check(DB_DRULE *rule, DB_DCHECK *check, char *ip)
+{
+ int port=22;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In process_check(ip:%s, ports:%s, type:%d)",
+ ip, check->ports, check->type);
+
+ check->status = discover_service(check->type,ip,port);
+ update_service(rule, check, ip, port);
+
+ zabbix_log(LOG_LEVEL_DEBUG, "End process_check()");
+}
+
+/******************************************************************************
+ * *
+ * Function: process_rule *
+ * *
+ * Purpose: process single discovery rule *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static void process_rule(DB_DRULE *rule)
+{
+ DB_RESULT result;
+ DB_ROW row;
+ DB_DCHECK check;
+
+ char ip[MAX_STRING_LEN];
+
+ int i;
+
+ zabbix_log( LOG_LEVEL_DEBUG, "In process_rule(name:%s)", rule->name);
+
+ result = DBselect("select dcheckid,druleid,type,ports from dchecks where druleid=" ZBX_FS_UI64,
+ rule->druleid);
+ while((row=DBfetch(result)))
+ {
+ ZBX_STR2UINT64(check.dcheckid,row[0]);
+ ZBX_STR2UINT64(check.druleid,row[1]);
+ check.type = atoi(row[2]);
+ check.ports = row[3];
+
+ for(i=1;i<6;i++)
+ {
+ zbx_snprintf(ip,MAX_STRING_LEN-1,"192.168.3.%d",i);
+ zabbix_log( LOG_LEVEL_DEBUG, "Processing IP %s", ip);
+
+ process_check(rule, &check, ip);
+ }
+ }
+ DBfree_result(result);
+
+ zabbix_log( LOG_LEVEL_DEBUG, "End process_rule()");
+}
+
+/******************************************************************************
+ * *
+ * Function: main_discoverer_loop *
+ * *
+ * Purpose: periodically try to find new hosts and services *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: executes once per 30 seconds (hardcoded) *
+ * *
+ ******************************************************************************/
+void main_discoverer_loop(int num)
+{
+ int now;
+
+ DB_RESULT result;
+ DB_ROW row;
+ DB_DRULE rule;
+
+ zabbix_log( LOG_LEVEL_DEBUG, "In main_discoverer_loop(num:%d)", num);
+
+ discoverer_num = num;
+
+ DBconnect(ZBX_DB_CONNECT_NORMAL);
+
+ for(;;)
+ {
+ now=time(NULL);
+
+ result = DBselect("select druleid,ipfirst,iplast,delay,nextcheck,name,status,upevent,downevent,svcupevent,svcdownevent from drules where status=%d and nextcheck<=%d and " ZBX_SQL_MOD(druleid,%d) "=%d and" ZBX_COND_NODEID,
+ DRULE_STATUS_MONITORED,
+ now,
+ CONFIG_DISCOVERER_FORKS,
+ discoverer_num-1,
+ LOCAL_NODE("druleid"));
+ while((row=DBfetch(result)))
+ {
+ ZBX_STR2UINT64(rule.druleid,row[0]);
+ rule.ipfirst = row[1];
+ rule.iplast = row[2];
+ rule.delay = atoi(row[3]);
+ rule.nextcheck = atoi(row[4]);
+ rule.name = row[5];
+ rule.status = atoi(row[6]);
+ rule.upevent = atoi(row[7]);
+ rule.downevent = atoi(row[8]);
+ rule.svcupevent = atoi(row[9]);
+ rule.svndownevent = atoi(row[10]);
+
+ process_rule(&rule);
+ }
+ DBfree_result(result);
+
+ zbx_setproctitle("sleeping for 30 sec");
+
+ sleep(30);
+ }
+ DBclose();
+}
diff --git a/src/zabbix_server/discoverer/discoverer.h b/src/zabbix_server/discoverer/discoverer.h
new file mode 100644
index 00000000..38a453b5
--- /dev/null
+++ b/src/zabbix_server/discoverer/discoverer.h
@@ -0,0 +1,28 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_DISCOVERER_H
+#define ZABBIX_DISCOVERER_H
+
+extern int CONFIG_NODEID;
+extern int CONFIG_DISCOVERER_FORKS;
+
+void main_discoverer_loop(int num);
+
+#endif
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index 97c57c4e..1ad2fe76 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -32,6 +32,7 @@
#include "daemon.h"
#include "alerter/alerter.h"
+#include "discoverer/discoverer.h"
#include "httppoller/httppoller.h"
#include "housekeeper/housekeeper.h"
#include "pinger/pinger.h"
@@ -82,6 +83,7 @@ struct option longopts[] =
pid_t *threads=NULL;
int CONFIG_ALERTER_FORKS = 1;
+int CONFIG_DISCOVERER_FORKS = 1;
int CONFIG_HOUSEKEEPER_FORKS = 1;
int CONFIG_NODEWATCHER_FORKS = 1;
int CONFIG_PINGER_FORKS = 1;
@@ -144,6 +146,7 @@ void init_config(void)
static struct cfg_line cfg[]=
{
/* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX */
+ {"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},
{"StartPollers",&CONFIG_POLLER_FORKS,0,TYPE_INT,PARM_OPT,0,255},
@@ -508,14 +511,17 @@ int MAIN_ZABBIX_ENTRY(void)
#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,sizeof(pid_t));
+ +CONFIG_NODEWATCHER_FORKS+CONFIG_HTTPPOLLER_FORKS+CONFIG_DISCOVERER_FORKS,
+ sizeof(pid_t));
if(CONFIG_TRAPPERD_FORKS > 0)
{
listenfd = tcp_listen(host,CONFIG_LISTEN_PORT,&addrlen);
}
- 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; 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;
+ i++)
{
if((pid = zbx_fork()) == 0)
{
@@ -616,6 +622,16 @@ int MAIN_ZABBIX_ENTRY(void)
- CONFIG_ALERTER_FORKS - CONFIG_HOUSEKEEPER_FORKS - CONFIG_TIMER_FORKS
- CONFIG_UNREACHABLE_POLLER_FORKS - CONFIG_NODEWATCHER_FORKS);
}
+ else if(server_num <= 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)
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Discoverer]",
+ server_num);
+ main_discoverer_loop(server_num - 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);
+ }
return SUCCEED;
/*
@@ -702,7 +718,7 @@ 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; 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; i++)
{
if(threads[i]) {
kill(threads[i],SIGTERM);
diff --git a/upgrades/dbpatches/1.3/mysql/patch/dchecks.sql b/upgrades/dbpatches/1.3/mysql/patch/dchecks.sql
new file mode 100644
index 00000000..cb00b398
--- /dev/null
+++ b/upgrades/dbpatches/1.3/mysql/patch/dchecks.sql
@@ -0,0 +1,7 @@
+CREATE TABLE dchecks (
+ dcheckid bigint unsigned DEFAULT '0' NOT NULL,
+ druleid bigint unsigned DEFAULT '0' NOT NULL,
+ type integer DEFAULT '0' NOT NULL,
+ ports varchar(255) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (dcheckid)
+) type=InnoDB;
diff --git a/upgrades/dbpatches/1.3/mysql/patch/dhosts.sql b/upgrades/dbpatches/1.3/mysql/patch/dhosts.sql
new file mode 100644
index 00000000..8cc14531
--- /dev/null
+++ b/upgrades/dbpatches/1.3/mysql/patch/dhosts.sql
@@ -0,0 +1,9 @@
+CREATE TABLE dhosts (
+ dhostid bigint unsigned DEFAULT '0' NOT NULL,
+ druleid bigint unsigned DEFAULT '0' NOT NULL,
+ ip varchar(15) DEFAULT '' NOT NULL,
+ status integer DEFAULT '0' NOT NULL,
+ lastup integer DEFAULT '0' NOT NULL,
+ lastdown integer DEFAULT '0' NOT NULL,
+ PRIMARY KEY (dhostid)
+) type=InnoDB;
diff --git a/upgrades/dbpatches/1.3/mysql/patch/drules.sql b/upgrades/dbpatches/1.3/mysql/patch/drules.sql
new file mode 100644
index 00000000..f2ffd70f
--- /dev/null
+++ b/upgrades/dbpatches/1.3/mysql/patch/drules.sql
@@ -0,0 +1,14 @@
+CREATE TABLE drules (
+ druleid bigint unsigned DEFAULT '0' NOT NULL,
+ name varchar(255) DEFAULT '' NOT NULL,
+ ipfirst varchar(15) DEFAULT '' NOT NULL,
+ iplast varchar(15) DEFAULT '' NOT NULL,
+ delay integer DEFAULT '0' NOT NULL,
+ nextcheck integer DEFAULT '0' NOT NULL,
+ status integer DEFAULT '0' NOT NULL,
+ upevent integer DEFAULT '0' NOT NULL,
+ downevent integer DEFAULT '0' NOT NULL,
+ svcupevent integer DEFAULT '0' NOT NULL,
+ svcdownevent integer DEFAULT '0' NOT NULL,
+ PRIMARY KEY (druleid)
+) type=InnoDB;
diff --git a/upgrades/dbpatches/1.3/mysql/patch/dservices.sql b/upgrades/dbpatches/1.3/mysql/patch/dservices.sql
new file mode 100644
index 00000000..9904db8c
--- /dev/null
+++ b/upgrades/dbpatches/1.3/mysql/patch/dservices.sql
@@ -0,0 +1,10 @@
+CREATE TABLE dservices (
+ dserviceid bigint unsigned DEFAULT '0' NOT NULL,
+ dhostid bigint unsigned DEFAULT '0' NOT NULL,
+ type integer DEFAULT '0' NOT NULL,
+ port integer DEFAULT '0' NOT NULL,
+ status integer DEFAULT '0' NOT NULL,
+ lastup integer DEFAULT '0' NOT NULL,
+ lastdown integer DEFAULT '0' NOT NULL,
+ PRIMARY KEY (dserviceid)
+) type=InnoDB;
diff --git a/upgrades/dbpatches/1.3/postgresql/patch/dchecks.sql b/upgrades/dbpatches/1.3/postgresql/patch/dchecks.sql
new file mode 100644
index 00000000..5cf5d873
--- /dev/null
+++ b/upgrades/dbpatches/1.3/postgresql/patch/dchecks.sql
@@ -0,0 +1,7 @@
+CREATE TABLE dchecks (
+ dcheckid bigint DEFAULT '0' NOT NULL,
+ druleid bigint DEFAULT '0' NOT NULL,
+ type integer DEFAULT '0' NOT NULL,
+ ports varchar(255) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (dcheckid)
+);
diff --git a/upgrades/dbpatches/1.3/postgresql/patch/dhosts.sql b/upgrades/dbpatches/1.3/postgresql/patch/dhosts.sql
new file mode 100644
index 00000000..37f3649e
--- /dev/null
+++ b/upgrades/dbpatches/1.3/postgresql/patch/dhosts.sql
@@ -0,0 +1,9 @@
+CREATE TABLE dhosts (
+ dhostid bigint DEFAULT '0' NOT NULL,
+ druleid bigint DEFAULT '0' NOT NULL,
+ ip varchar(15) DEFAULT '' NOT NULL,
+ status integer DEFAULT '0' NOT NULL,
+ lastup integer DEFAULT '0' NOT NULL,
+ lastdown integer DEFAULT '0' NOT NULL,
+ PRIMARY KEY (dhostid)
+);
diff --git a/upgrades/dbpatches/1.3/postgresql/patch/drules.sql b/upgrades/dbpatches/1.3/postgresql/patch/drules.sql
new file mode 100644
index 00000000..f05f14b9
--- /dev/null
+++ b/upgrades/dbpatches/1.3/postgresql/patch/drules.sql
@@ -0,0 +1,14 @@
+CREATE TABLE drules (
+ druleid bigint DEFAULT '0' NOT NULL,
+ name varchar(255) DEFAULT '' NOT NULL,
+ ipfirst varchar(15) DEFAULT '' NOT NULL,
+ iplast varchar(15) DEFAULT '' NOT NULL,
+ delay integer DEFAULT '0' NOT NULL,
+ nextcheck integer DEFAULT '0' NOT NULL,
+ status integer DEFAULT '0' NOT NULL,
+ upevent integer DEFAULT '0' NOT NULL,
+ downevent integer DEFAULT '0' NOT NULL,
+ svcupevent integer DEFAULT '0' NOT NULL,
+ svcdownevent integer DEFAULT '0' NOT NULL,
+ PRIMARY KEY (druleid)
+);
diff --git a/upgrades/dbpatches/1.3/postgresql/patch/dservices.sql b/upgrades/dbpatches/1.3/postgresql/patch/dservices.sql
new file mode 100644
index 00000000..3a2ec37a
--- /dev/null
+++ b/upgrades/dbpatches/1.3/postgresql/patch/dservices.sql
@@ -0,0 +1,10 @@
+CREATE TABLE dservices (
+ dserviceid bigint DEFAULT '0' NOT NULL,
+ dhostid bigint DEFAULT '0' NOT NULL,
+ type integer DEFAULT '0' NOT NULL,
+ port integer DEFAULT '0' NOT NULL,
+ status integer DEFAULT '0' NOT NULL,
+ lastup integer DEFAULT '0' NOT NULL,
+ lastdown integer DEFAULT '0' NOT NULL,
+ PRIMARY KEY (dserviceid)
+);