Module: check_mk
Branch: master
Commit: b31b62341f37f6ac0ae6819ed6a6dbce1b6d2d9a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b31b62341f37f6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Apr 21 17:41:30 2016 +0200
3390 Events can now be cancelled by the syslog application
Event Console rules can now close the events they created by having
a specific syslog application in messages.
If the application of the message matches this regular expression
(case insensitive) and either no text to cancel is specified or
that text also matched, then events created by this rule will
automatically be cancelled (if host, facility and match groups match).
---
.werks/3390 | 15 +++++++++++++++
ChangeLog | 1 +
bin/mkeventd | 34 ++++++++++++++++++++++------------
web/plugins/wato/mkeventd.py | 15 ++++++++++++---
4 files changed, 50 insertions(+), 15 deletions(-)
diff --git a/.werks/3390 b/.werks/3390
new file mode 100644
index 0000000..56c44ca
--- /dev/null
+++ b/.werks/3390
@@ -0,0 +1,15 @@
+Title: Events can now be cancelled by the syslog application
+Level: 1
+Component: ec
+Compatible: compat
+Version: 1.2.9i1
+Date: 1461253178
+Class: feature
+
+Event Console rules can now close the events they created by having
+a specific syslog application in messages.
+
+If the application of the message matches this regular expression
+(case insensitive) and either no text to cancel is specified or
+that text also matched, then events created by this rule will
+automatically be cancelled (if host, facility and match groups match).
diff --git a/ChangeLog b/ChangeLog
index b3ef07c..b83ba63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -325,6 +325,7 @@
* 2999 The contact name is now included in Event Console notifications...
* 3262 Event Console: bulk delete button for custom MIBs now available
* 3388 Event Console can now process SNMPv3 traps...
+ * 3390 Events can now be cancelled by the syslog application...
* 3058 FIX: Event Console is now allowing non loadable MIB modules on startup...
* 3097 FIX: mkeventd: fixed crash with non-descriptive error message if mibs
couldn't be loaded
* 3335 FIX: Improved error handling when requested rule pack does not exist
diff --git a/bin/mkeventd b/bin/mkeventd
index e68dc12..2aeb09d 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -1892,7 +1892,8 @@ class EventServer:
self.hash_rule(rule)
if "match_facility" not in rule \
and "match_priority" not in rule \
- and "cancel_priority" not in rule:
+ and "cancel_priority" not in rule \
+ and "cancel_application" not in rule:
count_unspecific += 1
@@ -2138,15 +2139,22 @@ class EventServer:
log(" did not match, because timeperiod %s is not active" %
rule["match_timeperiod"])
return False
- if "match_ok" in rule or "cancel_priority" in rule:
+ if "match_ok" in rule or "cancel_priority" in rule or
"cancel_application" in rule:
if "cancel_priority" in rule:
up, lo = rule["cancel_priority"]
cp = event["priority"] >= lo and event["priority"]
<= up
else:
cp = True
+ if "cancel_application" in rule:
+ cancel_by_application = match(rule.get("cancel_application"),
+ event["application"],
+ complete=False)
+ else:
+ cancel_by_application = True
+
match_groups = match(rule.get("match_ok", ""),
event["text"], complete = False)
- if match_groups != False and cp:
+ if match_groups != False and cp and cancel_by_application:
if debug:
log(" found cancelling event")
if match_groups == True:
@@ -3194,15 +3202,17 @@ class EventStatus():
(event["id"], event["host"], host))
return False
- # The same for the application
- application = new_event["application"]
- if "set_application" in rule:
- application = replace_groups(rule["set_application"], application,
match_groups)
- if event["application"] != application:
- if debug:
- log("Do not cancel event %d: application is not the same (%s !=
%s)" %
- (event["id"], event["application"],
application))
- return False
+ # The same for the application. But in case there is cancelling based on the
application
+ # configured in the rule, then don't check for tidfferent applications.
+ if "cancel_application" not in rule:
+ application = new_event["application"]
+ if "set_application" in rule:
+ application = replace_groups(rule["set_application"],
application, match_groups)
+ if event["application"] != application:
+ if debug:
+ log("Do not cancel event %d: application is not the same (%s !=
%s)" %
+ (event["id"], event["application"],
application))
+ return False
if event["facility"] != new_event["facility"]:
if debug:
diff --git a/web/plugins/wato/mkeventd.py b/web/plugins/wato/mkeventd.py
index fd1fa8f..41df8d3 100644
--- a/web/plugins/wato/mkeventd.py
+++ b/web/plugins/wato/mkeventd.py
@@ -651,7 +651,7 @@ vs_mkeventd_rule = Dictionary(
title = _("Syslog priority to cancel event"),
help = _("If the priority of the event lies withing this range and
either no text to cancel "
"is specified or that text also matched, then events created
with this rule will "
- "automatically be cancelled (if host, application and match
groups match)."),
+ "automatically be cancelled (if host, application, facility
and match groups match)."),
orientation = "horizontal",
show_titles = False,
elements = [
@@ -660,6 +660,15 @@ vs_mkeventd_rule = Dictionary(
],
),
),
+ ( "cancel_application",
+ RegExpUnicode(
+ title = _("Syslog application to cancel event"),
+ help = _("If the application of the message matches this regular
expression "
+ "(case insensitive) and either no text to cancel is specified
or "
+ "that text also matched, then events created by this rule
will "
+ "automatically be cancelled (if host, facility and match
groups match)."),
+ ),
+ ),
( "invert_matching",
Checkbox(
title = _("Invert matching"),
@@ -743,11 +752,11 @@ vs_mkeventd_rule = Dictionary(
optional_keys = [ "delay", "livetime", "count",
"expect", "match_priority", "match_priority",
"match_facility", "match_sl",
"match_host", "match_ipaddress", "match_application",
"match_timeperiod",
"set_text", "set_host",
"set_application", "set_comment",
- "set_contact", "cancel_priority",
"match_ok", "contact_groups", ],
+ "set_contact", "cancel_priority",
"cancel_application", "match_ok", "contact_groups", ],
headers = [
( _("Rule Properties"), [ "id", "description",
"comment", "docu_url", "disabled" ] ),
( _("Matching Criteria"), [ "match", "match_host",
"match_ipaddress", "match_application", "match_priority",
"match_facility",
- "match_sl", "match_ok",
"cancel_priority", "match_timeperiod", "invert_matching"
]),
+ "match_sl", "match_ok",
"cancel_priority", "cancel_application", "match_timeperiod",
"invert_matching" ]),
( _("Outcome & Action"), [ "state", "sl",
"contact_groups", "actions", "cancel_actions",
"cancel_action_phases", "drop", "autodelete" ]),
( _("Counting & Timing"), [ "count", "expect",
"delay", "livetime", ]),
( _("Rewriting"), [ "set_text", "set_host",
"set_application", "set_comment", "set_contact" ]),