Module: check_mk
Branch: master
Commit: 292dcad0cadbeb08b8f89348d617571deaf52d32
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=292dcad0cadbeb…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Oct 9 12:56:57 2012 +0200
livestatus: improved handling of log_initial_states
---
livestatus/src/LogEntry.cc | 4 +++
livestatus/src/LogEntry.h | 3 +-
livestatus/src/TableLog.cc | 13 ----------
livestatus/src/TableStateHistory.cc | 46 ++++++++++++++--------------------
livestatus/src/module.c | 8 +++++-
5 files changed, 32 insertions(+), 42 deletions(-)
diff --git a/livestatus/src/LogEntry.cc b/livestatus/src/LogEntry.cc
index db538c6..d554b9c 100644
--- a/livestatus/src/LogEntry.cc
+++ b/livestatus/src/LogEntry.cc
@@ -300,6 +300,10 @@ bool LogEntry::handleProgrammEntry()
{
_logclass = LOGCLASS_PROGRAM;
return true;
+ }else if (strstr(_text, "logging intitial states")){
+ _logclass = LOGCLASS_PROGRAM;
+ _type = LOG_INITIAL_STATES;
+ return true;
}
return false;
}
diff --git a/livestatus/src/LogEntry.h b/livestatus/src/LogEntry.h
index 274b8d2..8229224 100644
--- a/livestatus/src/LogEntry.h
+++ b/livestatus/src/LogEntry.h
@@ -48,7 +48,8 @@ enum LogEntryType { NONE,
FLAPPING_SERVICE,
TIMEPERIOD_TRANSITION,
NAGIOS_STARTING,
- LOG_VERSION
+ LOG_VERSION,
+ LOG_INITIAL_STATES,
};
struct LogEntry
diff --git a/livestatus/src/TableLog.cc b/livestatus/src/TableLog.cc
index 883cb59..36e5443 100644
--- a/livestatus/src/TableLog.cc
+++ b/livestatus/src/TableLog.cc
@@ -56,19 +56,6 @@ TableLog::TableLog()
addColumns(this, "", -1);
}
-// Debugging logging is hard if debug messages are logged themselves...
-void debug_log(const char *loginfo, ...)
-{
- FILE *x = fopen("/tmp/livestatus_log.log", "a+");
- va_list ap;
- va_start(ap, loginfo);
- vfprintf(x, loginfo, ap);
- fputc('\n', x);
- va_end(ap);
- fclose(x);
-}
-
-
void TableLog::addColumns(Table *table, string prefix, int indirect_offset, bool
add_host, bool add_services)
{
LogEntry *ref = 0;
diff --git a/livestatus/src/TableStateHistory.cc b/livestatus/src/TableStateHistory.cc
index e9e8ac7..8428a0b 100644
--- a/livestatus/src/TableStateHistory.cc
+++ b/livestatus/src/TableStateHistory.cc
@@ -44,18 +44,14 @@
#define CHECK_MEM_CYCLE 1000 /* Check memory every N'th new message */
-extern int g_debug_level;
extern Store *g_store;
-extern int log_initial_states;
#define CLASSMASK_STATEHIST 70
// Debugging logging is hard if debug messages are logged themselves...
void debug_statehist(const char *loginfo, ...)
{
- if (g_debug_level < 2)
- return;
-
+ return;
FILE *x = fopen("/tmp/livestatus_state.log", "a+");
va_list ap;
va_start(ap, loginfo);
@@ -365,22 +361,19 @@ void TableStateHistory::answerQuery(Query *query)
}
break;
}
- case NAGIOS_STARTING:
+ case LOG_INITIAL_STATES:
{
// This feature is only available if log_initial_states is set to 1
// If log_initial_states is set, each nagios startup logs the initial states of all
known
// hosts and services. Therefore we can detect if a host is no longer available after
// a nagios startup. If it still exists an INITIAL HOST/SERVICE state entry will
follow up shortly.
// If it reappaers again after multiple nagios restarts an unmonitored state entry is
generated
- if (log_initial_states)
- {
- state_info_t::iterator it_hst = state_info.begin();
- while (it_hst != state_info.end()) {
- if (it_hst->second->_no_longer_exists == 0)
- it_hst->second->_last_known_time = entry->_time;
- it_hst->second->_no_longer_exists++;
- it_hst++;
- }
+ state_info_t::iterator it_hst = state_info.begin();
+ while (it_hst != state_info.end()) {
+ if (it_hst->second->_no_longer_exists == 0)
+ it_hst->second->_last_known_time = entry->_time;
+ it_hst->second->_no_longer_exists++;
+ it_hst++;
}
break;
}
@@ -395,18 +388,17 @@ void TableStateHistory::answerQuery(Query *query)
//hst->_debug_info = "LOG FINAL";
// No trace since the last two nagios startup -> host/service has vanished
- if (log_initial_states)
- if (hst->_no_longer_exists > 1) {
- // Log last known state up to nagios restart
- hst->_time = hst->_last_known_time;
- hst->_until = hst->_last_known_time;
- process(query, hst);
-
- // Log absent state
- hst->_state = -1;
- hst->_until = hst->_time;
- hst->_debug_info = "UNMONITORED";
- }
+ if (hst->_no_longer_exists > 1) {
+ // Log last known state up to nagios restart
+ hst->_time = hst->_last_known_time;
+ hst->_until = hst->_last_known_time;
+ process(query, hst);
+
+ // Log absent state
+ hst->_state = -1;
+ hst->_until = hst->_time;
+ hst->_debug_info = "UNMONITORED";
+ }
hst->_time = _until - 1;
hst->_until = hst->_time;
diff --git a/livestatus/src/module.c b/livestatus/src/module.c
index 2d60382..8bef4f3 100644
--- a/livestatus/src/module.c
+++ b/livestatus/src/module.c
@@ -102,6 +102,8 @@ int g_data_encoding = ENCODING_UTF8;
extern struct host *host_list;
extern struct service *service_list;
extern scheduled_downtime *scheduled_downtime_list;
+extern int log_initial_states;
+
int g_num_hosts;
int g_num_services;
@@ -466,6 +468,7 @@ void livestatus_log_initial_states(){
// Log DOWNTIME hosts
host *h = (host *)host_list;
char buffer[8192];
+
while (h) {
if (h->scheduled_downtime_depth > 0) {
sprintf(buffer,"HOST DOWNTIME ALERT: %s;STARTED;%s", h->name,
get_downtime_comment(h->name, NULL));
@@ -496,7 +499,10 @@ int broker_event(int event_type __attribute__ ((__unused__)), void
*data)
if( ts->event_type == EVENT_LOG_ROTATION){
if( g_thread_running == 1 ){
livestatus_log_initial_states();
- }
+ } else {
+ if ( log_initial_states == 1 )
+ write_to_all_logs("logging intitial states", LG_INFO);
+ }
}
update_timeperiods_cache(ts->timestamp.tv_sec);