Module: check_mk
Branch: master
Commit: 5fe65e00863e43c160e08224b71d7de49eefc29d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5fe65e00863e43…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Wed May 25 12:09:15 2016 +0200
update for WK3532
---
modules/events.py | 26 ++++++++++++++++----------
web/htdocs/wato.py | 46 ++++++++++++++++++++++++++++++++++------------
2 files changed, 50 insertions(+), 22 deletions(-)
diff --git a/modules/events.py b/modules/events.py
index d6a9c13..8d261c9 100644
--- a/modules/events.py
+++ b/modules/events.py
@@ -336,7 +336,7 @@ def event_match_hosttags(rule, context):
def event_match_servicegroups(rule, context, is_regex = False):
if is_regex:
- required_groups = rule.get("match_servicegroups_regex")
+ match_type, required_groups = rule.get("match_servicegroups_regex",
(None, None))
else:
required_groups = rule.get("match_servicegroups")
@@ -361,23 +361,27 @@ def event_match_servicegroups(rule, context, is_regex = False):
if is_regex:
r = regex(group)
for sg in servicegroups:
- # The regex must match the alias name!
- if r.search(define_servicegroups[sg]):
+ match_value = match_type == "match_alias" and
define_servicegroups[sg] or sg
+ if r.search(match_value):
return
elif group in servicegroups:
return
if is_regex:
- return "The service is only in the groups %s. None of these patterns
match: %s" % (
- '"' + '", "'.join(map(lambda x:
define_servicegroups[x], servicegroups)) + '"',
- '"' + '" or "'.join(required_groups)) +
'"'
+ if match_type == "match_alias":
+ return "The service is only in the groups %s. None of these patterns
match: %s" % (
+ '"' + '", "'.join(map(lambda x:
define_servicegroups[x], servicegroups)) + '"',
+ '"' + '" or
"'.join(required_groups)) + '"'
+ else:
+ return "The service is only in the groups %s. None of these patterns
match: %s" % (
+ '"' + '", "'.join(servicegroups) +
'"', '"' + '" or "'.join(required_groups)) +
'"'
else:
return "The service is only in the groups %s, but %s is required" %
(
sgn, " or ".join(required_groups))
def event_match_exclude_servicegroups(rule, context, is_regex = False):
if is_regex:
- excluded_groups = rule.get("match_exclude_servicegroups_regex")
+ match_type, excluded_groups =
rule.get("match_exclude_servicegroups_regex", (None, None))
else:
excluded_groups = rule.get("match_exclude_servicegroups")
@@ -397,10 +401,12 @@ def event_match_exclude_servicegroups(rule, context, is_regex =
False):
if is_regex:
r = regex(group)
for sg in servicegroups:
- # The regex must match the alias name!
- if r.search(define_servicegroups[sg]):
+ match_value = match_type == "match_alias" and
define_servicegroups[sg] or sg
+ match_value_inverse = match_type == "match_alias" and sg or
define_servicegroups[sg]
+
+ if r.search(match_value):
return "The service group \"%s\" (%s) is excluded
per regex pattern: %s" %\
- (define_servicegroups[sg], sg, group)
+ (match_value, match_value_inverse, group)
elif group in servicegroups:
return "The service group %s is excluded" % group
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 92ef291..8ce203a 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7301,21 +7301,43 @@ def generic_rule_match_conditions():
)
),
( "match_servicegroups_regex",
- ListOfStrings(
- title = _("Match Service Groups (regex)"),
- help = _("The service group alias must match one of the following
regular expressions."
- " For host events this condition never matches as soon as at
least one group is selected."),
- valuespec = RegExpUnicode(size = 32),
- orientation = "horizontal",
+ Tuple(
+ title = _("Match Service Groups (regex)"),
+ elements = [
+ DropdownChoice(
+ choices = [
+ ( "match_id", _("Match the internal
identifier")),
+ ( "match_alias", _("Match the alias"))
+ ],
+ default = "match_id"
+ ),
+ ListOfStrings(
+ help = _("The service group alias must match one of the
following regular expressions."
+ " For host events this condition never matches as
soon as at least one group is selected."),
+ valuespec = RegExpUnicode(size = 32),
+ orientation = "horizontal",
+ )
+ ]
)
),
( "match_exclude_servicegroups_regex",
- ListOfStrings(
- title = _("Exclude Service Groups (regex)"),
- help = _("The service group alias must not match one of the following
regular expressions. "
- "For host events this condition is simply ignored."),
- valuespec = RegExpUnicode(size = 32),
- orientation = "horizontal",
+ Tuple(
+ title = _("Exclude Service Groups (regex)"),
+ elements = [
+ DropdownChoice(
+ choices = [
+ ( "match_id", _("Match the internal
identifier")),
+ ( "match_alias", _("Match the alias"))
+ ],
+ default = "match_id"
+ ),
+ ListOfStrings(
+ help = _("The service group alias must not match one of the
following regular expressions. "
+ "For host events this condition is simply
ignored."),
+ valuespec = RegExpUnicode(size = 32),
+ orientation = "horizontal",
+ )
+ ]
)
),
( "match_services",