首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python Set With PYSNMP

Python Set With PYSNMP
EN

Stack Overflow用户
提问于 2021-03-27 04:41:12
回答 2查看 229关注 0票数 0

我正在尝试使用SNMP get设置一个值。我已经测试过OID可以通过MIB浏览器写入。我可以使用另一个脚本来获取值,但是使用set就没有意义了。

代码语言:javascript
复制
from pysnmp.hlapi import *
engine = SnmpEngine()
community = CommunityData('public', mpModel=1)
transport = UdpTransportTarget(('target', 161))
context = ContextData()

# Your OID goes here.
identity = ObjectIdentity('.1.3.6.1.4.1.32050')

# If this was a string value, use OctetString() instead of Integer().
new_value = Integer(1)
type = ObjectType(identity, new_value)

# Setting lookupMib=False here because this example uses a numeric OID.
g = setCmd(engine, community, transport, context, identity, type, lookupMib=False)

errorIndication, errorStatus, errorIndex, varBinds = next(g)
print(errorIndication, varBinds)

我看到的错误

代码语言:javascript
复制
line 17, in <module>
    errorIndication, errorStatus, errorIndex, varBinds = next(g)

pysnmp.smi.error.SmiError: ObjectIdentity object not properly initialized
EN

回答 2

Stack Overflow用户

发布于 2021-03-27 20:07:54

context之后,setCmd期望ObjectType类的参数(例如,两个oid +context),但这里不是这种情况。在我看来,identity在这里是多余的。

试着这样做:

代码语言:javascript
复制
g = setCmd(engine, community, transport, context, type, lookupMib=False)

(顺便说一句,您应该避免调用变量type,这是一个预定义的python类。)

票数 0
EN

Stack Overflow用户

发布于 2021-03-28 22:16:40

在修复了前面答案中描述的问题之后,仅仅通过代码检查,它就会提示OID .1.3.6.1.4.1.32050不能是对象实例,因为它是企业分支。通过将identity设置为.1.3.6.1.2.1.1.5.0,您可以在不到一分钟的时间内证明这一点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66824056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档