[英]How can I perform SNMP command for several OIDs at once?
I have a MIB table that I want to be able to edit. 我有一个要编辑的MIB表。 The following code performs the task well. 以下代码可以很好地完成任务。 What I would like to know is if there is a way to do it all in one set command 我想知道的是,是否有一种方法可以在一个set命令中完成所有操作
main_Status_OID = '1.3.6.1.4.1.4515.1.3.23.1.1.1.0'
# Set the OIDs according to the Level argument
if Level == 1:
Server_IP_OID = '1.3.6.1.4.1.4515.1.3.23.1.1.2.1.2.1'
Secret_OID = '1.3.6.1.4.1.4515.1.3.23.1.1.2.1.6.1'
Status_OID = '1.3.6.1.4.1.4515.1.3.23.1.1.2.1.4.1'
elif Level == 2:
Server_IP_OID = '1.3.6.1.4.1.4515.1.3.23.1.1.2.1.2.2'
Secret_OID = '1.3.6.1.4.1.4515.1.3.23.1.1.2.1.6.2'
Status_OID = '1.3.6.1.4.1.4515.1.3.23.1.1.2.1.4.2'
else:
return -1
# Set the Main RADIUS Authentication Enable/Disable field
g = setCmd(SnmpEngine(),
CommunityData('admin', mpModel=1),
UdpTransportTarget((Device_IP, 161)),
ContextData(),
ObjectType(ObjectIdentity(main_Status_OID), Integer32(main_Status)))
next(g)
# Set the IP Address field of the Primary/Secondary RADIUS Server
g = setCmd(SnmpEngine(),
CommunityData('admin', mpModel=1),
UdpTransportTarget((Device_IP, 161)),
ContextData(),
ObjectType(ObjectIdentity(Server_IP_OID), IpAddress(Server_IP)))
next(g)
# Set the Shared Secret field of the Primary/Secondary RADIUS Server
g = setCmd(SnmpEngine(),
CommunityData('admin', mpModel=1),
UdpTransportTarget((Device_IP, 161)),
ContextData(),
ObjectType(ObjectIdentity(Secret_OID), OctetString(Secret)))
next(g)
# Set the Admin Status field of the Primary/Secondary RADIUS Server
g = setCmd(SnmpEngine(),
CommunityData('admin', mpModel=1),
UdpTransportTarget((Device_IP, 161)),
ContextData(),
ObjectType(ObjectIdentity(Status_OID), Integer32(Status)))
next(g)
I have tried to turn the ObjectType into a tuple of (ObjectIdentity(OID), Value) pairs but I got some errors. 我试图将ObjectType转换为(ObjectIdentity(OID),Value)对的元组,但是遇到了一些错误。 Is it possible to reduce all the "standalone" set commands into one set commands of 4 pairs ? 是否可以将所有“独立”设置命令简化为4对设置命令?
By the way, the if at the top of the code block is used to set the OID values so that I would be set to the right row in the table 顺便说一句,使用代码块顶部的if设置OID值,以便将我设置为表中的右行
From pysnmp prospective you surely can : 从pysnmp准用户肯定可以 :
...
g = setCmd(SnmpEngine(),
CommunityData('admin'),
UdpTransportTarget((Device_IP, 161)),
ContextData(),
ObjectType(ObjectIdentity(main_Status_OID), Integer32(main_Status))),
ObjectType(ObjectIdentity(Server_IP_OID), IpAddress(Server_IP))),
ObjectType(ObjectIdentity(Status_OID), Integer32(Status))
)
next(g)
Hopefully, your SNMP agent supports that as well. 希望您的SNMP代理也支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.