Module: check_mk
Branch: master
Commit: 152bf4d0112c4f49d02cc5e4f1d193a5b5513e5b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=152bf4d0112c4f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Aug 10 10:49:47 2015 +0200
Fixed encoding of incoming SNMP data
---
checks/if_brocade | 2 +-
checks/if_lancom | 2 +-
modules/snmp.py | 11 +++++++++++
3 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/checks/if_brocade b/checks/if_brocade
index 7304160..56bb1c9 100644
--- a/checks/if_brocade
+++ b/checks/if_brocade
@@ -26,7 +26,7 @@
def fix_if_64_highspeed(info):
for line in info:
- if type(line[3]) == str: # not yet converted
+ if type(line[3]) in [ str, unicode ]: # not yet converted
line[3] = saveint(line[3]) * 1000000
def if_brocade_convert(info):
diff --git a/checks/if_lancom b/checks/if_lancom
index c3bd4c6..67bfc88 100644
--- a/checks/if_lancom
+++ b/checks/if_lancom
@@ -26,7 +26,7 @@
def fix_if_64_highspeed(info):
for line in info:
- if type(line[3]) == str: # not yet converted
+ if type(line[3]) in [ str, unicode ]: # not yet converted
line[3] = saveint(line[3]) * 1000000
def if_lancom_convert(info):
diff --git a/modules/snmp.py b/modules/snmp.py
index 185c65f..b0045cb 100644
--- a/modules/snmp.py
+++ b/modules/snmp.py
@@ -226,11 +226,22 @@ def get_snmp_table(hostname, ip, check_type, oid_info):
# the OIDs and watch out for gaps we need to fill with dummy values.
new_columns = sanitize_snmp_table_columns(columns)
+ # From all SNMP data sources (stored walk, classic SNMP, inline SNMP) we
+ # get normal python strings. But for Check_MK we need unicode strings now.
+ # Convert them by using the standard Check_MK approach for incoming data
+ new_columns = sanitize_snmp_encoding(new_columns)
+
info += construct_snmp_table_of_rows(new_columns)
return info
+def sanitize_snmp_encoding(columns):
+ for index, column in enumerate(columns):
+ columns[index] = map(decode_incoming_string, column)
+ return columns
+
+
def sanitize_snmp_table_columns(columns):
# First compute the complete list of end-oids appearing in the output
# by looping all results and putting the endoids to a flat list