Module: check_mk
Branch: master
Commit: 8f40186b6e89fb877b61337eb3d5ea29f0727562
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8f40186b6e89fb…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jun 29 12:53:39 2015 +0200
#2378 FIX if: Now fixing encoding in interface descriptions according to rule
You can now use the rule "Output text coding settings for SNMP devices" to
fix the encoding of the interface descriptions reported by devices.
---
.werks/2378 | 11 +++++++++++
ChangeLog | 1 +
checks/if | 2 ++
modules/snmp.py | 10 +++++++++-
4 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/.werks/2378 b/.werks/2378
new file mode 100644
index 0000000..f81cae0
--- /dev/null
+++ b/.werks/2378
@@ -0,0 +1,11 @@
+Title: if: Now fixing encoding in interface descriptions according to rule
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.7i3
+Date: 1435575163
+
+You can now use the rule "Output text coding settings for SNMP devices" to
+fix the encoding of the interface descriptions reported by devices.
diff --git a/ChangeLog b/ChangeLog
index 3d73105..6c79657 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,7 @@
* 2352 FIX: FreeBSD Agent: Removed statgrab cpu section because there is a dedicated
cpu section...
* 2359 FIX: adva_fsp_if: Use more reliable SNMP table, avoids sporadic problems...
* 2360 FIX: esx_vsphere_vm.snapshot: Fix output of snapshot age in performance data
and graph...
+ * 2378 FIX: if: Now fixing encoding in interface descriptions according to rule...
Multisite:
* 2314 FIX: Availability: fixed exception when grouping by host or service group
diff --git a/checks/if b/checks/if
index a3849ae..5514c62 100644
--- a/checks/if
+++ b/checks/if
@@ -35,6 +35,8 @@ 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/modules/snmp.py b/modules/snmp.py
index 79ccbc8..44cad0f 100644
--- a/modules/snmp.py
+++ b/modules/snmp.py
@@ -430,7 +430,15 @@ def snmp_decode_string(text):
if encoding:
return text.decode(encoding).encode("utf-8")
else:
- return text.decode('latin1').encode('utf-8')
+ # 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:
+ text.decode('utf-8')
+ return text
+ except:
+ return text.decode('latin1').encode('utf-8')
# .--Classic SNMP--------------------------------------------------------.
# | ____ _ _ ____ _ _ __ __ ____ |