Module: check_mk
Branch: master
Commit: e3adcabdddc0f1600d295c1641b073e6dfd1d42d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e3adcabdddc0f1…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Mar 10 18:53:10 2015 +0100
#2135 Allow to filter notification contacts based on values of custom macros
You can now use custom user attributes (macros) for deciding which users should
be notified. For that purpose there is a new check box in the contact selection
of the rule based notifications called <i>Restrict by custom macros</i>.
Here you can specify the name of custom macros and regular expressions for
the allowed values. Users whose macros do not match are being removed from
the list of contacts. Note: You first need to select contacts, the options
just <i>removes</i> contacts, never adds ones.
Custom user attributes can be defined WATO's users module. Please make
sure that you add your macros to the monitoring configuration by selecting
<i>Make this variable available in notifications</i>.
---
.werks/2135 | 19 +++++++++++++++++++
ChangeLog | 1 +
modules/notify.py | 23 +++++++++++++++++++----
web/htdocs/wato.py | 40 ++++++++++++++++++++++++++++++++++------
4 files changed, 73 insertions(+), 10 deletions(-)
diff --git a/.werks/2135 b/.werks/2135
new file mode 100644
index 0000000..1c628ff
--- /dev/null
+++ b/.werks/2135
@@ -0,0 +1,19 @@
+Title: Allow to filter notification contacts based on values of custom macros
+Level: 1
+Component: notifications
+Compatible: compat
+Version: 1.2.7i1
+Date: 1426009795
+Class: feature
+
+You can now use custom user attributes (macros) for deciding which users should
+be notified. For that purpose there is a new check box in the contact selection
+of the rule based notifications called <i>Restrict by custom macros</i>.
+Here you can specify the name of custom macros and regular expressions for
+the allowed values. Users whose macros do not match are being removed from
+the list of contacts. Note: You first need to select contacts, the options
+just <i>removes</i> contacts, never adds ones.
+
+Custom user attributes can be defined WATO's users module. Please make
+sure that you add your macros to the monitoring configuration by selecting
+<i>Make this variable available in notifications</i>.
diff --git a/ChangeLog b/ChangeLog
index 19a0c19..5d99385 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -346,6 +346,7 @@
* 1662 notification plugin spectrum: finalized script. now able to handle host
notications
* 1213 New Notification macros $SERVICEFORURL$ and $HOSTFORURL$...
* 2041 Notification Spooler can now handle incoming and outgoing persistent TCP
connections...
+ * 2135 Allow to filter notification contacts based on values of custom macros...
* 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 0a5f042..1f91435 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -949,10 +949,25 @@ def rbn_rule_contacts(rule, context):
all_enabled = []
for contactname in the_contacts:
contact = contacts.get(contactname)
- if contact and contact.get("disable_notifications", False):
- notify_log(" - skipping contact %s: he/she has disabled
notifications" % contactname)
- else:
- all_enabled.append(contactname)
+ if contact:
+ if contact.get("disable_notifications", False):
+ notify_log(" - skipping contact %s: he/she has disabled
notifications" % contactname)
+ continue
+
+ if "contact_match_macros" in rule:
+ match = True
+ for macro_name, regexp in rule["contact_match_macros"]:
+ value = contact.get("_" + macro_name, "")
+ if not regexp.endswith("$"):
+ regexp = regexp + "$"
+ if not regex(regexp).match(value):
+ notify_log(" - skipping contact %s: value '%s' for
macro '%s' does not match '%s'" % (
+ contactname, value, macro_name, regexp))
+ match = False
+ break
+ if not match:
+ continue
+ all_enabled.append(contactname)
return all_enabled
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 211bc0e..b19f0f3 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -8250,7 +8250,7 @@ def vs_notification_rule(userid = None):
else:
contact_headers = [
( _("Contact Selection"), [ "contact_all",
"contact_all_with_email", "contact_object",
- "contact_users",
"contact_groups", "contact_emails" ] ),
+ "contact_users",
"contact_groups", "contact_emails", "contact_match_macros" ]
),
]
section_contacts = [
# Contact selection
@@ -8296,6 +8296,31 @@ def vs_notification_rule(userid = None):
orientation = "vertical",
)
),
+ ( "contact_match_macros",
+ ListOf(
+ Tuple(
+ elements = [
+ TextAscii(
+ title = _("Name of the macro"),
+ help = _("As configured in the users settings. Do not
add a leading underscore."),
+ allow_empty = False,
+ ),
+ RegExp(
+ title = _("Required match (regular
expression)"),
+ help = _("This expression must complete match the
value of the variable"),
+ allow_empty = False,
+ ),
+ ]
+ ),
+ title = _("Restrict by custom macros"),
+ help = _("Here you can <i>restrict</i> the list of
contacts that has been "
+ "built up by the previous options to those who have
certain values "
+ "in certain custom macros. If you add more than one macro
here then "
+ "<i>all</i> macros must match. The matches
are regular expressions "
+ "that must fully match the value of the macro."),
+ add_label = _("Add condition"),
+ )
+ ),
]
section_override = [
( "allow_disable",
@@ -8667,7 +8692,7 @@ def vs_notification_rule(userid = None):
"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" ],
+ "match_checktype", "bulk",
"contact_users", "contact_groups", "contact_emails",
"contact_match_macros" ],
headers = [
( _("General Properties"), [ "description",
"comment", "disabled", "allow_disable" ] ),
( _("Notification Method"), [ "notify_plugin",
"notify_method", "bulk" ] ),]
@@ -17460,17 +17485,20 @@ def mode_edit_custom_attr(phase, what):
forms.section(_('Editable by Users'))
html.help(_('It is possible to let users edit their custom attributes.'))
- html.checkbox('user_editable', attr.get('user_editable', True))
+ html.checkbox('user_editable', attr.get('user_editable', True),
+ label = _("Users can change this attribute in their personal
settings"))
forms.section(_('Show in Table'))
html.help(_('This attribute is only visibile on the detail pages by default, but
'
'you can also make it visible in the overview tables.'))
- html.checkbox('show_in_table', attr.get('show_in_table', False))
+ html.checkbox('show_in_table', attr.get('show_in_table', False),
+ label = _("Show the setting of the attribute in the user
table"))
- forms.section(_('Add as Custom Macro'))
+ forms.section(_('Add as custom macro'))
html.help(_('The attribute can be added to the contact definiton in order '
'to use it for notifications.'))
- html.checkbox('add_custom_macro', attr.get('add_custom_macro',
False))
+ html.checkbox('add_custom_macro', attr.get('add_custom_macro',
False),
+ label = _("Make this variable available in notifications"))
forms.end()
html.show_localization_hint()