Module: check_mk
Branch: master
Commit: 9e2cd7b4ac891e87e06733a70e1476f792bc0de0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9e2cd7b4ac891e…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Sep 28 12:50:24 2016 +0200
Improved error handling while sending GUI notifications via mail
---
web/htdocs/notify.py | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/web/htdocs/notify.py b/web/htdocs/notify.py
index c61ce60..59eadcb 100644
--- a/web/htdocs/notify.py
+++ b/web/htdocs/notify.py
@@ -317,12 +317,18 @@ def notify_mail(user_id, msg):
else:
raise MKInternalError(_('No UTF-8 encoding found in your locale -a! Please
provide C.UTF-8 encoding.'))
- p = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, stdin=subprocess.PIPE,
+ try:
+ p = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT, stdin=subprocess.PIPE,
close_fds=True)
- stdout_txt, stderr_txt = p.communicate(body.encode("utf-8"))
+ except OSError, e:
+ raise MKInternalError(_('Mail could not be delivered. '
+ 'Failed to execute command "%s": %s' %
(" ".join(command), e)))
+
+ output = p.communicate(body.encode("utf-8"))[0]
exitcode = p.returncode
if exitcode != 0:
- raise MKInternalError(_('Mail could not be delivered. Exit code of command is
%r') % exitcode)
+ raise MKInternalError(_('Mail could not be delivered. Exit code of command is
%r. '
+ 'Output is: %s') % (exitcode, output))
else:
return True