diff options
| author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-06-20 08:17:12 +0000 |
|---|---|---|
| committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-06-20 08:17:12 +0000 |
| commit | 01cd848a925015679ea237651e6291cd44129858 (patch) | |
| tree | 4327bfc443b9aff048f93b9d12ae3ad2de15533a /src/zabbix_server/timer | |
| parent | 06e27fe2d16497bb5021d9ed61b15a2d67b5d75e (diff) | |
| download | zabbix-01cd848a925015679ea237651e6291cd44129858.tar.gz zabbix-01cd848a925015679ea237651e6291cd44129858.tar.xz zabbix-01cd848a925015679ea237651e6291cd44129858.zip | |
- added column escalation_log.actiontype (Alexei)
- time related function 'nodata','date','dayofweek','time','now' will be
periodically updated (Alexei)
- update of functions optimised. Do not update if same value. (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@1880 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_server/timer')
| -rw-r--r-- | src/zabbix_server/timer/Makefile.am | 4 | ||||
| -rw-r--r-- | src/zabbix_server/timer/timer.c | 107 | ||||
| -rw-r--r-- | src/zabbix_server/timer/timer.h | 33 |
3 files changed, 144 insertions, 0 deletions
diff --git a/src/zabbix_server/timer/Makefile.am b/src/zabbix_server/timer/Makefile.am new file mode 100644 index 00000000..a1746574 --- /dev/null +++ b/src/zabbix_server/timer/Makefile.am @@ -0,0 +1,4 @@ +SUBDIRS=. +INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ +lib_LIBRARIES=libzbxtimer.a +libzbxtimer_a_SOURCES=timer.c diff --git a/src/zabbix_server/timer/timer.c b/src/zabbix_server/timer/timer.c new file mode 100644 index 00000000..15a5da7f --- /dev/null +++ b/src/zabbix_server/timer/timer.c @@ -0,0 +1,107 @@ +/* +** 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 <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> + +#include <string.h> + + +/* Required for getpwuid */ +#include <pwd.h> + +#include <signal.h> +#include <errno.h> + +#include <time.h> + +#include "cfg.h" +#include "pid.h" +#include "db.h" +#include "log.h" +#include "zlog.h" + +#include "common.h" + +/****************************************************************************** + * * + * Function: main_timer_loop * + * * + * Purpose: periodically updates time-related triggers * + * * + * Parameters: * + * * + * Return value: * + * * + * Author: Alexei Vladishev * + * * + * Comments: does update once per 30 seconds (hardcoded) * + * * + ******************************************************************************/ +void main_timer_loop() +{ + char sql[MAX_STRING_LEN]; + int i,now; + + int itemid,functionid; + char *parameter; + + DB_RESULT *result; + + for(;;) + { +#ifdef HAVE_FUNCTION_SETPROCTITLE + setproctitle("updating nodata() functions"); +#endif + + DBconnect(); + + now=time(NULL); +#ifdef HAVE_PGSQL + snprintf(sql,sizeof(sql)-1,"select distinct f.itemid,f.functionid,f.parameter from functions f, items i,hosts h where h.hostid=i.hostid and ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<%d)) and i.itemid=f.itemid and f.function in ('nodata','date','dayofweek','time','now') and i.lastclock+f.parameter::text::integer<=%d and i.status=%d and i.type=%d", HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER); +#else + snprintf(sql,sizeof(sql)-1,"select distinct f.itemid,f.functionid,f.parameter from functions f, items i,hosts h where h.hostid=i.hostid and ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<%d)) and i.itemid=f.itemid and f.function in ('nodata','date','dayofweek','time','now') and i.lastclock+f.parameter<=%d and i.status=%d and i.type=%d", HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER); +#endif + + result = DBselect(sql); + + for(i=0;i<DBnum_rows(result);i++) + { + itemid=atoi(DBget_field(result,i,0)); + functionid=atoi(DBget_field(result,i,1)); + parameter=DBget_field(result,i,2); + + snprintf(sql,sizeof(sql)-1,"update functions set lastvalue='1' where itemid=%d and function='nodata' and parameter='%s'" , itemid, parameter ); + DBexecute(sql); + + update_triggers(itemid); + } + + DBfree_result(result); + DBclose(); + +#ifdef HAVE_FUNCTION_SETPROCTITLE + setproctitle("sleeping for 30 sec"); +#endif + sleep(30); + } +} diff --git a/src/zabbix_server/timer/timer.h b/src/zabbix_server/timer/timer.h new file mode 100644 index 00000000..bcd95c1d --- /dev/null +++ b/src/zabbix_server/timer/timer.h @@ -0,0 +1,33 @@ +/* +** 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_TIMER_H +#define ZABBIX_TIMER_H + +/* +extern void signal_handler(int); +extern int server_num; + +extern int CONFIG_TIMEOUT; +extern int CONFIG_SUCKERD_FORKS; +*/ + +int main_timer_loop(); + +#endif |
