如何同时对多个 OID 执行 SNMP 命令?
How can I perform SNMP command for several OIDs at once?
我有一个 MIB table,我希望能够对其进行编辑。下面的代码很好地完成了任务。我想知道的是,是否有一种方法可以在一个设置命令中完成所有操作
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)
我试图将 ObjectType 转换为 (ObjectIdentity(OID), Value) 对的元组,但我遇到了一些错误。是否可以将所有 "standalone" set 命令减少为一组 4 对命令?
顺便说一下,代码块顶部的 if 用于设置 OID 值,以便我将被设置到 table
中的右行
来自pysnmp准你surely can:
...
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)
希望您的 SNMP 代理也支持。
我有一个 MIB table,我希望能够对其进行编辑。下面的代码很好地完成了任务。我想知道的是,是否有一种方法可以在一个设置命令中完成所有操作
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)
我试图将 ObjectType 转换为 (ObjectIdentity(OID), Value) 对的元组,但我遇到了一些错误。是否可以将所有 "standalone" set 命令减少为一组 4 对命令?
顺便说一下,代码块顶部的 if 用于设置 OID 值,以便我将被设置到 table
中的右行来自pysnmp准你surely can:
...
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)
希望您的 SNMP 代理也支持。