From feaffe83e4a0980af3e2f16742ca1c0e82d045dc Mon Sep 17 00:00:00 2001 From: hugetoad Date: Fri, 10 Jun 2005 08:08:17 +0000 Subject: Minor changes. git-svn-id: svn://svn.zabbix.com/trunk@1857 97f52cf1-0a1b-0410-bd0e-c28be96e8082 --- src/zabbix_server/Makefile.am | 4 +- src/zabbix_server/Makefile.in | 15 +-- src/zabbix_server/escalator.c | 197 -------------------------------- src/zabbix_server/escalator.h | 25 ---- src/zabbix_server/escalator/Makefile.am | 4 + src/zabbix_server/escalator/escalator.c | 197 ++++++++++++++++++++++++++++++++ src/zabbix_server/escalator/escalator.h | 25 ++++ src/zabbix_server/server.c | 2 +- 8 files changed, 237 insertions(+), 232 deletions(-) delete mode 100644 src/zabbix_server/escalator.c delete mode 100644 src/zabbix_server/escalator.h create mode 100644 src/zabbix_server/escalator/Makefile.am create mode 100644 src/zabbix_server/escalator/escalator.c create mode 100644 src/zabbix_server/escalator/escalator.h (limited to 'src') diff --git a/src/zabbix_server/Makefile.am b/src/zabbix_server/Makefile.am index 9dd121dc..32f874e0 100644 --- a/src/zabbix_server/Makefile.am +++ b/src/zabbix_server/Makefile.am @@ -2,6 +2,6 @@ SUBDIRS = pinger . INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ bin_PROGRAMS = zabbix_server -zabbix_server_SOURCES = alerter.c housekeeper.c checks_simple.c checks_snmp.c checks_agent.c checks_internal.c trapper.c escalator.c expression.c actions.c zlog.c functions.c server.c -zabbix_server_LDADD = ../libs/zbxsysinfo/libzbxsysinfo.a ../libs/zbxlog/libzbxlog.a ../libs/zbxpid/libzbxpid.a ../libs/zbxconf/libzbxconf.a ../libs/zbxdbhigh/libzbxdbhigh.a ../libs/zbxemail/libzbxemail.a ../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxnet/libzbxnet.a pinger/libzbxpinger.a +zabbix_server_SOURCES = alerter.c housekeeper.c checks_simple.c checks_snmp.c checks_agent.c checks_internal.c trapper.c expression.c actions.c zlog.c functions.c server.c +zabbix_server_LDADD = ../libs/zbxsysinfo/libzbxsysinfo.a ../libs/zbxlog/libzbxlog.a ../libs/zbxpid/libzbxpid.a ../libs/zbxconf/libzbxconf.a ../libs/zbxdbhigh/libzbxdbhigh.a ../libs/zbxemail/libzbxemail.a ../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxnet/libzbxnet.a pinger/libzbxpinger.a escalator/libzbxescalator.a zabbix_server_LDFLAGS=@MYSQL_LFLAGS@ @PGSQL_LFLAGS@ diff --git a/src/zabbix_server/Makefile.in b/src/zabbix_server/Makefile.in index eb8b93ff..5f42e132 100644 --- a/src/zabbix_server/Makefile.in +++ b/src/zabbix_server/Makefile.in @@ -80,8 +80,8 @@ SUBDIRS = pinger . INCLUDES = -I@top_srcdir@/include @MYSQL_INCLUDE@ bin_PROGRAMS = zabbix_server -zabbix_server_SOURCES = alerter.c housekeeper.c checks_simple.c checks_snmp.c checks_agent.c checks_internal.c trapper.c escalator.c expression.c actions.c zlog.c functions.c server.c -zabbix_server_LDADD = ../libs/zbxsysinfo/libzbxsysinfo.a ../libs/zbxlog/libzbxlog.a ../libs/zbxpid/libzbxpid.a ../libs/zbxconf/libzbxconf.a ../libs/zbxdbhigh/libzbxdbhigh.a ../libs/zbxemail/libzbxemail.a ../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxnet/libzbxnet.a pinger/libzbxpinger.a +zabbix_server_SOURCES = alerter.c housekeeper.c checks_simple.c checks_snmp.c checks_agent.c checks_internal.c trapper.c expression.c actions.c zlog.c functions.c server.c +zabbix_server_LDADD = ../libs/zbxsysinfo/libzbxsysinfo.a ../libs/zbxlog/libzbxlog.a ../libs/zbxpid/libzbxpid.a ../libs/zbxconf/libzbxconf.a ../libs/zbxdbhigh/libzbxdbhigh.a ../libs/zbxemail/libzbxemail.a ../libs/zbxcrypto/libzbxcrypto.a ../libs/zbxnet/libzbxnet.a pinger/libzbxpinger.a escalator/libzbxescalator.a zabbix_server_LDFLAGS = @MYSQL_LFLAGS@ @PGSQL_LFLAGS@ mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs CONFIG_HEADER = ../../include/config.h @@ -94,13 +94,14 @@ CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ zabbix_server_OBJECTS = alerter.o housekeeper.o checks_simple.o \ -checks_snmp.o checks_agent.o checks_internal.o trapper.o escalator.o \ -expression.o actions.o zlog.o functions.o server.o +checks_snmp.o checks_agent.o checks_internal.o trapper.o expression.o \ +actions.o zlog.o functions.o server.o zabbix_server_DEPENDENCIES = ../libs/zbxsysinfo/libzbxsysinfo.a \ ../libs/zbxlog/libzbxlog.a ../libs/zbxpid/libzbxpid.a \ ../libs/zbxconf/libzbxconf.a ../libs/zbxdbhigh/libzbxdbhigh.a \ ../libs/zbxemail/libzbxemail.a ../libs/zbxcrypto/libzbxcrypto.a \ -../libs/zbxnet/libzbxnet.a pinger/libzbxpinger.a +../libs/zbxnet/libzbxnet.a pinger/libzbxpinger.a \ +escalator/libzbxescalator.a CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) CCLD = $(CC) @@ -114,8 +115,8 @@ TAR = tar GZIP_ENV = --best DEP_FILES = .deps/actions.P .deps/alerter.P .deps/checks_agent.P \ .deps/checks_internal.P .deps/checks_simple.P .deps/checks_snmp.P \ -.deps/escalator.P .deps/expression.P .deps/functions.P \ -.deps/housekeeper.P .deps/server.P .deps/trapper.P .deps/zlog.P +.deps/expression.P .deps/functions.P .deps/housekeeper.P .deps/server.P \ +.deps/trapper.P .deps/zlog.P SOURCES = $(zabbix_server_SOURCES) OBJECTS = $(zabbix_server_OBJECTS) diff --git a/src/zabbix_server/escalator.c b/src/zabbix_server/escalator.c deleted file mode 100644 index 3b778841..00000000 --- a/src/zabbix_server/escalator.c +++ /dev/null @@ -1,197 +0,0 @@ -/* -** 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 "config.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#ifdef HAVE_NETDB_H - #include -#endif - -/* Required for getpwuid */ -#include - -#include -#include - -#include - -#include "common.h" -#include "cfg.h" -#include "db.h" -#include "functions.h" -#include "log.h" -#include "zlog.h" -#include "email.h" - -#include "escalator.h" - -int process_escalation(DB_ESCALATION_LOG *escalation_log) -{ - int i,now; - char sql[MAX_STRING_LEN]; - int processed_level; - - DB_RESULT *result; - DB_ESCALATION_RULE escalation_rule; - - zabbix_log( LOG_LEVEL_WARNING, "In process_escalation()"); - - snprintf(sql,sizeof(sql)-1,"select escalationruleid, escalationid,level,period,delay,actiontype from escalation_rules where escalationid=%d and level>=%d order by level", escalation_log->escalationid, escalation_log->level); - zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); - result = DBselect(sql); - - processed_level=escalation_log->level; - - for(i=0;i escalation_rule.level) break; - - zabbix_log( LOG_LEVEL_WARNING, "Selected escalationrule ID [%d]", escalation_rule.escalationruleid); - now=time(NULL); - if(escalation_log->nextcheck <= now) - { - /* ADD check_period() !!! */ - switch (escalation_rule.actiontype) - { - case ESCALATION_ACTION_NOTHING: - zabbix_log( LOG_LEVEL_WARNING, "ESCALATION_ACTION_NOTHING"); - escalation_log->nextcheck = escalation_rule.delay+now; - escalation_log->level = escalation_rule.level; - snprintf(sql,sizeof(sql)-1,"update escalation_log set nextcheck=%d,level=%d where escalationlogid=%d", escalation_log->nextcheck, escalation_log->level, escalation_log->escalationlogid); - zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); - DBexecute(sql); - break; - case ESCALATION_ACTION_EXEC_ACTION: - zabbix_log( LOG_LEVEL_WARNING, "ESCALATION_ACTION_EXEC_ACTION"); - escalation_log->nextcheck = escalation_rule.delay+now; - escalation_log->level = escalation_rule.level; - snprintf(sql,sizeof(sql)-1,"update escalation_log set nextcheck=%d,level=%d where escalationlogid=%d", escalation_log->nextcheck, escalation_log->level, escalation_log->escalationlogid); - zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); - DBexecute(sql); - break; - case ESCALATION_ACTION_INC_SEVERITY: - zabbix_log( LOG_LEVEL_WARNING, "ESCALATION_ACTION_INC_SEVERITY"); - escalation_log->nextcheck = escalation_rule.delay+now; - escalation_log->level = escalation_rule.level; - snprintf(sql,sizeof(sql)-1,"update escalation_log set nextcheck=%d,level=%d where escalationlogid=%d", escalation_log->nextcheck, escalation_log->level, escalation_log->escalationlogid); - zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); - DBexecute(sql); - break; - case ESCALATION_ACTION_INC_ADMIN: - zabbix_log( LOG_LEVEL_WARNING, "ESCALATION_ACTION_INC_ADMIN"); - escalation_log->nextcheck = escalation_rule.delay+now; - escalation_log->level = escalation_rule.level; - snprintf(sql,sizeof(sql)-1,"update escalation_log set nextcheck=%d,level=%d where escalationlogid=%d", escalation_log->nextcheck, escalation_log->level, escalation_log->escalationlogid); - zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); - DBexecute(sql); - break; - default: - zabbix_log( LOG_LEVEL_ERR, "Unknow escalation action type [%d]", escalation_rule.actiontype); - } - processed_level= escalation_rule.level; - } - } - if(DBnum_rows(result)==0) - { - zabbix_log( LOG_LEVEL_WARNING, "No more escalation levels"); - snprintf(sql,sizeof(sql)-1,"update escalation_log set status=1 where escalationlogid=%d", escalation_log->escalationlogid); - zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); - DBexecute(sql); - } - DBfree_result(result); - - return SUCCEED; -} - -int main_escalator_loop() -{ - char sql[MAX_STRING_LEN]; - - int i,res; - int now; - - DB_RESULT *result; - - DB_ESCALATION_LOG escalation_log; - - for(;;) - { - zabbix_log( LOG_LEVEL_WARNING, "Selecting data from escalation_log"); -#ifdef HAVE_FUNCTION_SETPROCTITLE - setproctitle("connecting to the database"); -#endif - - DBconnect(); - - now=time(NULL); - snprintf(sql,sizeof(sql)-1,"select escalationlogid,triggerid, alarmid, escalationid, level, adminlevel, nextcheck, status from escalation_log where status=0 and nextcheck<=%d", now); - result = DBselect(sql); - - for(i=0;i +#include +#include +#include +#include +#include +#include + +#include + +#include + +#ifdef HAVE_NETDB_H + #include +#endif + +/* Required for getpwuid */ +#include + +#include +#include + +#include + +#include "common.h" +#include "cfg.h" +#include "db.h" +#include "functions.h" +#include "log.h" +#include "zlog.h" +#include "email.h" + +#include "escalator.h" + +int process_escalation(DB_ESCALATION_LOG *escalation_log) +{ + int i,now; + char sql[MAX_STRING_LEN]; + int processed_level; + + DB_RESULT *result; + DB_ESCALATION_RULE escalation_rule; + + zabbix_log( LOG_LEVEL_WARNING, "In process_escalation()"); + + snprintf(sql,sizeof(sql)-1,"select escalationruleid, escalationid,level,period,delay,actiontype from escalation_rules where escalationid=%d and level>=%d order by level", escalation_log->escalationid, escalation_log->level); + zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); + result = DBselect(sql); + + processed_level=escalation_log->level; + + for(i=0;i escalation_rule.level) break; + + zabbix_log( LOG_LEVEL_WARNING, "Selected escalationrule ID [%d]", escalation_rule.escalationruleid); + now=time(NULL); + if(escalation_log->nextcheck <= now) + { + /* ADD check_period() !!! */ + switch (escalation_rule.actiontype) + { + case ESCALATION_ACTION_NOTHING: + zabbix_log( LOG_LEVEL_WARNING, "ESCALATION_ACTION_NOTHING"); + escalation_log->nextcheck = escalation_rule.delay+now; + escalation_log->level = escalation_rule.level; + snprintf(sql,sizeof(sql)-1,"update escalation_log set nextcheck=%d,level=%d where escalationlogid=%d", escalation_log->nextcheck, escalation_log->level, escalation_log->escalationlogid); + zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); + DBexecute(sql); + break; + case ESCALATION_ACTION_EXEC_ACTION: + zabbix_log( LOG_LEVEL_WARNING, "ESCALATION_ACTION_EXEC_ACTION"); + escalation_log->nextcheck = escalation_rule.delay+now; + escalation_log->level = escalation_rule.level; + snprintf(sql,sizeof(sql)-1,"update escalation_log set nextcheck=%d,level=%d where escalationlogid=%d", escalation_log->nextcheck, escalation_log->level, escalation_log->escalationlogid); + zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); + DBexecute(sql); + break; + case ESCALATION_ACTION_INC_SEVERITY: + zabbix_log( LOG_LEVEL_WARNING, "ESCALATION_ACTION_INC_SEVERITY"); + escalation_log->nextcheck = escalation_rule.delay+now; + escalation_log->level = escalation_rule.level; + snprintf(sql,sizeof(sql)-1,"update escalation_log set nextcheck=%d,level=%d where escalationlogid=%d", escalation_log->nextcheck, escalation_log->level, escalation_log->escalationlogid); + zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); + DBexecute(sql); + break; + case ESCALATION_ACTION_INC_ADMIN: + zabbix_log( LOG_LEVEL_WARNING, "ESCALATION_ACTION_INC_ADMIN"); + escalation_log->nextcheck = escalation_rule.delay+now; + escalation_log->level = escalation_rule.level; + snprintf(sql,sizeof(sql)-1,"update escalation_log set nextcheck=%d,level=%d where escalationlogid=%d", escalation_log->nextcheck, escalation_log->level, escalation_log->escalationlogid); + zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); + DBexecute(sql); + break; + default: + zabbix_log( LOG_LEVEL_ERR, "Unknow escalation action type [%d]", escalation_rule.actiontype); + } + processed_level= escalation_rule.level; + } + } + if(DBnum_rows(result)==0) + { + zabbix_log( LOG_LEVEL_WARNING, "No more escalation levels"); + snprintf(sql,sizeof(sql)-1,"update escalation_log set status=1 where escalationlogid=%d", escalation_log->escalationlogid); + zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql); + DBexecute(sql); + } + DBfree_result(result); + + return SUCCEED; +} + +int main_escalator_loop() +{ + char sql[MAX_STRING_LEN]; + + int i,res; + int now; + + DB_RESULT *result; + + DB_ESCALATION_LOG escalation_log; + + for(;;) + { + zabbix_log( LOG_LEVEL_WARNING, "Selecting data from escalation_log"); +#ifdef HAVE_FUNCTION_SETPROCTITLE + setproctitle("connecting to the database"); +#endif + + DBconnect(); + + now=time(NULL); + snprintf(sql,sizeof(sql)-1,"select escalationlogid,triggerid, alarmid, escalationid, level, adminlevel, nextcheck, status from escalation_log where status=0 and nextcheck<=%d", now); + result = DBselect(sql); + + for(i=0;i