Question

I have 2 almost identical method calls and they return different results

from pyasn1.type import univ
from pysnmp.entity.rfc3413.oneliner import cmdgen
def printResult(*result):
    print str(result)

print cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('agent', 'public', 1), cmdgen.UdpTransportTarget(('172.16.1.15', 161)), (univ.ObjectIdentifier(("1.3.6.1.4.1.5528.100.4.1.1.1.10"),)))

getCmdGen = cmdgen.AsynCommandGenerator()
getCmdGen.nextCmd(cmdgen.CommunityData('agent', 'public', 1), cmdgen.UdpTransportTarget(('172.16.1.15', 161)), (univ.ObjectIdentifier(("1.3.6.1.4.1.5528.100.4.1.1.1.10")),), (printResult, (None,)))
getCmdGen.snmpEngine.transportDispatcher.runDispatcher()

This prints out:

(None, Integer('noError'), Integer(0), [[(ObjectName(1.3.6.1.4.1.5528.100.4.1.1.1.10.1095346743), Counter32(1095346743))], [(ObjectName(1.3.6.1.4.1.5528.100.4.1.1.1.10.1382714849), Counter32(1382714849))]])
(695125368, None, Integer('noError'), Integer(0), [[(ObjectName(1.3.6.1.4.1.5528.100.4.1.1.1.10.1095346743), Counter32(1095346743))]], None)

And if you look closely you'll see that the first one correctly returns 2 items and the second one only returns 1:

[[(ObjectName(1.3.6.1.4.1.5528.100.4.1.1.1.10.1095346743), Counter32(1095346743))], [(ObjectName(1.3.6.1.4.1.5528.100.4.1.1.1.10.1382714849), Counter32(1382714849))]]

vs

[[(ObjectName(1.3.6.1.4.1.5528.100.4.1.1.1.10.1095346743), Counter32(1095346743))]]

Edit. Found out why I got a weird error in some cases but that didn't fix the rest

Was it helpful?

Solution

If the callback function returns nothing it will stop. Only if the callback function returns 1 (or something that evaluates to True) the next value will be requested.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top