Question

How is it possible to implement getting of SNMP table in Python + NetSnmp?

Simple set and get for Python + NetSNMP work fine:

myArgs = ['enterprises', 'set', '27142.1.1.20.1.2.1.1.1', '1', 'INTEGER']
var = netsnmp.Varbind(*myArgs)
res = netsnmp.snmpset(var, Version = 2, DestHost = 192.168.1.2, Community='private')

I would like to know how to implement the following NetSNMP command in Python:

snmptable -v 2c -c public -Ob 172.16.67.240 .1.3.6.1.2.1.2.2

Thanks

Was it helpful?

Solution

Tried to solve it unsuccessfully with getBulk in Python. It works quite strange returning only part of the table irrespective of getBulk parameters. Solved it by directly invoking Linux shell from Python. Got the correct table in out variable:

import subprocess
p = subprocess.Popen(['snmptable', '-v', '2c', '-c', 'public', '-Ob', '172.16.67.240',    '.1.3.6.1.2.1.2.2'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print out

I would appreciate any better ideas!

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