Module: check_mk
Branch: master
Commit: c4364765803862072f4fa7ef0c8d3b3024001e38
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c4364765803862…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Apr 2 12:25:12 2015 +0200
#2188 Rule based notification now allow match for notification comment
A new condition allows a match on the notification comment. This comment
is supplied in custom notifications - never in normal notifications. This
allows to create custom commands that e.g. open tickets by creating custom
notifications with a certain text in the comment.
---
.werks/2188 | 12 ++++++++++++
ChangeLog | 1 +
modules/notify.py | 9 +++++++++
web/htdocs/wato.py | 14 ++++++++++++--
4 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/.werks/2188 b/.werks/2188
new file mode 100644
index 0000000..d687b0e
--- /dev/null
+++ b/.werks/2188
@@ -0,0 +1,12 @@
+Title: Rule based notification now allow match for notification comment
+Level: 1
+Component: notifications
+Compatible: compat
+Version: 1.2.7i1
+Date: 1427970243
+Class: feature
+
+A new condition allows a match on the notification comment. This comment
+is supplied in custom notifications - never in normal notifications. This
+allows to create custom commands that e.g. open tickets by creating custom
+notifications with a certain text in the comment.
diff --git a/ChangeLog b/ChangeLog
index 6f11239..c1c697b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -425,6 +425,7 @@
* 2041 Notification Spooler can now handle incoming and outgoing persistent TCP
connections...
* 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...
* 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 1f91435..5ba3246 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -670,6 +670,7 @@ def rbn_match_rule(rule, context):
rbn_match_servicelevel(rule, context) or \
rbn_match_host_event(rule, context) or \
rbn_match_service_event(rule, context) or \
+ rbn_match_notification_comment(rule, context) or \
rbn_match_event_console(rule, context)
@@ -971,6 +972,14 @@ def rbn_rule_contacts(rule, context):
return all_enabled
+def rbn_match_notification_comment(rule, context):
+ if "match_notification_comment" in rule:
+ r = regex(rule["match_notification_comment"])
+ notification_comment = context.get("NOTIFICATIONCOMMENT",
"")
+ if not r.match(notification_comment):
+ return "The beginning of the notification comment '%s' is not
matched by the regex '%s'" % (
+ notification_comment, rule["match_notification_comment"])
+
def rbn_match_event_console(rule, context):
if "match_ec" in rule:
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index b58f738..d9a0ffa 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -8539,6 +8539,16 @@ def vs_notification_rule(userid = None):
default_value = [ 'rw', 'rc', 'ru',
'wc', 'wu', 'uc', 'f', 's', 'x' ],
)
),
+ ( "match_notification_comment",
+ RegExpUnicode(
+ title = _("Match notification comment"),
+ help = _("This match only makes sense for custom notifications.
When a user creates "
+ "a custom notification then he/she can enter a comment.
This comment is shipped "
+ "in the notification context variable
<tt>NOTIFICATIONCOMMENT</tt>. Here you can "
+ "make a condition of that comment. It is a regular
expression matching the beginning "
+ "of the comment."),
+ size = 60,
+ )),
( "match_ec",
Alternative(
title = _("Event Console alerts"),
@@ -8667,7 +8677,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_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_sl", "match_host_event",
"match_service_event", "match_ec",
"match_notification_comment",
"match_checktype", "bulk",
"contact_users", "contact_groups", "contact_emails",
"contact_match_macros" ],
headers = [
( _("Rule Properties"), [ "description",
"comment", "disabled", "docu_url", "allow_disable"
] ),
@@ -8678,7 +8688,7 @@ def vs_notification_rule(userid = None):
"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" ] ),
+ "match_sl",
"match_host_event", "match_service_event", "match_ec",
"match_notification_comment" ] ),
],
render = "form",
form_narrow = True,