Module: check_mk
Branch: master
Commit: d16580c6600da2215f45e31473cfde0f0ec9f6e0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d16580c6600da2…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Mon Mar 31 13:55:36 2014 +0200
FIX table statehist: now able to cancel a running query if limit is reached
The livestatus table statehist was unable to end a query when
the <tt>Timelimit:</tt> or <tt>Limit:</tt> options were reached.
---
.werks/742 | 11 +++++++
ChangeLog | 3 ++
livestatus/src/TableStateHistory.cc | 55 ++++++++++++++++++++---------------
livestatus/src/TableStateHistory.h | 1 +
4 files changed, 47 insertions(+), 23 deletions(-)
diff --git a/.werks/742 b/.werks/742
new file mode 100644
index 0000000..1f1b183
--- /dev/null
+++ b/.werks/742
@@ -0,0 +1,11 @@
+Title: table statehist: now able to cancel a running query if limit is reached
+Level: 1
+Component: livestatus
+Class: fix
+State: unknown
+Version: 1.2.5i2
+Date: 1396266716
+
+The livestatus table statehist was unable to end a query when
+the <tt>Timelimit:</tt> or <tt>Limit:</tt> options were reached.
+
diff --git a/ChangeLog b/ChangeLog
index 6707853..9305a36 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,9 @@
BI:
* 0741 FIX: BI editor: fixed display bug in "Create nodes based on a service
search"...
+ Livestatus:
+ * 0742 FIX: table statehist: now able to cancel a running query if limit is
reached...
+
1.2.5i1:
Core & Setup:
diff --git a/livestatus/src/TableStateHistory.cc b/livestatus/src/TableStateHistory.cc
index ee1f8c6..9705336 100644
--- a/livestatus/src/TableStateHistory.cc
+++ b/livestatus/src/TableStateHistory.cc
@@ -317,6 +317,9 @@ void TableStateHistory::answerQuery(Query *query)
g_store->logCache()->lockLogCache();
g_store->logCache()->logCachePreChecks();
+ // This flag might be set to true by the return value of processDataset(...)
+ _abort_query = false;
+
// Keep track of the historic state of services/hosts here
typedef map<HostServiceKey, HostServiceState*> state_info_t;
state_info_t state_info;
@@ -389,6 +392,9 @@ void TableStateHistory::answerQuery(Query *query)
while (0 != (entry = getNextLogentry()))
{
+ if (_abort_query)
+ break;
+
if (entry->_time >= _until) {
getPreviousLogentry();
break;
@@ -637,31 +643,33 @@ void TableStateHistory::answerQuery(Query *query)
// Create final reports
state_info_t::iterator it_hst = state_info.begin();
- while (it_hst != state_info.end())
- {
- HostServiceState* hst = it_hst->second;
-
- // No trace since the last two nagios startup -> host/service has vanished
- if (hst->_may_no_longer_exist) {
- // Log last known state up to nagios restart
- hst->_time = hst->_last_known_time;
- hst->_until = hst->_last_known_time;
- process(query, hst);
+ if (!_abort_query) {
+ while (it_hst != state_info.end())
+ {
+ HostServiceState* hst = it_hst->second;
+
+ // No trace since the last two nagios startup -> host/service has
vanished
+ if (hst->_may_no_longer_exist) {
+ // Log last known state up to nagios restart
+ hst->_time = hst->_last_known_time;
+ hst->_until = hst->_last_known_time;
+ process(query, hst);
+
+ // Set absent state
+ hst->_state = -1;
+ hst->_until = hst->_time;
+ hst->_debug_info = "UNMONITORED";
+ if (hst->_log_output)
+ free(hst->_log_output);
+ hst->_log_output = 0;
+ }
- // Set absent state
- hst->_state = -1;
+ hst->_time = _until - 1;
hst->_until = hst->_time;
- hst->_debug_info = "UNMONITORED";
- if (hst->_log_output)
- free(hst->_log_output);
- hst->_log_output = 0;
- }
- hst->_time = _until - 1;
- hst->_until = hst->_time;
-
- process(query, hst);
- it_hst++;
+ process(query, hst);
+ it_hst++;
+ }
}
// Cleanup !
@@ -889,7 +897,8 @@ inline void TableStateHistory::process(Query *query, HostServiceState
*hs_state)
}
// if (hs_state->_duration > 0)
- query->processDataset(hs_state);
+ _abort_query = !query->processDataset(hs_state);
+
hs_state->_from = hs_state->_until;
};
diff --git a/livestatus/src/TableStateHistory.h b/livestatus/src/TableStateHistory.h
index 465e0c1..99423d1 100644
--- a/livestatus/src/TableStateHistory.h
+++ b/livestatus/src/TableStateHistory.h
@@ -43,6 +43,7 @@ class TableStateHistory : public Table
Query *_query;
int _since;
int _until;
+ bool _abort_query;
// Notification periods information, name: active(1)/inactive(0)
typedef map<string, int> _notification_periods_t;