0
我試圖利用PySNMP的監控系統的陣列,但我想通過它的對象的動態列表每個連接查詢提出,象下面這樣:通PySNMP getCmd的對象類型
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData(self.device.getSNMPCommunity(), mpModel=0),
UdpTransportTarget((self.device.getHost(),
self.device.getSNMPPort()),self.device.getSNMPTimeout(),int(1)),
ContextData(),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysName', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysUpTime', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysContact', 0)),
)
)
相反,我希望能夠做到像下面這樣:
for sensor in self.sensors:
if(sensor.sensor_type == 'snmp'):
if(sensor.snmp_oid):
Sensors.append(ObjectType(ObjectIdentity(sensor.snmp_oid)))
else:
Sensors.append(
ObjectType(
ObjectIdentity(
sensor.snmp_mib,
sensor.snmp_object,
sensor.snmp_field
).addAsn1MibSource('file:///usr/share/snmp/mibs')))
然後調用
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
CommunityData(device_to_proc.snmp_community, mpModel=0),
UdpTransportTarget((device_to_proc.host, int(device_to_proc.snmp_port)),int(device_to_proc.snmp_timeout),int(1)),
ContextData(),
Sensors
)
)
有沒有differen我錯過了pysnmp的函數,還是有更好的方法來完成這個任務?
哇,我很明顯是一個Python noob,這是訣竅!很棒,謝謝。 –