Module: check_mk
Branch: master
Commit: 6958dd6fdce8ccfc8482dd27b0d2d8da8ee80715
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6958dd6fdce8cc…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Sep 3 15:50:09 2014 +0200
#1394 HTML notifications have a new content field for debugging variables
When configuring notifications and customizing templates then you might often
wonder, which variables are present and which values they have. In the HTML
email notifications you can now enable the new field <i>Complete variable
list</i>
in the <i>Information to be displayed in the email body<i/>. This adds a
table
with all avaiable variables and their current settings in the notification
in question.
---
.werks/1394 | 14 +++++++++++++
ChangeLog | 3 ++-
notifications/mail | 39 +++++++++++++++++++++++++++++++++++++
web/plugins/wato/notifications.py | 17 ++++++++--------
4 files changed, 64 insertions(+), 9 deletions(-)
diff --git a/.werks/1394 b/.werks/1394
new file mode 100644
index 0000000..0080009
--- /dev/null
+++ b/.werks/1394
@@ -0,0 +1,14 @@
+Title: HTML notifications have a new content field for debugging variables
+Level: 2
+Component: notifications
+Compatible: compat
+Version: 1.2.5i6
+Date: 1409752076
+Class: feature
+
+When configuring notifications and customizing templates then you might often
+wonder, which variables are present and which values they have. In the HTML
+email notifications you can now enable the new field <i>Complete variable
list</i>
+in the <i>Information to be displayed in the email body<i/>. This adds a
table
+with all avaiable variables and their current settings in the notification
+in question.
diff --git a/ChangeLog b/ChangeLog
index 3ac4fee..2debae7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -69,7 +69,7 @@
NOTE: Please refer to the migration notes!
* 1102 FIX: esx_vsphere_counters: no longer raise false alarms because of invalid
data from ESX Host...
* 1149 FIX: check_mk-ibm_svc_systemstats.diskio, check_mk-ibm_svc_systemstats.iops:
fix exception in Perf-O-Meter
- * 0651 FIX: f5_bigip_interfaces: indentation error and oid to determine the interface
state fixed...
+ * 0651 FIX: f5_bigip_interfaces: Fix invalid throughput values, detect newer F5
devices...
* 1393 FIX: casa_cpu_temp, casa_cpu_util: Change service description to standard...
NOTE: Please refer to the migration notes!
@@ -95,6 +95,7 @@
Notifications:
* 1151 Add variables (HOST/SERVICE)ACK(AUTHOR/COMMENT) to notification context...
+ * 1394 HTML notifications have a new content field for debugging variables...
* 1156 FIX: Graphs in HTML mails are now sent again where they where missing...
* 1157 FIX: Fixed SMS plugin on at least debian (distrs which have no
sendsms/smssend)...
diff --git a/notifications/mail b/notifications/mail
index 06c0408..57f4b28 100755
--- a/notifications/mail
+++ b/notifications/mail
@@ -170,6 +170,17 @@ td.graphs {
img {
margin-right: 10px;
}
+
+table.context {
+ border-collapse: collapse;
+}
+
+table.context td {
+ border: 1px solid #888;
+ padding: 3px 8px;
+}
+
+
</style>
</head>
<body>
@@ -261,6 +272,12 @@ body_elements = [
( "perfdata", "service", False, "Performance Data",
"$SERVICEPERFDATA$",
"$SERVICEPERFDATA$",),
+
+ # Debugging
+ ( "context", "both", False, "Complete variable list",
+ "$CONTEXT_ASCII$",
+ "$CONTEXT_HTML$",
+ )
]
tmpl_host_subject = 'Check_MK: $HOSTNAME$ - $EVENT_TXT$'
@@ -278,10 +295,32 @@ def substitute_context(template, context):
for varname, value in context.items():
template = template.replace('$'+varname+'$', value)
+ # Debugging of variables. Create content only on demand
+ if "$CONTEXT_ASCII$" in template or "$CONTEXT_HTML$" in
template:
+ template = replace_variable_context(template, context)
+
# Remove the rest of the variables and make them empty
template = re.sub("\$[A-Z_][A-Z_0-9]*\$", "", template)
return template
+
+def replace_variable_context(template, context):
+ ascii_output = ""
+ html_output = "<table class=context>\n"
+ elements = context.items()
+ elements.sort()
+ for varname, value in elements:
+ ascii_output += "%s=%s\n" % (varname, value)
+ html_output += "<tr><td class=varname>%s</td><td
class=value>%s</td></tr>\n" % (
+ varname, encode_entities(value))
+ html_output += "</table>\n"
+ return template.replace("$CONTEXT_ASCII$",
ascii_output).replace("$CONTEXT_HTML$", html_output)
+
+
+def encode_entities(text):
+ return text.replace("&",
"&").replace("<",
"<").replace(">", ">")
+
+
def multipart_mail(target, subject, from_address, reply_to, content_txt, content_html,
attach = []):
m = MIMEMultipart('related', _charset='utf-8')
diff --git a/web/plugins/wato/notifications.py b/web/plugins/wato/notifications.py
index b120dd1..33d8830 100644
--- a/web/plugins/wato/notifications.py
+++ b/web/plugins/wato/notifications.py
@@ -63,14 +63,15 @@ register_notification_parameters("mail",
ListChoice(
title = _("Information to be displayed in the email body"),
choices = [
- ( "address", _("IP Address of Host") ),
- ( "abstime", _("Absolute Time of Alert") ),
- ( "reltime", _("Relative Time of Alert") ),
- ( "longoutput", _("Additional Plugin Output")
),
- ( "ack_author", _("Acknowledgement Author") ),
- ( "ack_comment", _("Acknowledgement Comment")
),
- ( "perfdata", _("Performance Data") ),
- ( "graph", _("Performance Graphs") ),
+ ( "address", _("IP Address of Host") ),
+ ( "abstime", _("Absolute Time of Alert")
),
+ ( "reltime", _("Relative Time of Alert")
),
+ ( "longoutput", _("Additional Plugin Output")
),
+ ( "ack_author", _("Acknowledgement Author")
),
+ ( "ack_comment", _("Acknowledgement Comment")
),
+ ( "perfdata", _("Performance Data") ),
+ ( "graph", _("Performance Graphs") ),
+ ( "context", _("Complete variable list (for
testing)" ) ),
],
default_value = [ "perfdata", "graph",
"abstime", "address", "longoutput" ],
)