Module: check_mk
Branch: master
Commit: 8af39c0824755eb8c77f325e31a98d427dd43fd4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8af39c0824755e…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Nov 24 12:51:25 2015 +0100
#2801 snmp text encoding: now able to decode cp437 encoded snmp strings
Furthermore the explicit decoding with the <i>decode_snmp_string</i> function
in
the checks <i>if</i>, <i>hr_fs</i> and
<i>printer_supply</i> has been removed.
Decoding of strings is now done before the data hits the check.
---
.werks/2801 | 12 ++++++++++++
ChangeLog | 1 +
checks/hr_fs | 2 +-
checks/if | 2 --
checks/printer_supply | 2 +-
modules/snmp.py | 16 +++++-----------
web/plugins/wato/check_mk_configuration.py | 1 +
7 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/.werks/2801 b/.werks/2801
new file mode 100644
index 0000000..63a119c
--- /dev/null
+++ b/.werks/2801
@@ -0,0 +1,12 @@
+Title: snmp text encoding: now able to decode cp437 encoded snmp strings
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i4
+Date: 1448365635
+Class: feature
+
+Furthermore the explicit decoding with the <i>decode_snmp_string</i> function
in
+the checks <i>if</i>, <i>hr_fs</i> and
<i>printer_supply</i> has been removed.
+
+Decoding of strings is now done before the data hits the check.
diff --git a/ChangeLog b/ChangeLog
index 9dace45..f6fd98a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -40,6 +40,7 @@
* 1304 mk_mysql: Agent plugin can now detect multiple instances running unter the
same user...
* 2797 netscaler_vserver: now also shows tftp servers and health state of
loadbalacing entities
* 2863 wagner_titanus_topsens: added support for more devices...
+ * 2801 snmp text encoding: now able to decode cp437 encoded snmp strings...
* 2660 FIX: fixed windows agent using the wrong working directory...
* 2664 FIX: ps: Speedup in situation with many matching processes...
* 2661 FIX: windows agent: fixed incomplete process list...
diff --git a/checks/hr_fs b/checks/hr_fs
index 2e9bb33..6489d84 100644
--- a/checks/hr_fs
+++ b/checks/hr_fs
@@ -27,7 +27,7 @@
# Juniper devices put information about the device into the
# field where we expect the mount point. Ugly. Remove that crap.
def fix_hr_fs_mountpoint(mp):
- mp = snmp_decode_string(mp).replace("\\", "/")
+ mp = mp.replace("\\", "/")
if "mounted on:" in mp:
return mp.rsplit(":",1)[-1].strip()
elif "Label:" in mp:
diff --git a/checks/if b/checks/if
index 5514c62..a3849ae 100644
--- a/checks/if
+++ b/checks/if
@@ -35,8 +35,6 @@ def if_convert_to_if64(info):
for line in info:
if saveint(line[0]) > 0: #Fix for switches with empty indexes
newinfo.append(line[0:8] + ['0'] + line[8:12] + ['0'] +
line[12:16] + line[1:2] + line[16:17])
- # Fix encoding of interface description
- newinfo[-1][1] = snmp_decode_string(newinfo[-1][1])
return newinfo
check_includes['if'] = [ "if.include" ]
diff --git a/checks/printer_supply b/checks/printer_supply
index 6c4ed20..e3788ae 100644
--- a/checks/printer_supply
+++ b/checks/printer_supply
@@ -68,7 +68,7 @@ def printer_supply_fix_infos(info):
colors = []
new_info = []
for index, line in enumerate(info):
- line_0 = snmp_decode_string(line[0]) # give chance for latin1->utf8 decoding
+ line_0 = line[0] # give chance for latin1->utf8 decoding
# For toners or drum units add the color (if available)
if line_0.startswith('Toner Cartridge') \
diff --git a/modules/snmp.py b/modules/snmp.py
index 81660a9..f14b91f 100644
--- a/modules/snmp.py
+++ b/modules/snmp.py
@@ -276,7 +276,7 @@ def compute_fetch_oid(oid, suboid, column):
def sanitize_snmp_encoding(columns):
for index, column in enumerate(columns):
- columns[index] = map(decode_incoming_string, column)
+ columns[index] = map(snmp_decode_string, column)
return columns
@@ -529,22 +529,16 @@ def get_stored_snmpwalk(hostname, oid):
else:
return rowinfo
-# Helper function to be used in checks. It applies a user-specified
-# character encoding in order to tranlate e.g. latin1 to utf8
def snmp_decode_string(text):
encoding = get_snmp_character_encoding(g_hostname)
if encoding:
- return text.decode(encoding).encode("utf-8")
+ return text.decode(encoding)
else:
- # Try to determine the current string encoding. In case a UTF-8
- # decoding fails, we decode latin1 and encode it as UTF-8 again.
- # When UTF-8 decoding works, we assume the string is already
- # encoded in UTF-8 as we expect it to be.
+ # Try to determine the current string encoding. In case a UTF-8 decoding fails,
we decode latin1.
try:
- text.decode('utf-8')
- return text
+ return text.decode('utf-8')
except:
- return text.decode('latin1').encode('utf-8')
+ return text.decode('latin1')
# .--Classic SNMP--------------------------------------------------------.
# | ____ _ _ ____ _ _ __ __ ____ |
diff --git a/web/plugins/wato/check_mk_configuration.py
b/web/plugins/wato/check_mk_configuration.py
index 71efa24..e2cdd83 100644
--- a/web/plugins/wato/check_mk_configuration.py
+++ b/web/plugins/wato/check_mk_configuration.py
@@ -1979,6 +1979,7 @@ register_rule(group,
choices = [
("utf-8", _("UTF-8") ),
("latin1" ,_("latin1")),
+ ("cp437" ,_("cp437")),
]
)),