Python SNMP GetBulk - 多个 OID
我需要使用 PySNMP 的 GetBulk 实现来查询表 OID 列表。我能够让它查询 1 个表 OID,但无法让它从列表中读取表 OID。我做错了什么?请帮忙。
from pysnmp.entity.rfc3413.oneliner import cmdgen
errorIndication, errorStatus, errorIndex, \
varBindTable = cmdgen.CommandGenerator().bulkCmd(
cmdgen.CommunityData('test-agent', 'public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
0,
25,
(1,3,6,1,2,1,4,20) # ipAddrTable OID . This works fine.
# I also want to query .1.3.6.1.2.1.4.21 ipRouteTable in the same command
# Putting is as ( (1,3,6,1,2,1,4,20), (1,3,6,1,2,1,4,21) ) gives an error
)
if errorIndication:
print errorIndication
else:
if errorStatus:
print '%s at %s\n' % (
errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
)
else:
for varBindTableRow in varBindTable:
for name, val in varBindTableRow:
print '%s = %s' % (name.prettyPrint(), val.prettyPrint())
I need to use PySNMP's GetBulk implementation to query for a list of Table OIDs. I was able to get it to query for 1 Table OID, but unable to get it to read the Table OIDs from a list. What am I doing wrong? Please help.
from pysnmp.entity.rfc3413.oneliner import cmdgen
errorIndication, errorStatus, errorIndex, \
varBindTable = cmdgen.CommandGenerator().bulkCmd(
cmdgen.CommunityData('test-agent', 'public'),
cmdgen.UdpTransportTarget(('localhost', 161)),
0,
25,
(1,3,6,1,2,1,4,20) # ipAddrTable OID . This works fine.
# I also want to query .1.3.6.1.2.1.4.21 ipRouteTable in the same command
# Putting is as ( (1,3,6,1,2,1,4,20), (1,3,6,1,2,1,4,21) ) gives an error
)
if errorIndication:
print errorIndication
else:
if errorStatus:
print '%s at %s\n' % (
errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
)
else:
for varBindTableRow in varBindTable:
for name, val in varBindTableRow:
print '%s = %s' % (name.prettyPrint(), val.prettyPrint())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这就是你想要的...
编辑
使用
我收到...
I think this is what you want...
EDIT
Using
I receive...
试试这个......它可能会起作用
Try this...it might work