Module: check_mk
Branch: master
Commit: 5ef07d14765e49d527b2c212ed6438aff8492553
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5ef07d14765e49…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Oct 18 17:21:05 2012 +0200
FIX: rule simulator ("Try out") now handles cancelling rules correctly
---
ChangeLog | 1 +
mkeventd/web/htdocs/mkeventd.py | 17 ++++++++++++++++-
mkeventd/web/plugins/wato/mkeventd.py | 12 ++++++++----
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d3b1a3c..ce284ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,7 @@
* New button for resetting all rule hits counters
* When saving a rule then its hits counter is always reset
* New feature of hiding certain actions from the commands in the status GUI
+ * FIX: rule simulator ("Try out") now handles cancelling rules correctly
Multisite:
* Enable automation login with _username= and _secret=, while
diff --git a/mkeventd/web/htdocs/mkeventd.py b/mkeventd/web/htdocs/mkeventd.py
index 6994caa..a5c165b 100644
--- a/mkeventd/web/htdocs/mkeventd.py
+++ b/mkeventd/web/htdocs/mkeventd.py
@@ -142,6 +142,21 @@ def event_rule_matches(rule, event):
if "match_facility" in rule and event["facility"] !=
rule["match_facility"]:
return _("The syslog facility does not match")
+
+ # First try cancelling rules
+ if "match_ok" in rule or "cancel_priority" in rule:
+ if "cancel_priority" in rule:
+ up, lo = rule["cancel_priority"]
+ cp = event["priority"] >= lo and event["priority"]
<= up
+ else:
+ cp = True
+
+ match_groups = match(rule.get("match_ok", ""),
event["text"], complete = False)
+ if match_groups != False and cp:
+ if match_groups == True:
+ match_groups = ()
+ return True, match_groups
+
try:
match_groups = match(rule.get("match"), event["text"],
complete = False)
except Exception, e:
@@ -159,7 +174,7 @@ def event_rule_matches(rule, event):
if match_groups == True:
match_groups = () # no matching groups
- return match_groups
+ return False, match_groups
def match(pattern, text, complete = True):
if pattern == None:
diff --git a/mkeventd/web/plugins/wato/mkeventd.py
b/mkeventd/web/plugins/wato/mkeventd.py
index 0ba0fa1..073f1a9 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -822,15 +822,19 @@ def mode_mkeventd_rules(phase):
if rule.get("disabled"):
html.icon(_("This rule is currently disabled and will not be
applied"), "disabled")
elif event:
- groups = mkeventd.event_rule_matches(rule, event)
- if type(groups) != tuple:
- html.icon(_("Rule does not match: %s") % groups,
"rulenmatch")
+ result = mkeventd.event_rule_matches(rule, event)
+ if type(result) != tuple:
+ html.icon(_("Rule does not match: %s") % result,
"rulenmatch")
else:
+ cancelling, groups = result
if have_match:
msg = _("This rule matches, but is overruled by a previous
match.")
icon = "rulepmatch"
else:
- msg = _("This rule matches.")
+ if cancelling:
+ msg = _("This rule does a cancelling match.")
+ else:
+ msg = _("This rule matches.")
icon = "rulematch"
have_match = True
if groups: