Module: check_mk
Branch: master
Commit: 97808d280054fa3ff26ec4264758d9971ab9253b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=97808d280054fa…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri May 15 15:09:55 2015 +0200
Fixed handling of duplicate oids in case of using SNMPv3 contextes
---
modules/snmp.py | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/modules/snmp.py b/modules/snmp.py
index c312e63..79ccbc8 100644
--- a/modules/snmp.py
+++ b/modules/snmp.py
@@ -154,6 +154,7 @@ def get_snmp_table(hostname, ip, check_type, oid_info):
if opt_use_snmp_walk or is_usewalk_host(hostname):
rowinfo = get_stored_snmpwalk(hostname, fetchoid)
else:
+ added_oids = set([])
rowinfo = []
if is_snmpv3_host(hostname):
snmp_contexts = snmpv3_contexts_of(hostname, check_type)
@@ -162,18 +163,25 @@ def get_snmp_table(hostname, ip, check_type, oid_info):
for context_name in snmp_contexts:
if has_inline_snmp and use_inline_snmp:
- rowinfo += inline_snmpwalk_on_suboid(hostname, check_type,
fetchoid, oid,
+ rows = inline_snmpwalk_on_suboid(hostname, check_type, fetchoid,
oid,
context_name=context_name)
else:
- rowinfo += snmpwalk_on_suboid(hostname, ip, fetchoid,
context_name=context_name)
-
- # I've seen a broken device (Mikrotik Router), that broke after an
- # update to RouterOS v6.22. It would return 9 time the same OID when
- # .1.3.6.1.2.1.1.1.0 was being walked. We try to detect these situations
- # by removing any duplicate OID information
- if len(rowinfo) > 1 and rowinfo[0][0] == rowinfo[1][0]:
- vverbose("Detected broken SNMP agent. Ignoring duplicate OID
%s.\n" % rowinfo[0][0])
- rowinfo = rowinfo[:1]
+ rows = snmpwalk_on_suboid(hostname, ip, fetchoid,
context_name=context_name)
+
+ # I've seen a broken device (Mikrotik Router), that broke after
an
+ # update to RouterOS v6.22. It would return 9 time the same OID when
+ # .1.3.6.1.2.1.1.1.0 was being walked. We try to detect these
situations
+ # by removing any duplicate OID information
+ if len(rows) > 1 and rows[0][0] == rows[1][0]:
+ vverbose("Detected broken SNMP agent. Ignoring duplicate OID
%s.\n" % rows[0][0])
+ rows = rows[:1]
+
+ for row_oid, val in rows:
+ if row_oid in added_oids:
+ vverbose("Duplicate OID found: %s (%s)\n" %
(row_oid, val))
+ else:
+ rowinfo.append((row_oid, val))
+ added_oids.add(row_oid)
columns.append((fetchoid, rowinfo))
number_rows = len(rowinfo)
@@ -409,7 +417,6 @@ def get_stored_snmpwalk(hostname, oid):
rowinfo = collect_until(current, -1)
rowinfo.reverse()
rowinfo += collect_until(current + 1, 1)
- # import pprint ; pprint.pprint(rowinfo)
if dot_star:
return [ rowinfo[0] ]