문제

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

도움이 되었습니까?

해결책

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!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top