diff --git a/inventory_provider/snmp.py b/inventory_provider/snmp.py index a97df15d0b5aed2899cbdda0489a736d5f40153a..0c2c50461f886e5c719101de3622c3b1dad71c3b 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 %r at %r' % ( + pduErrorIndication, + 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) diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index b5c7a0c1061604d4ed37239f62988b1bcfb56a0a..3b7db454efc165a0ec5a5b20e2e8cb70f47ab5e2 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -416,5 +416,13 @@ def check_task_status(task_id): 'success': r.status == states.SUCCESS, } if r.result: - result['result'] = r.result + # TODO: only discovered this case by testing, is this the only one? + # ... otherwise need to pre-test json serialization + if isinstance(r.result, Exception): + result['result'] = { + 'error type': type(r.result).__name__, + 'message': str(r.result) + } + else: + result['result'] = r.result return result