Module: check_mk
Branch: master
Commit: bdcca5e8bad5b600637f5e2d432cb308c95bc11f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bdcca5e8bad5b6…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Thu Oct 19 14:56:53 2017 +0200
5323 Notification mail: Added variables which will be replaced by the entities choosen
below 'Create separate notification bulks based on'
If bulking is enabled in notification mail the following variables
will be replaced if the related entity is choosen below
<i>Create separate notification bulks based on</i>. These are
<ul>
<li>Folder: <code>$FOLDER$</code></li>
<li>Hostname: <code>$HOSTNAME$</code></li>
<li>Service description: <code>$SERVICEDESC$</code></li>
<li>Service level: <code>$SERVICE_LEVEL$</code></li>
<li>Check type: <code>$CHECKCOMMAND$</code></li>
<li>Host/Service state: <code>$STATE$</code></li>
<li>Event console contact: <code>$EC_CONTACT$</code></li>
</ul>
Change-Id: I01a444e0a2de47963be67ff303417178aab7497d
---
.werks/5323 | 21 +++++++++++++++++++++
cmk_base/notify.py | 22 +++++++++-------------
notifications/asciimail | 16 ++++++++++++++++
notifications/mail | 16 ++++++++++++++++
4 files changed, 62 insertions(+), 13 deletions(-)
diff --git a/.werks/5323 b/.werks/5323
new file mode 100644
index 0000000..bcc5d96
--- /dev/null
+++ b/.werks/5323
@@ -0,0 +1,21 @@
+Title: Notification mail: Added variables which will be replaced by the entities choosen
below 'Create separate notification bulks based on'
+Level: 1
+Component: notifications
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1508416809
+Class: feature
+
+If bulking is enabled in notification mail the following variables
+will be replaced if the related entity is choosen below
+<i>Create separate notification bulks based on</i>. These are
+<ul>
+<li>Folder: <code>$FOLDER$</code></li>
+<li>Hostname: <code>$HOSTNAME$</code></li>
+<li>Service description: <code>$SERVICEDESC$</code></li>
+<li>Service level: <code>$SERVICE_LEVEL$</code></li>
+<li>Check type: <code>$CHECKCOMMAND$</code></li>
+<li>Host/Service state: <code>$STATE$</code></li>
+<li>Event console contact: <code>$EC_CONTACT$</code></li>
+</ul>
diff --git a/cmk_base/notify.py b/cmk_base/notify.py
index dd5622c..61bb1de 100644
--- a/cmk_base/notify.py
+++ b/cmk_base/notify.py
@@ -1444,8 +1444,12 @@ def do_bulk_notify(plugin, params, plugin_context, bulk):
bulk_path = (contact, plugin, str(bulk["interval"]),
str(bulk["count"]))
bulkby = bulk["groupby"]
+ if "bulk_subject" in bulk:
+ plugin_context["PARAMETER_BULK_SUBJECT"] =
bulk["bulk_subject"]
+
if "host" in bulkby:
bulk_path += ("host", plugin_context["HOSTNAME"])
+
elif "folder" in bulkby:
bulk_path += ("folder", find_wato_folder(plugin_context))
@@ -1453,27 +1457,19 @@ def do_bulk_notify(plugin, params, plugin_context, bulk):
bulk_path += ("service", plugin_context.get("SERVICEDESC",
""))
if "sl" in bulkby:
- sl = plugin_context.get(what + "_SL", "")
- bulk_path += ("sl", sl)
+ bulk_path += ("sl", plugin_context.get(what + "_SL",
""))
if "check_type" in bulkby:
- command = plugin_context.get(what + "CHECKCOMMAND",
"").split("!")[0]
- bulk_path += ("check_type", command)
+ bulk_path += ("check_type", plugin_context.get(what +
"CHECKCOMMAND", "").split("!")[0])
if "state" in bulkby:
- state = plugin_context.get(what + "STATE", "")
- bulk_path += ("state", state)
+ bulk_path += ("state", plugin_context.get(what + "STATE",
""))
if "ec_contact" in bulkby:
- ec_contact = plugin_context.get("EC_CONTACT", "")
- bulk_path += ("ec_contact", ec_contact)
+ bulk_path += ("ec_contact", plugin_context.get("EC_CONTACT",
""))
if "ec_comment" in bulkby:
- ec_comment = plugin_context.get("EC_COMMENT", "")
- bulk_path += ("ec_comment", ec_comment)
-
- if "bulk_subject" in bulk:
- plugin_context["PARAMETER_BULK_SUBJECT"] =
bulk["bulk_subject"]
+ bulk_path += ("ec_comment", plugin_context.get("EC_COMMENT",
""))
# User might have specified _FOO instead of FOO
bulkby_custom = bulk.get("groupby_custom", [])
diff --git a/notifications/asciimail b/notifications/asciimail
index cd2f6e1..886f401 100755
--- a/notifications/asciimail
+++ b/notifications/asciimail
@@ -215,12 +215,24 @@ def read_bulk_contexts():
return parameters, contexts
+def find_wato_folder(context):
+ # Same as in notify.py
+ for tag in context.get("HOSTTAGS", "").split():
+ if tag.startswith("/wato/"):
+ return tag[6:].rstrip("/")
+ return ""
+
+
def get_bulk_notification_subject(contexts, hosts):
hosts = list(hosts)
bulk_subject = None
+ folder = None
+ bulk_context = {}
for context in contexts:
if context.get("PARAMETER_BULK_SUBJECT"):
+ bulk_context = context
bulk_subject = context["PARAMETER_BULK_SUBJECT"]
+ folder = find_wato_folder(context)
break
if bulk_subject:
@@ -230,10 +242,14 @@ def get_bulk_notification_subject(contexts, hosts):
else:
subject = "Check_MK: $COUNT_NOTIFICATIONS$ notifications for $COUNT_HOSTS$
hosts"
+ if "$FOLDER$" in subject and folder is not None:
+ subject = subject.replace("$FOLDER$", folder)
if "$COUNT_NOTIFICATIONS$" in subject:
subject = subject.replace("$COUNT_NOTIFICATIONS$", str(len(contexts)))
if "$COUNT_HOSTS$" in subject:
subject = subject.replace("$COUNT_HOSTS$", str(len(hosts)))
+
+ subject = substitute_context(subject, bulk_context)
return subject
diff --git a/notifications/mail b/notifications/mail
index 464704d..5404d7a 100755
--- a/notifications/mail
+++ b/notifications/mail
@@ -949,12 +949,24 @@ def read_bulk_contexts():
return parameters, contexts
+def find_wato_folder(context):
+ # Same as in notify.py
+ for tag in context.get("HOSTTAGS", "").split():
+ if tag.startswith("/wato/"):
+ return tag[6:].rstrip("/")
+ return ""
+
+
def get_bulk_notification_subject(contexts, hosts):
hosts = list(hosts)
bulk_subject = None
+ folder = None
+ bulk_context = {}
for context in contexts:
if context.get("PARAMETER_BULK_SUBJECT"):
+ bulk_context = context
bulk_subject = context["PARAMETER_BULK_SUBJECT"]
+ folder = find_wato_folder(context)
break
if bulk_subject:
@@ -964,10 +976,14 @@ def get_bulk_notification_subject(contexts, hosts):
else:
subject = "Check_MK: $COUNT_NOTIFICATIONS$ notifications for $COUNT_HOSTS$
hosts"
+ if "$FOLDER$" in subject and folder is not None:
+ subject = subject.replace("$FOLDER$", folder)
if "$COUNT_NOTIFICATIONS$" in subject:
subject = subject.replace("$COUNT_NOTIFICATIONS$", str(len(contexts)))
if "$COUNT_HOSTS$" in subject:
subject = subject.replace("$COUNT_HOSTS$", str(len(hosts)))
+
+ subject = substitute_context(subject, bulk_context)
return subject