Module: check_mk
Branch: master
Commit: 20f2763a812c5332a8d83e460987319a672a4369
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=20f2763a812c53…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jul 23 12:10:07 2015 +0200
Fixed UnicodeDecodeError when processing latin1 encoded agent data for piggyback
---
modules/check_mk_base.py | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 63bb080..048e873 100644
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -656,7 +656,7 @@ def translate_piggyback_host(sourcehost, backedhost):
# To make it possible to match umlauts we need to change the backendhost
# to a unicode string which can then be matched with regexes etc.
# We assume the incoming name is correctly encoded in UTF-8
- backedhost = backedhost.decode('utf-8')
+ backedhost = decode_incoming_string(backedhost)
# 3. Regular expression conversion
if "regex" in translation:
@@ -920,21 +920,22 @@ def parse_info(lines, hostname):
line = stripped_line
if encoding:
- try:
- line = line.decode(encoding)
- except:
- line = line.decode(fallback_agent_output_encoding)
+ line = decode_incoming_string(line, encoding)
else:
- try:
- line = line.decode('utf-8')
- except:
- line = line.decode(fallback_agent_output_encoding)
+ line = decode_incoming_string(line)
section.append(line.split(separator))
return info, piggybacked, persist, agent_cache_info
+def decode_incoming_string(s, encoding="utf-8"):
+ try:
+ return s.decode('utf-8')
+ except:
+ return s.decode(fallback_agent_output_encoding)
+
+
def cachefile_age(filename):
try:
return time.time() - os.stat(filename)[8]