Module: check_mk
Branch: master
Commit: dc8445afe08d1a35a233f0d1f313f3588fda9dc1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dc8445afe08d1a…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Dec 16 12:37:55 2013 +0100
FIX Parse state of downtime notification log entries correctly
The state information of log messages of notifications that are
triggered by downtimes was not correctly parsed. This has been
fixed.
---
.bugs/952 | 7 +++++--
.werks/335 | 12 ++++++++++++
ChangeLog | 3 +++
livestatus/src/LogEntry.cc | 36 +++++++++++++++++++++++++++---------
4 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/.bugs/952 b/.bugs/952
index 45a0fb5..5db7895 100644
--- a/.bugs/952
+++ b/.bugs/952
@@ -1,9 +1,9 @@
Title: Livestatus: parse DOWNTIMESTOPPED (UP) into correct state UP
Component: livestatus
-State: open
+Class: bug
+State: done
Date: 2013-09-16 11:34:56
Targetversion: 1.4.0
-Class: bug
When parsing lines like:
@@ -12,3 +12,6 @@ When parsing lines like:
Livestatus sets 3 as the state (meaning invalid). It should extract the (UP) however
and set the state 0.
+
+2013-12-16 12:35:09: changed state open -> done
+Fixed. Nagios uses log enries with varying order.
diff --git a/.werks/335 b/.werks/335
new file mode 100644
index 0000000..0a77090
--- /dev/null
+++ b/.werks/335
@@ -0,0 +1,12 @@
+Title: Parse state of downtime notification log entries correctly
+Level: 1
+Component: livestatus
+Class: fix
+State: unknown
+Version: 1.2.5i1
+Date: 1387193798
+Targetversion: future
+
+The state information of log messages of notifications that are
+triggered by downtimes was not correctly parsed. This has been
+fixed.
diff --git a/ChangeLog b/ChangeLog
index 7a17c48..01bca7c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -59,6 +59,9 @@
* 0304 FIX: Escaping several unwanted chars from incoming log messages...
* 0089 FIX: CSV export of event console was broken...
+ Livestatus:
+ * 0335 FIX: Parse state of downtime notification log entries correctly...
+
1.2.3i7:
Core & Setup:
diff --git a/livestatus/src/LogEntry.cc b/livestatus/src/LogEntry.cc
index 86b6482..5d4783b 100644
--- a/livestatus/src/LogEntry.cc
+++ b/livestatus/src/LogEntry.cc
@@ -240,8 +240,12 @@ inline bool LogEntry::handleStatusEntry()
return false;
}
-
-
+// Examples of host notifications. Beware CUSTOM and DOWNTIME notifications
+// have a different column order. This can be considered as a bug. But we
+// need to parse that anyway.
+// HOST NOTIFICATION: omdadmin;localhost;check-mk-notify;DOWNTIMESTOPPED (UP);mk
+// HOST NOTIFICATION: omdadmin;localhost;CUSTOM (UP);check-mk-notify;OK - 127.0.0.1: rta
0.055ms, lost 0%;omdadmin;TEST
+// HOST NOTIFICATION: omdadmin;localhost;DOWN;check-mk-notify;Manually set to Down by
omdadmin
inline bool LogEntry::handleNotificationEntry()
{
if (!strncmp(_text, "HOST NOTIFICATION: ", 19)
@@ -255,17 +259,31 @@ inline bool LogEntry::handleNotificationEntry()
_contact_name = next_token(&scan, ';');
_host_name = next_token(&scan, ';');
- if (svc) {
+ if (svc)
_svc_desc = next_token(&scan, ';');
- _state_type = save_next_token(&scan, ';');
+
+ _state_type = save_next_token(&scan, ';');
+ _command_name = next_token(&scan, ';');
+
+ if (svc)
_state = serviceStateToInt(_state_type);
- }
- else {
- _state_type = save_next_token(&scan, ';');
+ else
_state = hostStateToInt(_state_type);
+
+ // If that state is not parsable then we assume that the order
+ // is swapped
+ if ((svc && _state == 4) ||
+ (!svc && _state == 3))
+ {
+ char *swap = _state_type;
+ _state_type = _command_name;
+ _command_name = swap;
+ if (svc)
+ _state = serviceStateToInt(_state_type);
+ else
+ _state = hostStateToInt(_state_type);
}
- _command_name = next_token(&scan, ';');
_check_output = next_token(&scan, ';');
return true;
}
@@ -370,7 +388,7 @@ inline int LogEntry::serviceStateToInt(char *s)
inline int LogEntry::hostStateToInt(char *s)
{
char *last = s + strlen(s) - 1;
- if (*last == ')')
+ if (*last == ')') // handle CUSTOM (UP) and DOWNTIMESTOPPED (DOWN)
last--;
// UP, DOWN, UNREACHABLE, RECOVERY