[checkmk-commits] Check_MK Git: check_mk: #2195 New condition "Match Contacts" in rule based notifications

Mathias Kettner mk at mathias-kettner.de
Thu Apr 9 15:15:03 CEST 2015


Module: check_mk
Branch: master
Commit: ad7587e4e504e87e35e43b0ce43a2830a29dde29
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ad7587e4e504e87e35e43b0ce43a2830a29dde29

Author: Mathias Kettner <mk at mathias-kettner.de>
Date:   Thu Apr  9 15:14:55 2015 +0200

#2195 New condition "Match Contacts" in rule based notifications

You can now add a new condition in a notification rule in order to match
for the contacts of a host or service. That way you can make rules
like "If user adam is a contact of the host/service, then notify bernie."

---

 .werks/2195        |   11 +++++++++++
 ChangeLog          |    1 +
 modules/notify.py  |   18 ++++++++++++++++++
 web/htdocs/wato.py |    5 ++---
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/.werks/2195 b/.werks/2195
new file mode 100644
index 0000000..120f7b0
--- /dev/null
+++ b/.werks/2195
@@ -0,0 +1,11 @@
+Title: New condition "Match Contacts" in rule based notifications
+Level: 2
+Component: notifications
+Compatible: compat
+Version: 1.2.7i1
+Date: 1428585184
+Class: feature
+
+You can now add a new condition in a notification rule in order to match
+for the contacts of a host or service. That way you can make rules
+like "If user adam is a contact of the host/service, then notify bernie."
diff --git a/ChangeLog b/ChangeLog
index 14435e9..946e6f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -433,6 +433,7 @@
     * 2135 Allow to filter notification contacts based on values of custom macros...
     * 1235 Added notification plugin for Braintwoer SMS Gateways...
     * 2188 Rule based notification now allow match for notification comment...
+    * 2195 New condition "Match Contacts" in rule based notifications...
     * 1661 FIX: mknotifyd: improved performance when receiving forwarded notifications
     * 1664 FIX: mknotifyd: further performance improvements for notification forwarding
     * 1205 FIX: RBN: Fixed match contactgroup condition...
diff --git a/modules/notify.py b/modules/notify.py
index 5ba3246..dcfd344 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -657,6 +657,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_contacts(rule, context)              or \
         rbn_match_contactgroups(rule, context)         or \
         rbn_match_hosts(rule, context)                 or \
         rbn_match_exclude_hosts(rule, context)         or \
@@ -727,6 +728,23 @@ 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_contacts(rule, context):
+    if "match_contacts" in rule:
+        required_contacts = rule["match_contacts"]
+        contacts_text = context["CONTACTS"]
+        if not contacts_text:
+            return "The object has no contact, but %s is required" % (
+                 " or ".join(required_contacts))
+
+        contacts = contacts_text.split(",")
+        for contact in required_contacts:
+            if contact in contacts:
+                return
+
+        return "The object has the contacts %s, but %s is required" % (
+              contacts_text, " or ".join(required_contacts))
+
+
 def rbn_match_contactgroups(rule, context):
     required_groups = rule.get("match_contactgroups")
     if context["WHAT"] == "SERVICE":
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index ea83d37..fa5d715 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -8397,9 +8397,8 @@ def vs_notification_rule(userid = None):
             ( "match_contacts",
               ListOf(
                   UserSelection(only_contacts = True),
-                      title = _("Match Contacts (CMC only)"),
-                      help = _("The host/service must have one of the selected contacts. This only works with Check_MK Micro Core. " \
-                               "If you don't use the CMC that filter will not apply"),
+                      title = _("Match Contacts"),
+                      help = _("The host/service must have one of the selected contacts."),
                       movable = False,
                       allow_empty = False,
                       add_label = _("Add contact"),



More information about the checkmk-commits mailing list