diff options
-rw-r--r-- | create/schema/schema.sql | 2 | ||||
-rw-r--r-- | include/common.h | 3 | ||||
-rw-r--r-- | include/db.h | 6 | ||||
-rw-r--r-- | src/zabbix_server/actions.c | 126 | ||||
-rw-r--r-- | src/zabbix_server/discoverer/discoverer.c | 150 | ||||
-rw-r--r-- | upgrades/dbpatches/1.4/mysql/patch/dhosts.sql | 1 | ||||
-rw-r--r-- | upgrades/dbpatches/1.4/mysql/patch/drules.sql | 4 | ||||
-rw-r--r-- | upgrades/dbpatches/1.4/mysql/patch/dservices.sql | 1 | ||||
-rw-r--r-- | upgrades/dbpatches/1.4/postgresql/patch/dhosts.sql | 1 | ||||
-rw-r--r-- | upgrades/dbpatches/1.4/postgresql/patch/drules.sql | 4 | ||||
-rw-r--r-- | upgrades/dbpatches/1.4/postgresql/patch/dservices.sql | 1 |
11 files changed, 183 insertions, 116 deletions
diff --git a/create/schema/schema.sql b/create/schema/schema.sql index 97c7f1e5..6e0eaa76 100644 --- a/create/schema/schema.sql +++ b/create/schema/schema.sql @@ -60,7 +60,6 @@ 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 -FIELD |eventsent |t_integer |'0' |NOT NULL |ZBX_SYNC TABLE|dservices|dserviceid|ZBX_SYNC FIELD |dserviceid |t_id |'0' |NOT NULL |ZBX_SYNC @@ -70,7 +69,6 @@ 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 -FIELD |eventsent |t_integer |'0' |NOT NULL |ZBX_SYNC TABLE|ids|nodeid,table_name,field_name| FIELD |nodeid |t_integer |'0' |NOT NULL |0 diff --git a/include/common.h b/include/common.h index b5cd9229..2bbe40c6 100644 --- a/include/common.h +++ b/include/common.h @@ -220,7 +220,8 @@ typedef enum CONDITION_TYPE_DHOST_IP, CONDITION_TYPE_DSERVICE_TYPE, CONDITION_TYPE_DSERVICE_PORT, - CONDITION_TYPE_DSTATUS + CONDITION_TYPE_DSTATUS, + CONDITION_TYPE_DUPTIME } zbx_condition_type_t; /* Condition operators */ diff --git a/include/db.h b/include/db.h index 68a9203c..644f294f 100644 --- a/include/db.h +++ b/include/db.h @@ -121,10 +121,6 @@ DB_DRULE int nextcheck; char *name; int status; - int upevent; - int downevent; - int svcupevent; - int svcdownevent; }; DB_DCHECK @@ -144,7 +140,6 @@ DB_DHOST int status; int lastup; int lastdown; - int eventsent; }; DB_DSERVICE @@ -156,7 +151,6 @@ DB_DSERVICE int status; int lastup; int lastdown; - int eventsent; }; DB_EVENT diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c index c2330f17..dddd9a87 100644 --- a/src/zabbix_server/actions.c +++ b/src/zabbix_server/actions.c @@ -75,6 +75,8 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) zbx_uint64_t hostid; zbx_uint64_t condition_value; int value_int; + int now; + int tmp_int; char *tmp_str = NULL; @@ -320,6 +322,130 @@ static int check_action_condition(DB_EVENT *event, DB_CONDITION *condition) DBfree_result(result); } else if(event->source == EVENT_SOURCE_DISCOVERY && + event->object == EVENT_OBJECT_DHOST && + condition->conditiontype == CONDITION_TYPE_DSTATUS) + { + zabbix_log( LOG_LEVEL_DEBUG, "CONDITION_TYPE_DSTATUS [%d:%s]", + event->value, + condition->value); + value_int = atoi(condition->value); + result = DBselect("select status from dhosts where dhostid=" ZBX_FS_UI64, + event->objectid); + row = DBfetch(result); + if(row && DBis_null(row[0]) != SUCCEED) + { + if(condition->operator == CONDITION_OPERATOR_EQUAL) + { + if(value_int == atoi(row[0])) ret = SUCCEED; + } + else if(condition->operator == CONDITION_OPERATOR_NOT_EQUAL) + { + if(atoi(row[0]) != value_int) ret = SUCCEED; + } + else + { + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", + condition->operator, + condition->conditionid); + } + } + DBfree_result(result); + } + else if(event->source == EVENT_SOURCE_DISCOVERY && + event->object == EVENT_OBJECT_DSERVICE && + condition->conditiontype == CONDITION_TYPE_DSTATUS) + { + zabbix_log( LOG_LEVEL_DEBUG, "CONDITION_TYPE_DSERVICE [%d:%s]", + event->value, + condition->value); + value_int = atoi(condition->value); + result = DBselect("select status from dservices where dserviceid=" ZBX_FS_UI64, + event->objectid); + row = DBfetch(result); + if(row && DBis_null(row[0]) != SUCCEED) + { + if(condition->operator == CONDITION_OPERATOR_EQUAL) + { + if(value_int == atoi(row[0])) ret = SUCCEED; + } + else if(condition->operator == CONDITION_OPERATOR_NOT_EQUAL) + { + if(atoi(row[0]) != value_int) ret = SUCCEED; + } + else + { + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", + condition->operator, + condition->conditionid); + } + } + DBfree_result(result); + } + else if(event->source == EVENT_SOURCE_DISCOVERY && + event->object == EVENT_OBJECT_DHOST && + condition->conditiontype == CONDITION_TYPE_DUPTIME) + { + zabbix_log( LOG_LEVEL_DEBUG, "CONDITION_TYPE_DUPTIME [%d:%s]", + event->value, + condition->value); + value_int = atoi(condition->value); + result = DBselect("select status,lastup,lastdown from dhosts where dhostid=" ZBX_FS_UI64, + event->objectid); + row = DBfetch(result); + if(row && DBis_null(row[0]) != SUCCEED) + { + tmp_int = (atoi(row[0]) == DOBJECT_STATUS_UP)?atoi(row[1]):atoi(row[2]); + now = time(NULL); + if(condition->operator == CONDITION_OPERATOR_LESS_EQUAL) + { + if(tmp_int != 0 && (now-value_int)<=value_int) ret = SUCCEED; + } + else if(condition->operator == CONDITION_OPERATOR_MORE_EQUAL) + { + if(tmp_int != 0 && (now-value_int)>=value_int) ret = SUCCEED; + } + else + { + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", + condition->operator, + condition->conditionid); + } + } + DBfree_result(result); + } + else if(event->source == EVENT_SOURCE_DISCOVERY && + event->object == EVENT_OBJECT_DSERVICE && + condition->conditiontype == CONDITION_TYPE_DUPTIME) + { + zabbix_log( LOG_LEVEL_DEBUG, "CONDITION_TYPE_DUPTIME [%d:%s]", + event->value, + condition->value); + value_int = atoi(condition->value); + result = DBselect("select status,lastup,lastdown from dservices where dserviceid=" ZBX_FS_UI64, + event->objectid); + row = DBfetch(result); + if(row && DBis_null(row[0]) != SUCCEED) + { + tmp_int = (atoi(row[0]) == DOBJECT_STATUS_UP)?atoi(row[1]):atoi(row[2]); + now = time(NULL); + if(condition->operator == CONDITION_OPERATOR_LESS_EQUAL) + { + if(tmp_int != 0 && (now-value_int)<=value_int) ret = SUCCEED; + } + else if(condition->operator == CONDITION_OPERATOR_MORE_EQUAL) + { + if(tmp_int != 0 && (now-value_int)>=value_int) ret = SUCCEED; + } + else + { + zabbix_log( LOG_LEVEL_ERR, "Unsupported operator [%d] for condition id [" ZBX_FS_UI64 "]", + condition->operator, + condition->conditionid); + } + } + DBfree_result(result); + } + else if(event->source == EVENT_SOURCE_DISCOVERY && event->object == EVENT_OBJECT_DSERVICE && condition->conditiontype == CONDITION_TYPE_DSERVICE_PORT) { diff --git a/src/zabbix_server/discoverer/discoverer.c b/src/zabbix_server/discoverer/discoverer.c index 3ce8074c..5268cb83 100644 --- a/src/zabbix_server/discoverer/discoverer.c +++ b/src/zabbix_server/discoverer/discoverer.c @@ -47,26 +47,42 @@ int discoverer_num; * Comments: * * * ******************************************************************************/ -static void add_host_event(DB_DHOST *host, DB_DSERVICE *service) +static void add_host_event(char *ip) { + DB_RESULT result; + DB_ROW row; DB_EVENT event; int now; + int status; + zbx_uint64_t dhostid; - zabbix_log(LOG_LEVEL_DEBUG, "In add_host_event()"); + zabbix_log(LOG_LEVEL_WARNING, "In add_host_event(ip:%s)", + ip); - now = time(NULL); + result = DBselect("select status,dhostid from dhosts where ip='%s'", + ip); + row=DBfetch(result); + if(row && DBis_null(row[0])!=SUCCEED) + { + now = time(NULL); + status = atoi(row[0]); + ZBX_STR2UINT64(dhostid, row[1]); - memset(&event,0,sizeof(DB_EVENT)); + memset(&event,0,sizeof(DB_EVENT)); - event.eventid = 0; - event.source = EVENT_SOURCE_DISCOVERY; - event.object = EVENT_OBJECT_DHOST; - event.objectid = service->dhostid; - event.clock = now; - event.value = host->status; - event.acknowledged = 0; + event.eventid = 0; + event.source = EVENT_SOURCE_DISCOVERY; + event.object = EVENT_OBJECT_DHOST; + event.objectid = dhostid; + event.clock = now; + event.value = status; + event.acknowledged = 0; - process_event(&event); + process_event(&event); + } + DBfree_result(result); + + zabbix_log(LOG_LEVEL_WARNING, "End add_host_event()"); } /****************************************************************************** @@ -89,7 +105,7 @@ static void add_service_event(DB_DSERVICE *service) DB_EVENT event; int now; - zabbix_log(LOG_LEVEL_DEBUG, "In add_host_event()"); + zabbix_log(LOG_LEVEL_WARNING, "In add_service_event()"); now = time(NULL); @@ -104,6 +120,8 @@ static void add_service_event(DB_DSERVICE *service) event.acknowledged = 0; process_event(&event); + + zabbix_log(LOG_LEVEL_WARNING, "End add_service_event()"); } /****************************************************************************** @@ -123,14 +141,13 @@ static void add_service_event(DB_DSERVICE *service) ******************************************************************************/ static void update_dservice(DB_DSERVICE *service) { - DBexecute("update dservices set dhostid=" ZBX_FS_UI64 ",type=%d,port=%d,status=%d,lastup=%d,lastdown=%d,eventsent=%d where dserviceid=" ZBX_FS_UI64, + DBexecute("update dservices set dhostid=" ZBX_FS_UI64 ",type=%d,port=%d,status=%d,lastup=%d,lastdown=%d where dserviceid=" ZBX_FS_UI64, service->dhostid, service->type, service->port, service->status, service->lastup, service->lastdown, - service->eventsent, service->dserviceid); } @@ -151,13 +168,12 @@ static void update_dservice(DB_DSERVICE *service) ******************************************************************************/ static void update_dhost(DB_DHOST *host) { - DBexecute("update dhosts set druleid=" ZBX_FS_UI64 ",ip='%s',status=%d,lastup=%d,lastdown=%d,eventsent=%d where dhostid=" ZBX_FS_UI64, + DBexecute("update dhosts set druleid=" ZBX_FS_UI64 ",ip='%s',status=%d,lastup=%d,lastdown=%d where dhostid=" ZBX_FS_UI64, host->druleid, host->ip, host->status, host->lastup, host->lastdown, - host->eventsent, host->dhostid); } @@ -186,7 +202,7 @@ static void register_service(DB_DSERVICE *service,DB_DRULE *rule,DB_DCHECK *chec ip, port); - result = DBselect("select dserviceid,dhostid,type,port,status,lastup,lastdown,eventsent from dservices where dhostid=" ZBX_FS_UI64 " and type=%d and port=%d", + result = DBselect("select dserviceid,dhostid,type,port,status,lastup,lastdown from dservices where dhostid=" ZBX_FS_UI64 " and type=%d and port=%d", dhostid, check->type, port); @@ -212,7 +228,6 @@ static void register_service(DB_DSERVICE *service,DB_DRULE *rule,DB_DCHECK *chec service->status = DOBJECT_STATUS_UP; service->lastup = 0; service->lastdown = 0; - service->eventsent = 0; } } else @@ -225,7 +240,6 @@ static void register_service(DB_DSERVICE *service,DB_DRULE *rule,DB_DCHECK *chec service->status = atoi(row[4]); service->lastup = atoi(row[5]); service->lastdown = atoi(row[6]); - service->eventsent = atoi(row[7]); } DBfree_result(result); @@ -256,7 +270,7 @@ static void register_host(DB_DHOST *host,DB_DCHECK *check, zbx_uint64_t druleid, ip); host->dhostid=0; - result = DBselect("select dhostid,druleid,ip,status,lastup,lastdown,eventsent from dhosts where ip='%s' and " ZBX_COND_NODEID, + result = DBselect("select dhostid,druleid,ip,status,lastup,lastdown from dhosts where ip='%s' and " ZBX_COND_NODEID, ip, LOCAL_NODE("dhostid")); row=DBfetch(result); @@ -277,7 +291,6 @@ static void register_host(DB_DHOST *host,DB_DCHECK *check, zbx_uint64_t druleid, host->status = 0; host->lastup = 0; host->lastdown = 0; - host->eventsent = 0; } } else @@ -289,7 +302,6 @@ static void register_host(DB_DHOST *host,DB_DCHECK *check, zbx_uint64_t druleid, host->status = atoi(row[3]); host->lastup = atoi(row[4]); host->lastdown = atoi(row[5]); - host->eventsent = atoi(row[6]); } DBfree_result(result); @@ -349,7 +361,6 @@ static void update_service(DB_DRULE *rule, DB_DCHECK *check, char *ip, int port) host.status=DOBJECT_STATUS_UP; host.lastdown=0; host.lastup=now; - host.eventsent=0; update_dhost(&host); } /* Update service status */ @@ -358,7 +369,6 @@ static void update_service(DB_DRULE *rule, DB_DCHECK *check, char *ip, int port) service.status=DOBJECT_STATUS_UP; service.lastdown=0; service.lastup=now; - service.eventsent=0; update_dservice(&service); } } @@ -370,7 +380,6 @@ static void update_service(DB_DRULE *rule, DB_DCHECK *check, char *ip, int port) host.status=DOBJECT_STATUS_DOWN; host.lastup=now; host.lastdown=0; - host.eventsent=0; update_dhost(&host); } /* Update service status */ @@ -379,56 +388,11 @@ static void update_service(DB_DRULE *rule, DB_DCHECK *check, char *ip, int port) service.status=DOBJECT_STATUS_DOWN; service.lastup=now; service.lastdown=0; - service.eventsent=0; update_dservice(&service); } } - /* Generating host events */ - if(host.eventsent == 0) - { - if(host.status == DOBJECT_STATUS_UP && (host.lastup<=now-rule->upevent)) - { - zabbix_log(LOG_LEVEL_DEBUG, "Generating host event for %s", - host.ip); - host.eventsent=1; - - update_dhost(&host); - add_host_event(&host,&service); - } - if(host.status == DOBJECT_STATUS_DOWN && (host.lastdown<=now-rule->downevent)) - { - zabbix_log(LOG_LEVEL_DEBUG, "Generating host event for %s", - host.ip); - host.eventsent=1; - - update_dhost(&host); - add_host_event(&host,&service); - } - } - - /* Generating service events */ - if(service.eventsent == 0) - { - if(service.status == DOBJECT_STATUS_UP && (service.lastup<=now-rule->svcupevent)) - { - zabbix_log(LOG_LEVEL_DEBUG, "Generating service event for %s", - host.ip); - service.eventsent=1; - - update_dservice(&service); - add_service_event(&service); - } - if(service.status == DOBJECT_STATUS_DOWN && (service.lastdown<=now-rule->svcdownevent)) - { - zabbix_log(LOG_LEVEL_DEBUG, "Generating service event for %s", - host.ip); - service.eventsent=1; - - update_dservice(&service); - add_service_event(&service); - } - } + add_service_event(&service); } /****************************************************************************** @@ -626,31 +590,31 @@ static void process_rule(DB_DRULE *rule) 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]; - - first=atoi(strrchr(rule->ipfirst,'.')+1); - last=atoi(strrchr(rule->iplast,'.')+1); - c = strrchr(rule->ipfirst,'.'); + first=atoi(strrchr(rule->ipfirst,'.')+1); + last=atoi(strrchr(rule->iplast,'.')+1); + c = strrchr(rule->ipfirst,'.'); + for(i=first;i<=last;i++) + { c[0] = 0; - for(i=first;i<=last;i++) + zbx_snprintf(ip,MAX_STRING_LEN-1,"%s.%d", + rule->ipfirst, + i); + result = DBselect("select dcheckid,druleid,type,ports from dchecks where druleid=" ZBX_FS_UI64, + rule->druleid); + while((row=DBfetch(result))) { - zbx_snprintf(ip,MAX_STRING_LEN-1,"%s.%d", - rule->ipfirst, - i); - + ZBX_STR2UINT64(check.dcheckid,row[0]); + ZBX_STR2UINT64(check.druleid,row[1]); + check.type = atoi(row[2]); + check.ports = row[3]; + process_check(rule, &check, ip); } + DBfree_result(result); + add_host_event(ip); c[0] = '.'; } - DBfree_result(result); zabbix_log( LOG_LEVEL_DEBUG, "End process_rule()"); } @@ -689,7 +653,7 @@ void main_discoverer_loop(int num) { 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, + result = DBselect("select druleid,ipfirst,iplast,delay,nextcheck,name,status 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, @@ -704,10 +668,6 @@ void main_discoverer_loop(int num) 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.svcdownevent = atoi(row[10]); process_rule(&rule); } diff --git a/upgrades/dbpatches/1.4/mysql/patch/dhosts.sql b/upgrades/dbpatches/1.4/mysql/patch/dhosts.sql index d15489c8..17718048 100644 --- a/upgrades/dbpatches/1.4/mysql/patch/dhosts.sql +++ b/upgrades/dbpatches/1.4/mysql/patch/dhosts.sql @@ -5,6 +5,5 @@ CREATE TABLE dhosts ( status integer DEFAULT '0' NOT NULL, lastup integer DEFAULT '0' NOT NULL, lastdown integer DEFAULT '0' NOT NULL, - eventsent integer DEFAULT '0' NOT NULL, PRIMARY KEY (dhostid) ) type=InnoDB; diff --git a/upgrades/dbpatches/1.4/mysql/patch/drules.sql b/upgrades/dbpatches/1.4/mysql/patch/drules.sql index f2ffd70f..46a96eff 100644 --- a/upgrades/dbpatches/1.4/mysql/patch/drules.sql +++ b/upgrades/dbpatches/1.4/mysql/patch/drules.sql @@ -6,9 +6,5 @@ CREATE TABLE drules ( 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.4/mysql/patch/dservices.sql b/upgrades/dbpatches/1.4/mysql/patch/dservices.sql index 9c8fc2b2..1e37f046 100644 --- a/upgrades/dbpatches/1.4/mysql/patch/dservices.sql +++ b/upgrades/dbpatches/1.4/mysql/patch/dservices.sql @@ -6,6 +6,5 @@ CREATE TABLE dservices ( status integer DEFAULT '0' NOT NULL, lastup integer DEFAULT '0' NOT NULL, lastdown integer DEFAULT '0' NOT NULL, - eventsent integer DEFAULT '0' NOT NULL, PRIMARY KEY (dserviceid) ) type=InnoDB; diff --git a/upgrades/dbpatches/1.4/postgresql/patch/dhosts.sql b/upgrades/dbpatches/1.4/postgresql/patch/dhosts.sql index f4a1c855..37f3649e 100644 --- a/upgrades/dbpatches/1.4/postgresql/patch/dhosts.sql +++ b/upgrades/dbpatches/1.4/postgresql/patch/dhosts.sql @@ -5,6 +5,5 @@ CREATE TABLE dhosts ( status integer DEFAULT '0' NOT NULL, lastup integer DEFAULT '0' NOT NULL, lastdown integer DEFAULT '0' NOT NULL, - eventsent integer DEFAULT '0' NOT NULL, PRIMARY KEY (dhostid) ); diff --git a/upgrades/dbpatches/1.4/postgresql/patch/drules.sql b/upgrades/dbpatches/1.4/postgresql/patch/drules.sql index f05f14b9..b2ba3419 100644 --- a/upgrades/dbpatches/1.4/postgresql/patch/drules.sql +++ b/upgrades/dbpatches/1.4/postgresql/patch/drules.sql @@ -6,9 +6,5 @@ CREATE TABLE drules ( 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.4/postgresql/patch/dservices.sql b/upgrades/dbpatches/1.4/postgresql/patch/dservices.sql index 2636c81d..3a2ec37a 100644 --- a/upgrades/dbpatches/1.4/postgresql/patch/dservices.sql +++ b/upgrades/dbpatches/1.4/postgresql/patch/dservices.sql @@ -6,6 +6,5 @@ CREATE TABLE dservices ( status integer DEFAULT '0' NOT NULL, lastup integer DEFAULT '0' NOT NULL, lastdown integer DEFAULT '0' NOT NULL, - eventsent integer DEFAULT '0' NOT NULL, PRIMARY KEY (dserviceid) ); |