Module: check_mk
Branch: master
Commit: 3821ae6d250e93dd2fe33b511d44503211bd291b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3821ae6d250e93…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Dec 8 22:22:41 2014 +0100
#1719 Allow to allow both host name and IP address when checking for events in Event
Console
The check <i>Check for events in Event Console</i> used to allow either a
match for the host name or the IP address when trying to find events that
belong to a monitored host. Now there is a new third option <i>Try both
host name and IP address</i> that will try to match the host name and the
IP address at the same time and will match the event if one of both matches
succeeds. This helps in situations where the Event Console sometimes just
gets the IP address of the remote host correctly, but has no host name.
---
.werks/1719 | 15 ++++++++++++
ChangeLog | 1 +
mkeventd/lib/check_mkevents.cc | 41 +++++++++++++++++++++++++++------
mkeventd/web/plugins/wato/mkeventd.py | 8 ++++---
4 files changed, 55 insertions(+), 10 deletions(-)
diff --git a/.werks/1719 b/.werks/1719
new file mode 100644
index 0000000..a5d2b48
--- /dev/null
+++ b/.werks/1719
@@ -0,0 +1,15 @@
+Title: Allow to allow both host name and IP address when checking for events in Event
Console
+Level: 2
+Component: ec
+Compatible: compat
+Version: 1.2.5i7
+Date: 1418073600
+Class: feature
+
+The check <i>Check for events in Event Console</i> used to allow either a
+match for the host name or the IP address when trying to find events that
+belong to a monitored host. Now there is a new third option <i>Try both
+host name and IP address</i> that will try to match the host name and the
+IP address at the same time and will match the event if one of both matches
+succeeds. This helps in situations where the Event Console sometimes just
+gets the IP address of the remote host correctly, but has no host name.
diff --git a/ChangeLog b/ChangeLog
index 59e40f5..5ac7b22 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -253,6 +253,7 @@
Event Console:
* 1169 Added host state type filter to "recent event history" view
* 1718 Show groups of regex match of events in details views of Event Console
+ * 1719 Allow to allow both host name and IP address when checking for events in Event
Console...
* 1531 FIX: Fixed exception in event history view when displaying CHANGESTATE events
* 1610 FIX: Hostname translation now also works for incoming SNMP traps
* 1643 FIX: Improved error handling of exceptions when processing log lines
diff --git a/mkeventd/lib/check_mkevents.cc b/mkeventd/lib/check_mkevents.cc
index 4d54be5..c9bcfeb 100644
--- a/mkeventd/lib/check_mkevents.cc
+++ b/mkeventd/lib/check_mkevents.cc
@@ -47,6 +47,26 @@ void usage()
{
printf("Usage: check_mkevents [-s SOCKETPATH] [-H REMOTE:PORT] [-a] HOST
[APPLICATION]");
printf("\n -a do not take into account acknowledged events.\n");
+ printf(" HOST may be a hostname, and IP address or
hostname/IP-address.\n");
+}
+
+
+string prepare_hostname_regex(const char *s)
+{
+ const char *scan = s;
+ string result = "";
+ while (*scan) {
+ if (strchr("[](){}^$.*+?|\\", *scan)) {
+ result += "\\";
+ result += *scan;
+ }
+ else if (*scan == '/')
+ result += "|";
+ else
+ result += *scan;
+ scan ++;
+ }
+ return result;
}
@@ -174,15 +194,22 @@ int main(int argc, char** argv)
// Create query message
string query_message;
- query_message.append("GET events\nFilter: event_host =~ ");
- query_message.append(host);
- query_message.append("\nFilter: event_phase in open ack\n");
- query_message.append("OutputFormat: plain\n");
+ query_message += "GET events\nFilter: event_host ";
+ if (strchr(host, '/')) {
+ query_message += "~~ ";
+ query_message += prepare_hostname_regex(host);
+ }
+ else {
+ query_message += "=~ ";
+ query_message += host;
+ }
+ query_message += "\nFilter: event_phase in open ack\n";
+ query_message += "OutputFormat: plain\n";
if (application) {
- query_message.append("Filter: event_application ~~ ");
- query_message.append(application);
- query_message.append("\n");
+ query_message += "Filter: event_application ~~ ";
+ query_message += application;
+ query_message += "\n";
}
// Send message
diff --git a/mkeventd/web/plugins/wato/mkeventd.py
b/mkeventd/web/plugins/wato/mkeventd.py
index 298146f..bbd54ab 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -1947,11 +1947,13 @@ register_rule(
"host. This is needed in cases where the event source (syslog,
snmptrapd) "
"do not send a host name that matches the monitoring host
name."),
choices = [
- ( '$HOSTNAME$', _("Monitoring Host name") ),
- ( '$HOSTADDRESS$', _("Host IP Address" ) ) ],
+ ( '$HOSTNAME$', _("Monitoring host
name") ),
+ ( '$HOSTADDRESS$', _("Host IP address" )
),
+ ( '$HOSTNAME$/$HOSTADDRESS$', _("Try both host name and
IP address" ) ),
+ ],
otherlabel = _("Specify explicitly"),
explicit = TextAscii(allow_empty = False, attrencode = True),
- default_value = '$HOSTNAME$',
+ default_value = '$HOSTNAME$/$HOSTADDRESS$',
)
),
( "item",