Module: check_mk
Branch: master
Commit: 5245b99b018b592b30d8a4ff29b17fbd7c076596
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5245b99b018b59…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Dec 22 16:27:08 2010 +0100
Livestatus: write timeperiod transitions to logfile
---
.bugs/7 | 25 ++++++++++++++++++++++---
ChangeLog | 3 +++
livestatus/src/TimeperiodsCache.cc | 21 +++++++++++++++++++--
livestatus/src/TimeperiodsCache.h | 2 ++
livestatus/src/module.c | 26 ++++++++++++++------------
5 files changed, 60 insertions(+), 17 deletions(-)
diff --git a/.bugs/7 b/.bugs/7
index 030a6bf..8112cfd 100644
--- a/.bugs/7
+++ b/.bugs/7
@@ -1,10 +1,11 @@
Title: Timeperiod-Übergänge ins Nagios-Log schreiben
Component: livestatus
+State: done
+Class: feature
+Date: 2010-12-21 10:56:28
Benefit: 3
-State: open
Cost: 1
-Date: 2010-12-21 10:56:28
-Class: feature
+Fun: 0
Livestatus hält ja ohnehin einen Cache der Timeperiods. Immer
wenn eine umschaltet, sollte ein Logeintrag gemacht werden.
@@ -12,3 +13,21 @@ Auch initial beim Starten des Systems. Anhand dieser Einträge
ist es später viel einfacher, die Verfügbarkeiten zu berechnen.
Das sollte man recht bald programmieren, damit die Leute
schon Gelegenheit haben, Daten zu sammeln.
+
+2010-12-22 16:13:20: changed state open -> done
+Ist erledigt. Jetzt wird immer ein Eintrag
+gemacht. Beim Starten von Nagios:
+
+[1293030598] TIMEPERIOD TRANSITION: 24X7;-1;1
+[1293030598] TIMEPERIOD TRANSITION: 24x7;-1;1
+[1293030598] TIMEPERIOD TRANSITION: hirni10;-1;1
+[1293030598] TIMEPERIOD TRANSITION: hirni11;-1;1
+[1293030598] TIMEPERIOD TRANSITION: hirni9;-1;0
+[1293030598] TIMEPERIOD TRANSITION: none;-1;0
+[1293030598] TIMEPERIOD TRANSITION: workhours;-1;1
+
+Später dann:
+
+[1293030660] TIMEPERIOD TRANSITION: hirni10;1;0
+
+Doku von Livestatus is auch bereits aktualisiert.
diff --git a/ChangeLog b/ChangeLog
index 5715a30..838aecf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -44,6 +44,9 @@
* Allow more than one column for StatsGroupBy:
* Do not use function is_contact_member_of_contactgroup anymore (get compatible
with Nagios CVS)
+ * Livestatus: log timeperiod transitions (active <-> inactive) into Nagios
+ log file. This will enable us to create availability reports more simple
+ in future.
1.1.9i2:
Checks & Agents:
diff --git a/livestatus/src/TimeperiodsCache.cc b/livestatus/src/TimeperiodsCache.cc
index 089c277..ed94aba 100644
--- a/livestatus/src/TimeperiodsCache.cc
+++ b/livestatus/src/TimeperiodsCache.cc
@@ -57,14 +57,24 @@ void TimeperiodsCache::update(time_t now)
}
_cache_time = minutes;
- _cache.clear();
// Loop over all timeperiods and compute if we are
// currently in
timeperiod *tp = timeperiod_list;
while (tp) {
bool is_in = 0 == check_time_against_period(now, tp);
- _cache.insert(std::make_pair(tp, is_in));
+
+ // check previous state and log transition if state has changed
+ _cache_t::iterator it = _cache.find(tp);
+ if (it == _cache.end()) { // first entry
+ logTransition(tp->name, -1, is_in ? 1 : 0);
+ _cache.insert(std::make_pair(tp, is_in));
+ }
+ else if (it->second != is_in) {
+ logTransition(tp->name, it->second ? 1 : 0, is_in ? 1 : 0);
+ it->second = is_in;
+ }
+
tp = tp->next;
}
pthread_mutex_unlock(&_cache_lock);
@@ -87,3 +97,10 @@ bool TimeperiodsCache::inTimeperiod(timeperiod *tp)
return is_in;
}
+
+void TimeperiodsCache::logTransition(char *name, int from, int to)
+{
+ char buffer[64];
+ snprintf(buffer, sizeof(buffer), "TIMEPERIOD TRANSITION: %s;%d;%d", name,
from, to);
+ write_to_all_logs(buffer, LOG_INFO);
+}
diff --git a/livestatus/src/TimeperiodsCache.h b/livestatus/src/TimeperiodsCache.h
index e3d070e..5a3d2a4 100644
--- a/livestatus/src/TimeperiodsCache.h
+++ b/livestatus/src/TimeperiodsCache.h
@@ -40,6 +40,8 @@ public:
~TimeperiodsCache();
void update(time_t now);
bool inTimeperiod(timeperiod *tp);
+private:
+ void logTransition(char *name, int from, int to);
};
#endif // _TimeperiodsCache_h
diff --git a/livestatus/src/module.c b/livestatus/src/module.c
index 87449bc..46c2e81 100644
--- a/livestatus/src/module.c
+++ b/livestatus/src/module.c
@@ -386,54 +386,56 @@ int broker_event(int event_type, void *data)
int broker_process(int event_type, void *data)
{
struct nebstruct_process_struct *ps = (struct nebstruct_process_struct *)data;
- if (ps->type == NEBTYPE_PROCESS_EVENTLOOPSTART)
+ if (ps->type == NEBTYPE_PROCESS_EVENTLOOPSTART) {
+ update_timeperiods_cache(time(0));
start_threads();
+ }
}
int verify_event_broker_options()
{
int errors = 0;
- if(!(event_broker_options & BROKER_PROGRAM_STATE)) {
+ if (!(event_broker_options & BROKER_PROGRAM_STATE)) {
logger( LG_CRIT, "need BROKER_PROGRAM_STATE (%i) event_broker_option enabled
to work.", BROKER_PROGRAM_STATE );
errors++;
}
- if(!(event_broker_options & BROKER_TIMED_EVENTS)) {
+ if (!(event_broker_options & BROKER_TIMED_EVENTS)) {
logger( LG_CRIT, "need BROKER_TIMED_EVENTS (%i) event_broker_option enabled
to work.", BROKER_TIMED_EVENTS );
errors++;
}
- if(!(event_broker_options & BROKER_SERVICE_CHECKS)) {
+ if (!(event_broker_options & BROKER_SERVICE_CHECKS)) {
logger( LG_CRIT, "need BROKER_SERVICE_CHECKS (%i) event_broker_option
enabled to work.", BROKER_SERVICE_CHECKS );
errors++;
}
- if(!(event_broker_options & BROKER_HOST_CHECKS)) {
+ if (!(event_broker_options & BROKER_HOST_CHECKS)) {
logger( LG_CRIT, "need BROKER_HOST_CHECKS (%i) event_broker_option enabled
to work.", BROKER_HOST_CHECKS );
errors++;
}
- if(!(event_broker_options & BROKER_LOGGED_DATA)) {
+ if (!(event_broker_options & BROKER_LOGGED_DATA)) {
logger( LG_CRIT, "need BROKER_LOGGED_DATA (%i) event_broker_option enabled
to work.", BROKER_LOGGED_DATA );
errors++;
}
- if(!(event_broker_options & BROKER_COMMENT_DATA)) {
+ if (!(event_broker_options & BROKER_COMMENT_DATA)) {
logger( LG_CRIT, "need BROKER_COMMENT_DATA (%i) event_broker_option enabled
to work.", BROKER_COMMENT_DATA );
errors++;
}
- if(!(event_broker_options & BROKER_DOWNTIME_DATA)) {
+ if (!(event_broker_options & BROKER_DOWNTIME_DATA)) {
logger( LG_CRIT, "need BROKER_DOWNTIME_DATA (%i) event_broker_option enabled
to work.", BROKER_DOWNTIME_DATA );
errors++;
}
- if(!(event_broker_options & BROKER_STATUS_DATA)) {
+ if (!(event_broker_options & BROKER_STATUS_DATA)) {
logger( LG_CRIT, "need BROKER_STATUS_DATA (%i) event_broker_option enabled
to work.", BROKER_STATUS_DATA );
errors++;
}
- if(!(event_broker_options & BROKER_ADAPTIVE_DATA)) {
+ if (!(event_broker_options & BROKER_ADAPTIVE_DATA)) {
logger( LG_CRIT, "need BROKER_ADAPTIVE_DATA (%i) event_broker_option enabled
to work.", BROKER_ADAPTIVE_DATA );
errors++;
}
- if(!(event_broker_options & BROKER_EXTERNALCOMMAND_DATA)) {
+ if (!(event_broker_options & BROKER_EXTERNALCOMMAND_DATA)) {
logger( LG_CRIT, "need BROKER_EXTERNALCOMMAND_DATA (%i) event_broker_option
enabled to work.", BROKER_EXTERNALCOMMAND_DATA );
errors++;
}
- if(!(event_broker_options & BROKER_STATECHANGE_DATA)) {
+ if (!(event_broker_options & BROKER_STATECHANGE_DATA)) {
logger( LG_CRIT, "need BROKER_STATECHANGE_DATA (%i) event_broker_option
enabled to work.", BROKER_STATECHANGE_DATA );
errors++;
}