Module: check_mk
Branch: master
Commit: d21c5573c5ac4a7ceab6a4426ade551bd761b2a3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d21c5573c5ac4a…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Wed Sep 23 10:42:50 2015 +0200
#2430 FIX Fixed crash with availability queries when using nagios as core
The nagios core crashed when a query on the statehist table did return zero entries.
This happened when a timewindow was queried where the hosts/services in question did not
exist.
---
.werks/2430 | 11 +++++++++++
ChangeLog | 1 +
livestatus/src/TableStateHistory.cc | 21 ++++++++++++---------
3 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/.werks/2430 b/.werks/2430
new file mode 100644
index 0000000..e4d46bd
--- /dev/null
+++ b/.werks/2430
@@ -0,0 +1,11 @@
+Title: Fixed crash with availability queries when using nagios as core
+Level: 2
+Component: core
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i3
+Date: 1442997503
+
+The nagios core crashed when a query on the statehist table did return zero entries.
+This happened when a timewindow was queried where the hosts/services in question did not
exist.
diff --git a/ChangeLog b/ChangeLog
index d64011b..9e72585 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
* 2540 FIX: Process piggy backed data even if host is set to "No Agent"...
* 2543 FIX: Fixed usage of icons/actions configured directly with process rules
* 2630 FIX: fixed incorrect check interval of Check_MK Discovery...
+ * 2430 FIX: Fixed crash with availability queries when using nagios as core...
Checks & Agents:
* 2312 New checks for EMC VPLEX: emc_vplex_cpu, emc_vplex_director_stats,
emc_vplex_if, emc_vplex_volumes...
diff --git a/livestatus/src/TableStateHistory.cc b/livestatus/src/TableStateHistory.cc
index df39ab4..02887c9 100644
--- a/livestatus/src/TableStateHistory.cc
+++ b/livestatus/src/TableStateHistory.cc
@@ -186,7 +186,7 @@ void TableStateHistory::addColumns(Table *table)
LogEntry *TableStateHistory::getPreviousLogentry()
{
- if (_it_entries == _entries->begin()) {
+ while (_it_entries == _entries->begin()) {
// open previous logfile
if (_it_logs == g_store->logCache()->logfiles()->begin())
return 0;
@@ -196,25 +196,28 @@ LogEntry *TableStateHistory::getPreviousLogentry()
_it_entries = _entries->end();
}
}
+
return (--_it_entries)->second;
}
LogEntry *TableStateHistory::getNextLogentry()
{
- if (++_it_entries == _entries->end()) {
- if (++_it_logs == g_store->logCache()->logfiles()->end()) {
- // No further logfiles available
- // prevent errors on subsequent getNextLogentry()
- --_it_entries;
- --_it_logs;
+ if (_it_entries != _entries->end())
+ ++_it_entries;
+
+ while (_it_entries == _entries->end()) {
+ _logfiles_t::iterator _it_logs_cpy = _it_logs;
+ if (++_it_logs_cpy == g_store->logCache()->logfiles()->end()) {
return 0;
}
else {
+ ++_it_logs;
_entries = _it_logs->second->getEntriesFromQuery(_query,
g_store->logCache(), _since, _until, CLASSMASK_STATEHIST);
_it_entries = _entries->begin();
}
}
return _it_entries->second;
+
}
void TableStateHistory::answerQuery(Query *query)
@@ -306,10 +309,11 @@ void TableStateHistory::answerQuery(Query *query)
return;
}
+
// Determine initial logentry
LogEntry* entry;
_entries = _it_logs->second->getEntriesFromQuery(query, g_store->logCache(),
_since, _until, CLASSMASK_STATEHIST);
- if (_it_logs != newest_log) {
+ if (_entries->size() > 0 &&_it_logs != newest_log) {
_it_entries = _entries->end();
// Check last entry. If it's younger than _since -> use this logfile too
if (--_it_entries != _entries->begin()) {
@@ -321,7 +325,6 @@ void TableStateHistory::answerQuery(Query *query)
} else
_it_entries = _entries->begin();
-
// From now on use getPreviousLogentry() / getNextLogentry()
HostServiceKey key;
bool only_update = true;