Reputation: 788
For better performance I have to migrate my bash script to python script... So I begin to use pysnmp and I'm facing an issue about output format...
You will find below netsnmp request:
snmpwalk -v 2c -c mycommunity 192.168.2.20 1.3.6.1.4.1.9.9.387.1.7.8.1.3
The same thing with pysnmp:
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(
cmdgen.CommunityData('mycommunity'),
cmdgen.UdpTransportTarget(('192.168.2.20', 161)),
'1.3.6.1.4.1.9.9.387.1.7.8.1.3'
)
With netsnmp I can change the output format like this:
snmpwalk -v 2c -Oa -c mycommunity 192.168.2.20 1.3.6.1.4.1.9.9.387.1.7.8.1.3
But I'm not able to change output format with pysnmp. How I can do it?
Upvotes: 3
Views: 521
Reputation: 788
I didn't use Pooh's solution but it helped me to find what to do:
val.prettyPrint().encode("hex")
Upvotes: 1
Reputation: 276
Response values are all in the VarBindTable so you could format it as you wish. For example:
>>> varBindTable
[ [(ObjectName('1.3.6.1.2.1.1.1.0'), OctetString('SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'))] ]
>>> varBindTable[0][0][1]
OctetString('SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m')
>>> varBindTable[0][0][1].asOctets()
'SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m'
>>> varBinds[0][1].asOctets()
There's no built-in option in pysnmp to modify output format to some pre-defined settings.
Upvotes: 2