首先,我不熟悉Python和PySNMP。我试图将网络设备列表传递给bulkCmd,以获取所有物理接口的信息。在
目前它只收集第一个接口,然后移动到列表中的下一个网络设备。我用字典法和maxCalls进行了修改,重复了一下,但没有任何区别。在
我已经成功地轮询了所有接口时,发送一个单一的bulkCmd到单个网络设备。在
代码:
from pysnmp.hlapi import *
routers = ["router1", "router2"]
#adds routers to getCmd and bulkCmd
def snmpquery (hostip):
errorIndication, errorStatus, errorIndex, varBinds = next (
bulkCmd(SnmpEngine(),
CommunityData('communitystring'),
UdpTransportTarget((hostip, 161)),
ContextData(),
0, 50,
ObjectType(ObjectIdentity('IF-MIB', 'ifDescr')),
ObjectType(ObjectIdentity('IF-MIB', 'ifAlias')),
ObjectType(ObjectIdentity('IF-MIB', 'ifOperStatus')),
lexicographicMode=True
)
)
# Check for errors and print out results
if errorIndication:
print(errorIndication)
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind]))
# calls snmpquery for all routers in list
for router in routers:
snmpquery(router)
输出:
^{pr2}$
您可以在程序确认的文本视图上调用
setCustomTitle()
例如:
相关问题 更多 >
编程相关推荐