Module: check_mk
Branch: master
Commit: cdc0a13ee70358e6c0b36620d2b2ebb56f274871
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cdc0a13ee70358…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Oct 7 14:03:32 2014 +0200
#1123 Rule based notifications: New condition "Match Service Groups"
---
.werks/1123 | 9 +++++++++
ChangeLog | 1 +
check_mk_templates.cfg | 1 +
modules/notify.py | 26 +++++++++++++++++++++++++-
web/htdocs/wato.py | 21 ++++++++++++++-------
5 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/.werks/1123 b/.werks/1123
new file mode 100644
index 0000000..c856d9d
--- /dev/null
+++ b/.werks/1123
@@ -0,0 +1,9 @@
+Title: Rule based notifications: New condition "Match Service Groups"
+Level: 1
+Component: notifications
+Compatible: compat
+Version: 1.2.5i6
+Date: 1412683344
+Class: feature
+
+
diff --git a/ChangeLog b/ChangeLog
index 6ef12ef..554de9d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -141,6 +141,7 @@
* 1151 Add variables (HOST/SERVICE)ACK(AUTHOR/COMMENT) to notification context...
* 1394 HTML notifications have a new content field for debugging variables...
* 1400 Added example notification script for Pushover to
doc/treasures/notifications...
+ * 1123 Rule based notifications: New condition "Match Service Groups"
* 1156 FIX: Graphs in HTML mails are now sent again where they where missing...
* 1157 FIX: Fixed SMS plugin on at least debian (distrs which have no
sendsms/smssend)...
* 1407 FIX: Fix exception in rule based notification on non-Ascii characters in log
message
diff --git a/check_mk_templates.cfg b/check_mk_templates.cfg
index 7cef53f..47bc763 100644
--- a/check_mk_templates.cfg
+++ b/check_mk_templates.cfg
@@ -397,6 +397,7 @@ define command {
NOTIFY_NOTIFICATIONAUTHORALIAS='$NOTIFICATIONAUTHORALIAS$' \
NOTIFY_SERVICEACKAUTHOR='$SERVICEACKAUTHOR$' \
NOTIFY_SERVICEACKCOMMENT='$SERVICEACKCOMMENT$' \
+ NOTIFY_SERVICEGROUPNAMES='$SERVICEGROUPNAMES$' \
NOTIFY_HOSTACKAUTHOR='$HOSTACKAUTHOR$' \
NOTIFY_HOSTACKCOMMENT='$HOSTACKCOMMENT$' \
NOTIFY_HOSTGROUPNAMES='$HOSTGROUPNAMES$' \
diff --git a/modules/notify.py b/modules/notify.py
index 57b90d9..276b11a 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -626,6 +626,7 @@ def rbn_match_rule(rule, context):
rbn_match_folder(rule, context) or \
rbn_match_hosttags(rule, context) or \
rbn_match_hostgroups(rule, context) or \
+ rbn_match_servicegroups(rule, context) or \
rbn_match_hosts(rule, context) or \
rbn_match_exclude_hosts(rule, context) or \
rbn_match_services(rule, context) or \
@@ -672,6 +673,29 @@ def rbn_match_hosttags(rule, context):
"|".join(tags), "|".join(required))
+def rbn_match_servicegroups(rule, context):
+ if context["WHAT"] != "SERVICE":
+ return
+ required_groups = rule.get("match_servicegroups")
+ if required_groups != None:
+ sgn = context.get("SERVICEGROUPNAMES")
+ if sgn == None:
+ return "No information about service groups is in the context, but
service " \
+ "must be in group %s" % ( " or
".join(required_groups))
+ if sgn:
+ servicegroups = sgn.split(",")
+ else:
+ return "The service is in no group, but %s is required" % (
+ " or ".join(required_groups))
+
+ for group in required_groups:
+ if group in servicegroups:
+ return
+
+ return "The service is only in the groups %s, but %s is required" % (
+ sgn, " or ".join(required_groups))
+
+
def rbn_match_hostgroups(rule, context):
required_groups = rule.get("match_hostgroups")
if required_groups != None:
@@ -689,7 +713,7 @@ def rbn_match_hostgroups(rule, context):
if group in hostgroups:
return
- return "The host only is the groups %s, but %s is required" % (
+ return "The host is only in the groups %s, but %s is required" % (
hgn, " or ".join(required_groups))
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index ad72b8d..a4cf757 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -8114,17 +8114,17 @@ def FolderChoice(**kwargs):
return DropdownChoice(**kwargs)
-class HostgroupChoice(DualListChoice):
- def __init__(self, **kwargs):
+class GroupChoice(DualListChoice):
+ def __init__(self, what, **kwargs):
DualListChoice.__init__(self, **kwargs)
+ self.what = what
self._choices = lambda: self.load_groups()
def load_groups(self):
all_groups = userdb.load_group_information()
- this_group = all_groups.get("host", {})
+ this_group = all_groups.get(self.what, {})
return [ (k, t['alias'] and t['alias'] or k) for (k, t) in
this_group.items() ]
-
def vs_notification_bulkby():
return ListChoice(
title = _("Create separate notification bulks based on"),
@@ -8262,7 +8262,7 @@ def vs_notification_rule(userid = None):
title = _("Match Host Tags"))
),
( "match_hostgroups",
- HostgroupChoice(
+ GroupChoice("host",
title = _("Match Host Groups"),
help = _("The host must be in one of the selected host
groups"),
allow_empty = False,
@@ -8296,6 +8296,13 @@ def vs_notification_rule(userid = None):
empty_text = _("Please specify at least one service regex. Disable
the option if you want to allow all services."),
)
),
+ ( "match_servicegroups",
+ GroupChoice("service",
+ title = _("Match Service Groups"),
+ help = _("The host must be in one of the selected service
groups"),
+ allow_empty = False,
+ )
+ ),
( "match_exclude_services",
ListOfStrings(
title = _("Do <b>not</b> match the following
services"),
@@ -8546,7 +8553,7 @@ def vs_notification_rule(userid = None):
],
optional_keys = [ "match_folder", "match_hosttags",
"match_hostgroups", "match_hosts", "match_exclude_hosts",
- "match_services", "match_exclude_services",
"match_plugin_output",
+ "match_services", "match_servicegroups",
"match_exclude_services", "match_plugin_output",
"match_timeperiod", "match_escalation",
"match_escalation_throttle",
"match_sl", "match_host_event",
"match_service_event", "match_ec",
"match_checktype", "bulk",
"contact_users", "contact_groups", "contact_emails" ],
@@ -8556,7 +8563,7 @@ def vs_notification_rule(userid = None):
+ contact_headers
+ [
( _("Conditions"), [ "match_folder",
"match_hosttags", "match_hostgroups", "match_hosts",
"match_exclude_hosts",
- "match_services",
"match_exclude_services", "match_plugin_output",
+ "match_services",
"match_servicegroups", "match_exclude_services",
"match_plugin_output",
"match_checktype",
"match_timeperiod",
"match_escalation",
"match_escalation_throttle",
"match_sl",
"match_host_event", "match_service_event", "match_ec" ] ),