Module: check_mk
Branch: master
Commit: b796073e9a6c5545b38bc28c8d8e21b1b93dfbf1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b796073e9a6c55…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Nov 17 12:23:51 2014 +0100
#1512 Bulk notification can now be grouped according to custom macro values
When you configure notification bulking you can now let the value of
one or several host/service custom macros decide in which bulk a
notification email goes. For example you can select the variable <tt>FOO</tt>
to be used for grouping. Then for each different value of this macro
a separate bulk will be created.
---
.werks/1512 | 13 +++++++++++++
ChangeLog | 1 +
modules/notify.py | 9 ++++++++-
web/htdocs/wato.py | 14 ++++++++++++++
4 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/.werks/1512 b/.werks/1512
new file mode 100644
index 0000000..398292b
--- /dev/null
+++ b/.werks/1512
@@ -0,0 +1,13 @@
+Title: Bulk notification can now be grouped according to custom macro values
+Level: 2
+Component: notifications
+Compatible: compat
+Version: 1.2.5i7
+Date: 1416223329
+Class: feature
+
+When you configure notification bulking you can now let the value of
+one or several host/service custom macros decide in which bulk a
+notification email goes. For example you can select the variable
<tt>FOO</tt>
+to be used for grouping. Then for each different value of this macro
+a separate bulk will be created.
diff --git a/ChangeLog b/ChangeLog
index 0fe476a..2eb70db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -63,6 +63,7 @@
* 1498 FIX: Fixed displaying of global settings titles / help texts...
Notifications:
+ * 1512 Bulk notification can now be grouped according to custom macro values...
* 1168 FIX: HTML mails can now be configured to display graphs among each other...
BI:
diff --git a/modules/notify.py b/modules/notify.py
index 3c0d063..f9d6164 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -1443,7 +1443,7 @@ def do_bulk_notify(contact, plugin, params, plugin_context, bulk):
# 2. plugin
# 3. time horizon (interval) in seconds
# 4. max bulked notifications
- # 5. elements specified in bulk["groupby"]
+ # 5. elements specified in bulk["groupby"] and
bulk["groupby_custom"]
# We first create a bulk path constructed as a tuple of strings.
# Later we convert that to a unique directory name.
# Note: if you have separate bulk rules with exactly the same
@@ -1468,6 +1468,13 @@ def do_bulk_notify(contact, plugin, params, plugin_context, bulk):
state = plugin_context.get(what + "STATE", "")
bulk_path += ("state", state)
+ # User might have specified _FOO instead of FOO
+ bulkby_custom = bulk.get("groupby_custom", [])
+ for macroname in bulkby_custom:
+ macroname = macroname.lstrip("_").upper()
+ value = plugin_context.get(what + "_" + macroname, "")
+ bulk_path += (macroname.lower(), value)
+
notify_log(" --> storing for bulk notification %s" %
"|".join(bulk_path))
bulk_dirname = create_bulk_dirname(bulk_path)
uuid = fresh_uuid()
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 5d4ca8e..5b68ffe 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -8511,6 +8511,20 @@ def vs_notification_rule(userid = None):
( "groupby",
vs_notification_bulkby(),
),
+ ( "groupby_custom",
+ ListOfStrings(
+ valuespec = ID(),
+ orientation = "horizontal",
+ title = _("Create separate notification bulks for
different values of the following custom macros"),
+ help = _("If you enter the names of host/service-custom
macros here then for each different "
+ "combination of values of those macros a separate
bulk will be created. This can be used "
+ "in combination with the grouping by folder, host
etc. Omit any leading underscore. "
+ "<b>Note</b>: If you are using
"
+ "Nagios as a core you need to make sure that the
values of the required macros are "
+ "present in the notification context. This is
done in <tt>check_mk_templates.cfg</tt>. If you "
+ "macro is <tt>_FOO</tt> then you need
to add the variables <tt>NOTIFY_HOST_FOO</tt> and "
+
"<tt>NOTIFY_SERVICE_FOO</tt>."),
+ )),
],
columns = 1,
optional_keys = False,