Module: check_mk
Branch: master
Commit: a01205c72d38baac68f4aa03669e93fc025e4d61
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a01205c72d38ba…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Sep 30 16:30:46 2015 +0200
#2645 FIX Fix garbled notification context when \n appears in service description
When your service has the name <tt>C:\tmp\network.log</tt>, then the
<tt>\n</tt> would
be interpreted as newline and everything after the \ was lost. This has been fixed.
---
.werks/2645 | 10 ++++++++++
ChangeLog | 1 +
modules/events.py | 13 ++++++++++---
modules/notify.py | 4 ++--
4 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/.werks/2645 b/.werks/2645
new file mode 100644
index 0000000..143839b
--- /dev/null
+++ b/.werks/2645
@@ -0,0 +1,10 @@
+Title: Fix garbled notification context when \n appears in service description
+Level: 2
+Component: notifications
+Compatible: compat
+Version: 1.2.7i3
+Date: 1443623319
+Class: fix
+
+When your service has the name <tt>C:\tmp\network.log</tt>, then the
<tt>\n</tt> would
+be interpreted as newline and everything after the \ was lost. This has been fixed.
diff --git a/ChangeLog b/ChangeLog
index 85d86de..f8c2f56 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -301,6 +301,7 @@
* 2347 FIX: Improved error message in notify.log when sendmail is missing
* 2348 FIX: HTML-Mails: Added missing link to service descriptions
* 2349 FIX: HTML-Mails: Fixed state colors in Outlook
+ * 2645 FIX: Fix garbled notification context when \n appears in service
description...
BI:
* 2537 BI Editor: restructured, now show tree structure of aggregations, show unused
rules...
diff --git a/modules/events.py b/modules/events.py
index fe2dff7..60b198c 100644
--- a/modules/events.py
+++ b/modules/events.py
@@ -123,21 +123,28 @@ def raw_context_from_string(data):
try:
for line in data.split('\n'):
varname, value = line.strip().split("=", 1)
- context[varname] = value.replace(r"\n",
"\n").replace("\\\\", "\\")
+ context[varname] = expand_backslashes(value)
except Exception, e: # line without '=' ignored or alerted
if opt_debug:
raise
return context
-
def raw_context_from_stdin():
context = {}
for line in sys.stdin:
varname, value = line.strip().split("=", 1)
- context[varname] = value.replace(r"\n",
"\n").replace("\\\\", "\\")
+ context[varname] = expand_backslashes(value)
return context
+def expand_backslashes(value):
+ # We cannot do the following:
+ # value.replace(r"\n", "\n").replace("\\\\",
"\\")
+ # \\n would be exapnded to \<LF> instead of \n. This was a bug
+ # in previous versions.
+ return value.replace("\\\\", "\0").replace("\\n",
"\n").replace("\0", "\\")
+
+
def convert_context_to_unicode(context):
# Convert all values to unicode
for key, value in context.iteritems():
diff --git a/modules/notify.py b/modules/notify.py
index 5be18a5..b5c6a86 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -236,8 +236,8 @@ def notify_notify(raw_context, analyse=False):
notify_log("Analysing notification (%s) context with %s variables" % (
find_host_service_in_context(raw_context), len(raw_context)))
else:
- notify_log("Got raw notification (%s) context with %s variables" % (
- find_host_service_in_context(raw_context), len(raw_context)))
+ notify_log("Got raw notification (%s) context with %s variables (%r)" %
(
+ find_host_service_in_context(raw_context), len(raw_context), raw_context))
# Add some further variable for the conveniance of the plugins