Module: check_mk
Branch: master
Commit: afd036f5d79f1000ac3edf9b1b1f7a3080d9213f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=afd036f5d79f10…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri May 29 17:18:48 2015 +0200
#2304 notification bulking: now able to configure the notification sort order in emails
With this update you can now configure, which notification should get shown
at the top of the email. Per default the oldest notification was displayed at the top.
You can configure the new option <i>Notification sort order for bulk
notifications</i>
in the WATO rules <i>Parameters for HTML Email</i> and <i>Parameters for
ASCII Email</i> or
specifically in a notification rule.
---
.werks/2304 | 14 ++++++++++++++
ChangeLog | 1 +
modules/notify.py | 15 +++++++++++++--
web/plugins/wato/notifications.py | 24 ++++++++++++++++++++++++
4 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/.werks/2304 b/.werks/2304
new file mode 100644
index 0000000..98ea31c
--- /dev/null
+++ b/.werks/2304
@@ -0,0 +1,14 @@
+Title: notification bulking: now able to configure the notification sort order in emails
+Level: 1
+Component: notifications
+Compatible: compat
+Version: 1.2.7i1
+Date: 1432912433
+Class: feature
+
+With this update you can now configure, which notification should get shown
+at the top of the email. Per default the oldest notification was displayed at the top.
+
+You can configure the new option <i>Notification sort order for bulk
notifications</i>
+in the WATO rules <i>Parameters for HTML Email</i> and <i>Parameters
for ASCII Email</i> or
+specifically in a notification rule.
diff --git a/ChangeLog b/ChangeLog
index 403ea87..1b55da4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -536,6 +536,7 @@
* 1235 Added notification plugin for Braintower SMS Gateways...
* 2188 Rule based notification now allow match for notification comment...
* 2195 New condition "Match Contacts" in rule based notifications...
+ * 2304 notification bulking: now able to configure the notification sort order in
emails...
* 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 26bb7b7..f7642ae 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -1690,9 +1690,11 @@ def notify_bulk(dirname, uuids):
unhandled_uuids.append((mtime, uuid))
continue
- bulk_context.append("\n")
+ part_block = []
+ part_block.append("\n")
for varname, value in context.items():
- bulk_context.append("%s=%s\n" % (varname,
value.replace("\r", "").replace("\n", "\1")))
+ part_block.append("%s=%s\n" % (varname,
value.replace("\r", "").replace("\n", "\1")))
+ bulk_context.append(part_block)
# Do not forget to add this to the monitoring log. We create
# a single entry for each notification contained in the bulk.
@@ -1701,6 +1703,15 @@ def notify_bulk(dirname, uuids):
core_notification_log(plugin_name, context)
if bulk_context: # otherwise: only corrupted files
+ # Per default the uuids are sorted chronologically from oldest to newest
+ # Therefore the notification plugin also shows the oldest entry first
+ # The following configuration option allows to reverse the sorting
+ if old_params.get("bulk_sort_order") == "newest_first":
+ bulk_context.reverse()
+
+ # Converts bulk context from [[1,2],[3,4]] to [1,2,3,4]
+ bulk_context = [x for y in bulk_context for x in y]
+
parameter_context = create_bulk_parameter_context(old_params)
context_text = "".join(parameter_context + bulk_context)
call_bulk_notification_script(plugin, context_text)
diff --git a/web/plugins/wato/notifications.py b/web/plugins/wato/notifications.py
index 5b5ac87..b4e9a4c 100644
--- a/web/plugins/wato/notifications.py
+++ b/web/plugins/wato/notifications.py
@@ -103,6 +103,18 @@ register_notification_parameters(
"other."),
)
),
+ ('bulk_sort_order',
+ DropdownChoice(
+ choices = [
+ ('oldest_first', _('Oldest first')),
+ ('newest_first', _('Newest first')),
+ ],
+ help = _("With this option you can specify, whether the oldest
(default) or "
+ "the newest notification should get shown at the top of
the notification mail."),
+ title = _("Notification sort order for bulk
notifications"),
+ default = "oldest_first"
+ )
+ )
]
)
)
@@ -185,6 +197,18 @@ $LONGSERVICEOUTPUT$
""",
)
),
+ ('bulk_sort_order',
+ DropdownChoice(
+ choices = [
+ ('oldest_first', _('Oldest first')),
+ ('newest_first', _('Newest first')),
+ ],
+ help = _("With this option you can specify, whether the oldest
(default) or "
+ "the newest notification should get shown at the top of
the notification mail."),
+ title = _("Notification sort order for bulk
notifications"),
+ default = "oldest_first"
+ )
+ )
]
)
)