Module: check_mk
Branch: master
Commit: 9936c652b78901eda9d930e21014f29fad7e648d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9936c652b78901…
Author: Bastian Kuhn <bk(a)mathias-kettner.de>
Date: Tue Oct 14 15:37:44 2014 +0200
RBN: Prepare support for Contact Group Filter. Only works with CMC, Nagios don't have
all needed informations
---
modules/notify.py | 26 ++++++++++++++++++++++++++
web/htdocs/wato.py | 14 +++++++++++---
2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/modules/notify.py b/modules/notify.py
index 276b11a..ec09c31 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -627,6 +627,7 @@ def rbn_match_rule(rule, context):
rbn_match_hosttags(rule, context) or \
rbn_match_hostgroups(rule, context) or \
rbn_match_servicegroups(rule, context) or \
+ rbn_match_contactgroups(rule, context) or \
rbn_match_hosts(rule, context) or \
rbn_match_exclude_hosts(rule, context) or \
rbn_match_services(rule, context) or \
@@ -695,6 +696,31 @@ def rbn_match_servicegroups(rule, context):
return "The service is only in the groups %s, but %s is required" % (
sgn, " or ".join(required_groups))
+def rbn_match_contactgroups(rule, context):
+ required_groups = rule.get("match_contactgroups")
+ if context["WHAT"] != "SERVICE":
+ cgn = context.get("SERVICECONTACTS")
+ else:
+ cgn = context.get("HOSTCONTACTGROUPNAMES")
+
+ if required_groups != None:
+ if cgn == None:
+ notify_log("Warning: No information about contact groups in the context.
" \
+ "Seams that you don't use the Check_MK Microcore.
")
+ return
+ if cgn:
+ contactgroups = cgn.split(",")
+ else:
+ return "The object is in no group, but %s is required" % (
+ " or ".join(required_groups))
+
+ for group in required_groups:
+ if group in contactgroups:
+ return
+
+ return "The object is only in the groups %s, but %s is required" % (
+ cgn, " or ".join(required_groups))
+
def rbn_match_hostgroups(rule, context):
required_groups = rule.get("match_hostgroups")
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index b0fea5a..80ce88e 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -8301,7 +8301,15 @@ def vs_notification_rule(userid = None):
( "match_servicegroups",
GroupChoice("service",
title = _("Match Service Groups"),
- help = _("The host must be in one of the selected service
groups"),
+ help = _("The service must be in one of the selected service
groups"),
+ allow_empty = False,
+ )
+ ),
+ ( "match_contactgroups",
+ GroupChoice("contact",
+ title = _("Match Contact Groups (cmc only)"),
+ help = _("The host/ service must be in one of the selected contact
groups. Only works with Check_MK Microcore. " \
+ "If you don't use the CMC, that filter will not
apply"),
allow_empty = False,
)
),
@@ -8555,7 +8563,7 @@ def vs_notification_rule(userid = None):
],
optional_keys = [ "match_folder", "match_hosttags",
"match_hostgroups", "match_hosts", "match_exclude_hosts",
- "match_services", "match_servicegroups",
"match_exclude_services", "match_plugin_output",
+ "match_services", "match_servicegroups",
"match_contactgroups", "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" ],
@@ -8565,7 +8573,7 @@ def vs_notification_rule(userid = None):
+ contact_headers
+ [
( _("Conditions"), [ "match_folder",
"match_hosttags", "match_hostgroups", "match_hosts",
"match_exclude_hosts",
- "match_services",
"match_servicegroups", "match_exclude_services",
"match_plugin_output",
+ "match_services",
"match_servicegroups", "match_contactgroups",
"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" ] ),