Module: check_mk
Branch: master
Commit: f44b2f0925b735e5fbd4443a5c203cd1dadfc672
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f44b2f0925b735…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Mon Jul 18 11:16:07 2016 +0200
3558 check_mail: now able to process mail body with Content-Transfer-Encoding base64
When forwarding mails to the event console the plugin now
decodes any base64 content back to human readable lines.
---
.werks/3558 | 10 ++++++++++
ChangeLog | 1 +
doc/treasures/active_checks/check_mail | 15 ++++++++++++---
3 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/.werks/3558 b/.werks/3558
new file mode 100644
index 0000000..7eda279
--- /dev/null
+++ b/.werks/3558
@@ -0,0 +1,10 @@
+Title: check_mail: now able to process mail body with Content-Transfer-Encoding base64
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.4.0i1
+Date: 1468833224
+Class: feature
+
+When forwarding mails to the event console the plugin now
+decodes any base64 content back to human readable lines.
diff --git a/ChangeLog b/ChangeLog
index 6b2d57b..c35803a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -114,6 +114,7 @@
* 3554 Inotify: Added configurable levels for movedto, movefrom and move self
* 3706 hp_proliant_systeminfo, hp_proliant_mem, hp_proliant_da_phydrv: new inventory
plugins
* 3671 mssql_backup: Is now aware of backup types and outputs ages per backup type
+ * 3558 check_mail: now able to process mail body with Content-Transfer-Encoding
base64...
* 3073 FIX: windows agent: relative paths to mrpe scripts are now treated as relative
to the agent installation directory...
* 3061 FIX: mk_jolokia: Fixed debugging of the agent plugin
* 3074 FIX: windows agent: fixed incorrect values for 32-bit performance counters
diff --git a/doc/treasures/active_checks/check_mail
b/doc/treasures/active_checks/check_mail
index bdc2ba2..d88ae28 100755
--- a/doc/treasures/active_checks/check_mail
+++ b/doc/treasures/active_checks/check_mail
@@ -26,6 +26,7 @@
import sys, getopt, os, time, random, poplib, imaplib, email
import traceback, socket, re
+import base64
def parse_exception(e):
e = str(e)
@@ -296,7 +297,8 @@ def forward_to_ec(mails):
cur_time = syslog_time()
priority = 5 # OK
for index, msg in mails.items():
- subject = msg.get('Subject', 'None')
+ subject = msg.get('Subject', 'None')
+ encoding = msg.get('Content-Transfer-Encoding', 'None')
log_line = subject
# Now add the body to the event
if msg.is_multipart():
@@ -305,10 +307,17 @@ def forward_to_ec(mails):
content_type = part.get_content_type()
disposition = str(part.get('Content-Disposition'))
if content_type == 'text/plain' and 'attachment' not in
disposition:
- log_line += '|' + part.get_payload()[:body_limit]
+ payload = part.get_payload()
+ if encoding == "base64"
+ payload = base64.b64decode(payload)
+ log_line += '|' + payload[:body_limit]
break
else:
- log_line += '|' + msg.get_payload()[:body_limit]
+ payload = msg.get_payload()
+ if encoding == "base64"
+ payload = base64.b64decode(payload)
+ log_line += '|' + payload[:body_limit]
+
log_line = log_line.replace('\r\n', '\0')
log_line = log_line.replace('\n', '\0')