Module: check_mk
Branch: master
Commit: 8ea57fbbebf36ce89e3437adee9703b1f20fdc21
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8ea57fbbebf36c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Dec 7 11:29:54 2015 +0100
#2862 FIX Fixed handling of umlauts in mails send by the EC
---
.werks/2862 | 9 +++++++++
ChangeLog | 1 +
mkeventd/bin/mkeventd | 43 ++++++++++++++++++++++++++++++++++++-------
3 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/.werks/2862 b/.werks/2862
new file mode 100644
index 0000000..6cd4355
--- /dev/null
+++ b/.werks/2862
@@ -0,0 +1,9 @@
+Title: Fixed handling of umlauts in mails send by the EC
+Level: 1
+Component: ec
+Compatible: compat
+Version: 1.2.7i4
+Date: 1449484145
+Class: fix
+
+
diff --git a/ChangeLog b/ChangeLog
index c0ec42c..2b55848 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -200,6 +200,7 @@
* 2719 FIX: Events Check: Links to EC were broken when using regular expressions as
application...
* 2757 FIX: Events Check: Fixed check finding too many events (host search was infix
search instead of full match)...
* 2795 FIX: mkeventd: send email action did not work if message text contains
umlauts...
+ * 2862 FIX: Fixed handling of umlauts in mails send by the EC
Livestatus:
* 2743 FIX: Fixed handling of column types in "GET columns"...
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index 6dd2160..e17ad39 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -3244,14 +3244,15 @@ def do_event_actions(actions, event, is_cancelling):
# not hang for more than a couple of ms.
def do_event_action(action, event, user=""):
if action["disabled"]:
+ log("Skipping disabled action %s." % action["id"])
return
try:
action_type, settings = action["action"]
if action_type == 'email':
- to = substitute_event_tags(settings["to"], event)
+ to = substitute_event_tags(settings["to"], event)
subject = substitute_event_tags(settings["subject"], event)
- body = to_utf8(substitute_event_tags(settings["body"], event))
+ body = substitute_event_tags(settings["body"], event)
send_email(to, subject, body)
log_event_history(event, "EMAIL", user, "%s|%s" % (to,
subject))
elif action_type == 'script':
@@ -3363,11 +3364,40 @@ def substitute_event_tags(text, event):
text = text.replace('$%s$' % key.upper(), value)
return text
+
def quote_shell_string(s):
return "'" + s.replace("'",
"'\"'\"'") + "'"
+
def send_email(to, subject, body):
- os.popen("mail -s %s %s" % (quote_shell_string(subject),
quote_shell_string(to)), "w").write(body)
+ # -S sendcharsets=utf-8 is "nail" specific. Nail is delivered with OMD.
Hope
+ # it does not cause problems with other mail commands. Otherwise we need
+ # to find another solution for sending mails containing special chars.
+ # At least nail fails without this header when the mail contains such chars.
+ command_utf8 = "mail -S sendcharsets=utf-8 " \
+ "-s %s %s" %
(quote_shell_string(subject.encode("utf-8")),
+ quote_shell_string(to.encode("utf-8")))
+
+ if g_config["debug_rules"]:
+ log(" Executing: %s" % command_utf8)
+
+ p = subprocess.Popen(command_utf8, shell=True, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, stdin=subprocess.PIPE)
+ # FIXME: This may lock on too large buffer. We should move all "mail
sending" code
+ # to a general place and fix this for all our components (notification plugins,
+ # notify.py, this one, ...)
+ stdout_txt, stderr_txt = p.communicate(body.encode("utf-8"))
+ exitcode = p.returncode
+
+ log(' Exitcode: %d' % exitcode)
+ if exitcode != 0:
+ log(" Error: Failed to send the mail.")
+ for line in (stdout_txt + stderr_txt).splitlines():
+ log(" Output: %s" % line.rstrip())
+ return False
+
+ return True
+
def execute_script(body):
p = subprocess.Popen(
@@ -3379,10 +3409,9 @@ def execute_script(body):
output = p.stdout.read()
exitcode = p.wait()
- if g_config["debug_rules"]:
- if output:
- log(' Output: %s' % output)
- log(' Exitcode: %d' % exitcode)
+ log(' Exitcode: %d' % exitcode)
+ if output:
+ log(' Output: %s' % output)
#.