我目前有一个脚本,它使用PySNMP轮询多个设备上的多个OID。它从文件中读取主机列表,对于某些主机,需要轮询3或4个OID,目前它正在按顺序执行此操作,因此为了使其更高效,我想做一个getbulk,所以我只轮询一次主机。
我已经对此做了多次搜索,并且可以找到许多使用pysnmp和snmp v2的示例,但找不到snmpv3的示例。我已经试过下面的测试脚本,但是它抛出了一个错误,所以有人能看看,让我知道我做错了什么吗?我的测试脚本如下所示:
from pysnmp.entity.rfc3413.oneliner import cmdgen
host='10.0.0.1'
incount = '.1.3.6.1.2.1.31.1.1.1.6.16'
outcount ='.1.3.6.1.2.1.31.1.1.1.10.16'
errorIndication, errorStatus, errorIndex,
varBindTable = cmdgen.CommandGenerator().bulkCmd(
UsmUserData('snmp_user', 'password', 'password',
authProtocol=usmHMACSHAAuthProtocol,
privProtocol=usmAesCfb128Protocol),
UdpTransportTarget((host, 161)),
0,
25,
(incount),
(outcount),
)
if errorIndication:
print errorIndication
else:
if errorStatus:
print '%s at %s\n' % (
errorStatus.prettyPrint(),
errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
)
else:
for varBindTableRow in varBindTable:
for name, val in varBindTableRow:
print '%s = %s' % (name.prettyPrint(), val.prettyPrint())
以及错误:
^{pr2}$它在第一个障碍上下降了很多,所以我显然语法错误了,但是就像我说的,我找不到snmpv3的例子。
谢谢
埃德
See regex in use here
(?<=(?<!@)\{)
正向查找确保前面的内容与以下内容匹配(?<!@)
反向查找确保前面的内容不匹配@
\{
按字面意思匹配{[^}]*
多次匹配除}
之外的任何字符(?=})
积极的前瞻性确保接下来的是}
字面意思结果:
使用此正则表达式:
负向后看以确保不
@{
,正向后看以确保{
,正向前看以确保}
在线试用here
相关问题 更多 >
编程相关推荐