From 62af98e517e0df0980c2ad78885cbbab675b2ad4 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Sat, 9 Feb 2019 16:49:34 +0100
Subject: [PATCH] added snmp response error descriptions

---
 inventory_provider/snmp.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/inventory_provider/snmp.py b/inventory_provider/snmp.py
index a97df15d..8bbcc93c 100644
--- a/inventory_provider/snmp.py
+++ b/inventory_provider/snmp.py
@@ -57,9 +57,19 @@ def walk(agent_hostname, community, base_oid):  # pragma: no cover
             lexicographicMode=False,
             lookupNames=True,
             lookupValues=True):
-        assert not engineErrorIndication
-        assert not pduErrorIndication
-        assert errorIndex == 0
+
+        # cf. http://snmplabs.com/
+        #       pysnmp/examples/hlapi/asyncore/sync/contents.html
+        assert not engineErrorIndication, (
+            'snmp response engine error indication: %r'
+            % str(engineErrorIndication))
+        assert not pduErrorIndication, 'snmp response pdu error %s at %s' % (
+            pduErrorIndication.prettyPrint(),
+            errorIndex and varBinds[int(errorIndex) - 1][0] or '?')
+        assert errorIndex == 0, (
+            'sanity failure: errorIndex != 0, '
+            'but no error indication')
+
         # varBinds = [
         #     rfc1902.ObjectType(rfc1902.ObjectIdentity(x[0]),x[1])
         #         .resolveWithMib(mibViewController)
-- 
GitLab