我有以下代码,我一直在使用 pysnmp 进行轮询。到目前为止,它一直用于走路,但我希望能够获得特定的索引。例如我想投票HOST-RESOURCES-MIB::hrSWRunPerfMem.999
我可以使用它来成功取回 hrSWRunPerfMem 中的所有内容getCounter('1.1.1.1', 'public', 'HOST-RESOURCES-MIB', 'hrSWRunPerfMem')
但是,一旦我尝试包含索引号getCounter('1.1.1.1', 'public', 'HOST-RESOURCES-MIB', 'hrSWRunPerfMem', indexNum=999)
,我总是会得到varBindTable == []
from pysnmp.entity.rfc3413.oneliner import cmdgen
from pysnmp.smi import builder, view
def getCounter(ip, community, mibName, counterName, indexNum=None):
cmdGen = cmdgen.CommandGenerator()
mibBuilder = cmdGen.mibViewController.mibBuilder
mibPath = mibBuilder.getMibSources() + (builder.DirMibSource("/path/to/mibs"),)
mibBuilder.setMibSources(*mibPath)
mibBuilder.loadModules(mibName)
mibView = view.MibViewController(mibBuilder)
retList = []
if indexNum is not None:
mibVariable = cmdgen.MibVariable(mibName, counterName, int(indexNum))
else:
mibVariable = cmdgen.MibVariable(mibName, counterName)
errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd(cmdgen.CommunityData('test-agent', community),
cmdgen.UdpTransportTarget((ip, snmpPort)),
mibVariable)
有没有人对如何使用 pysnmp 轮询特定索引有所了解?