Module: check_mk
Branch: master
Commit: a8f7258ece79ebd94315d6ade73cd1ff46dcf71c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a8f7258ece79eb…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon May 29 17:07:49 2017 +0200
4665 mail, asciimail: Added subject for bulk notifications
Change-Id: I4adef18679f88b00aa706091d8da2b187dabcd1a
---
.werks/4665 | 13 +++++++++++++
modules/notify.py | 3 +++
notifications/asciimail | 28 ++++++++++++++++------------
notifications/mail | 24 ++++++++++++++----------
web/htdocs/wato.py | 9 ++++++++-
5 files changed, 54 insertions(+), 23 deletions(-)
diff --git a/.werks/4665 b/.werks/4665
new file mode 100644
index 0000000..3da43c2
--- /dev/null
+++ b/.werks/4665
@@ -0,0 +1,13 @@
+Title: mail, asciimail: Added subject for bulk notifications
+Level: 1
+Component: notifications
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1496070439
+Class: feature
+
+With this new configuration option you can now customize
+the subject for bulk notifications and overwrite default
+subject 'Check_MK: X notifications for HOST' resp.
+'Check_MK: X notifications for Y hosts'.
diff --git a/modules/notify.py b/modules/notify.py
index a8f2f38..2b8d67d 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -1316,6 +1316,9 @@ def do_bulk_notify(contact, plugin, params, plugin_context, bulk):
ec_contact = plugin_context.get("EC_CONTACT", "")
bulk_path += ("ec_contact", ec_contact)
+ if "bulk_subject" in bulk:
+ plugin_context["PARAMETER_BULK_SUBJECT"] =
bulk["bulk_subject"]
+
# User might have specified _FOO instead of FOO
bulkby_custom = bulk.get("groupby_custom", [])
for macroname in bulkby_custom:
diff --git a/notifications/asciimail b/notifications/asciimail
index 618d0af..8ee4b2e 100755
--- a/notifications/asciimail
+++ b/notifications/asciimail
@@ -193,7 +193,6 @@ def read_bulk_contexts():
# First comes a section with global variables
for line in sys.stdin:
line = line.strip()
-
if not line:
in_params = False
context = {}
@@ -213,6 +212,20 @@ def read_bulk_contexts():
return parameters, contexts
+
+def get_bulk_notification_subject(parameters, contexts, hosts):
+ if parameters.get("PARAMETER_BULK_SUBJECT"):
+ return parameters["PARAMETER_BULK_SUBJECT"]
+
+ else:
+ hosts = list(hosts)
+ if len(hosts) == 1:
+ return "Check_MK: %d notifications for %s" % (len(contexts),
hosts[0])
+ else:
+ return "Check_MK: %d notifications for %d hosts" % \
+ (len(contexts), len(hosts))
+
+
def main():
if bulk_mode:
content_txt = ""
@@ -220,20 +233,11 @@ def main():
hosts = set([])
for context in contexts:
context.update(parameters)
- txt = construct_content(context)
- content_txt += txt
+ content_txt += construct_content(context)
mailto = context['CONTACTEMAIL'] # Assume the same in each context
subject = context['SUBJECT']
hosts.add(context["HOSTNAME"])
-
- # Create a useful subject
- hosts = list(hosts)
- if len(contexts) > 1:
- if len(hosts) == 1:
- subject = "Check_MK: %d notifications for %s" % (len(contexts),
hosts[0])
- else:
- subject = "Check_MK: %d notifications for %d hosts" % (
- len(contexts), len(hosts))
+ subject = get_bulk_notification_subject(parameters, contexts, hosts)
else:
# gather all options from env
diff --git a/notifications/mail b/notifications/mail
index 4d2f3b8..532d959 100755
--- a/notifications/mail
+++ b/notifications/mail
@@ -867,7 +867,6 @@ def read_bulk_contexts():
# First comes a section with global variables
for line in sys.stdin:
line = line.strip()
-
if not line:
in_params = False
context = {}
@@ -882,6 +881,19 @@ def read_bulk_contexts():
return parameters, contexts
+
+def get_bulk_notification_subject(parameters, contexts, hosts):
+ if parameters.get("PARAMETER_BULK_SUBJECT"):
+ return parameters["PARAMETER_BULK_SUBJECT"]
+
+ else:
+ hosts = list(hosts)
+ if len(hosts) == 1:
+ return "Check_MK: %d notifications for %s" % (len(contexts),
hosts[0])
+ else:
+ return "Check_MK: %d notifications for %d hosts" % \
+ (len(contexts), len(hosts))
+
def main():
if bulk_mode:
attachments = []
@@ -898,15 +910,7 @@ def main():
mailto = context['CONTACTEMAIL'] # Assume the same in each context
subject = context['SUBJECT']
hosts.add(context["HOSTNAME"])
-
- # Create a useful subject
- hosts = list(hosts)
- if len(contexts) > 1:
- if len(hosts) == 1:
- subject = "Check_MK: %d notifications for %s" % (len(contexts),
hosts[0])
- else:
- subject = "Check_MK: %d notifications for %d hosts" % (
- len(contexts), len(hosts))
+ subject = get_bulk_notification_subject(parameters, contexts, hosts)
else:
# gather all options from env
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index c23bb2b..b7d7fd9 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7634,9 +7634,16 @@ def vs_notification_rule(userid = None):
"macro is <tt>_FOO</tt> then you need
to add the variables <tt>NOTIFY_HOST_FOO</tt> and "
"<tt>NOTIFY_SERVICE_FOO</tt>."),
)),
+ ( "bulk_subject", TextAscii(
+ title = _("Subject for bulk notifications"),
+ help = _("Customize the subject for bulk notifications and
overwrite "
+ "default subject 'Check_MK: X notifications for
HOST' resp. "
+ "'Check_MK: X notifications for Y
hosts'."),
+ size = 80,
+ )),
],
columns = 1,
- optional_keys = False,
+ optional_keys = ["bulk_subject"],
),
),