Module: check_mk
Branch: master
Commit: 90f05a3a9492a1b00fa7926f75ed0961b16ac85e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=90f05a3a9492a1…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Wed Sep 13 16:27:51 2017 +0200
5127 asciimail, mail: Added macros $COUNT_NOTIFICATIONS$ and $COUNT_HOSTS$ which can be
used in bulk notification subject
In notification bulking you're able to customize your own subject.
Moreover if the macro {{$COUNT_NOTIFICATIONS$}} is used, the amount of
notifications will be inserted and if you use the macro {{$COUNT_HOSTS$}}
then the amount of hosts will be applied.
Change-Id: Ic80c5c8ff6eac114463522b44962faa78b78e27e
---
.werks/5127 | 13 +++++++++++++
notifications/asciimail | 19 +++++++++++--------
notifications/mail | 20 ++++++++++++--------
web/htdocs/wato.py | 9 +++++++--
4 files changed, 43 insertions(+), 18 deletions(-)
diff --git a/.werks/5127 b/.werks/5127
new file mode 100644
index 0000000..d763f11
--- /dev/null
+++ b/.werks/5127
@@ -0,0 +1,13 @@
+Title: asciimail, mail: Added macros $COUNT_NOTIFICATIONS$ and $COUNT_HOSTS$ which can be
used in bulk notification subject
+Level: 1
+Component: notifications
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1505312621
+Class: feature
+
+In notification bulking you're able to customize your own subject.
+Moreover if the macro {{$COUNT_NOTIFICATIONS$}} is used, the amount of
+notifications will be inserted and if you use the macro {{$COUNT_HOSTS$}}
+then the amount of hosts will be applied.
diff --git a/notifications/asciimail b/notifications/asciimail
index 3e72eef..94f17d8 100755
--- a/notifications/asciimail
+++ b/notifications/asciimail
@@ -216,16 +216,19 @@ def read_bulk_contexts():
def get_bulk_notification_subject(parameters, contexts, hosts):
+ hosts = list(hosts)
if parameters.get("PARAMETER_BULK_SUBJECT"):
- return parameters["PARAMETER_BULK_SUBJECT"]
-
+ subject = parameters["PARAMETER_BULK_SUBJECT"]
+ elif len(hosts) == 1:
+ subject = "Check_MK: $COUNT_NOTIFICATIONS$ notifications for %s" %
hosts[0]
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))
+ subject = "Check_MK: $COUNT_NOTIFICATIONS$ notifications for $COUNT_HOSTS$
hosts"
+
+ if "$COUNT_NOTIFICATIONS$" in subject:
+ subject.replace("$COUNT_NOTIFICATIONS$", len(contexts))
+ if "$COUNT_HOSTS$" in subject:
+ subject.replace("$COUNT_HOSTS$", len(hosts))
+ return subject
def main():
diff --git a/notifications/mail b/notifications/mail
index 4c8920f..8cbdadd 100755
--- a/notifications/mail
+++ b/notifications/mail
@@ -950,16 +950,20 @@ def read_bulk_contexts():
def get_bulk_notification_subject(parameters, contexts, hosts):
+ hosts = list(hosts)
if parameters.get("PARAMETER_BULK_SUBJECT"):
- return parameters["PARAMETER_BULK_SUBJECT"]
-
+ subject = parameters["PARAMETER_BULK_SUBJECT"]
+ elif len(hosts) == 1:
+ subject = "Check_MK: $COUNT_NOTIFICATIONS$ notifications for %s" %
hosts[0]
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))
+ subject = "Check_MK: $COUNT_NOTIFICATIONS$ notifications for $COUNT_HOSTS$
hosts"
+
+ if "$COUNT_NOTIFICATIONS$" in subject:
+ subject.replace("$COUNT_NOTIFICATIONS$", len(contexts))
+ if "$COUNT_HOSTS$" in subject:
+ subject.replace("$COUNT_HOSTS$", len(hosts))
+ return subject
+
def main():
if bulk_mode:
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 243c617..a05d0b8 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -7671,9 +7671,14 @@ def vs_notification_rule(userid = None):
( "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'."),
+ "default subject <tt>Check_MK:
$COUNT_NOTIFICATIONS$ notifications for HOST</tt>"
+ " resp. <tt>Check_MK: $COUNT_NOTIFICATIONS$
notifications for $COUNT_HOSTS$ hosts</tt>. "
+ "Both macros
<tt>$COUNT_NOTIFICATIONS$</tt> and <tt>$COUNT_HOSTS$</tt> can be
used in "
+ "any customized subject. If
<tt>$COUNT_NOTIFICATIONS$</tt> is used, the amount of "
+ "notifications will be inserted and if you use
<tt>$COUNT_HOSTS$</tt> then the "
+ "amount of hosts will be applied."),
size = 80,
+ default_value = "Check_MK: $COUNT_NOTIFICATIONS$
notifications for $COUNT_HOSTS$ hosts"
)),
],
columns = 1,