首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PySNMP添加自定义MIB

PySNMP添加自定义MIB
EN

Stack Overflow用户
提问于 2018-08-22 05:21:32
回答 2查看 2.1K关注 0票数 0

我一直在尝试让自定义MIB工作,但没有成功。

理想情况下,我希望从ASN1源中获得MIB的完整列表,但由于失败,我尝试了多种选择。

我已经下载了IF-MIB和IANAifType-MIB,并复制了基于文本和PySNMP格式的编译版本,但似乎都没有读到。未编译.py文件。

代码语言:javascript
运行
复制
2018-08-21 21:14:18,442 pysmi: running pysmi version 0.3.1
2018-08-21 21:14:18,442 pysmi: debug category 'searcher' enabled
2018-08-21 21:14:18,442 pysmi: debug category 'reader' enabled
2018-08-21 21:14:18,442 pysmi: debug category 'compiler' enabled
2018-08-21 21:14:19,595 pysmi: current MIB source(s): FileReader{"/usr/share/snmp/mibs"}, FileReader{"/usr/share/mibs"}
2018-08-21 21:14:19,595 pysmi: current compiled MIBs location(s): StubSearcher
2018-08-21 21:14:19,595 pysmi: current compiled MIBs location(s): StubSearcher, PyPackageSearcher{"/usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs"}, PyPackageSearcher{"/usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs/instances"}, PyPackageSearcher{"pysnmp_mibs"}
2018-08-21 21:14:19,595 pysmi: current MIB borrower(s): 
2018-08-21 21:14:20,343 pysmi: current MIB source(s): FileReader{"/usr/share/snmp/mibs"}, FileReader{"/usr/share/mibs"}
2018-08-21 21:14:20,343 pysmi: current compiled MIBs location(s): StubSearcher
2018-08-21 21:14:20,343 pysmi: current compiled MIBs location(s): StubSearcher, PyPackageSearcher{"/usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs"}, PyPackageSearcher{"/usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs/instances"}, PyPackageSearcher{"pysnmp_mibs"}
2018-08-21 21:14:20,343 pysmi: current MIB borrower(s): 
2018-08-21 21:14:22,527 pysmi: current MIB source(s): FileReader{"/usr/share/snmp/mibs"}, FileReader{"/usr/share/mibs"}
2018-08-21 21:14:22,527 pysmi: current compiled MIBs location(s): StubSearcher
2018-08-21 21:14:22,527 pysmi: current compiled MIBs location(s): StubSearcher, PyPackageSearcher{"/usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs"}, PyPackageSearcher{"/usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs/instances"}, PyPackageSearcher{"pysnmp_mibs"}
2018-08-21 21:14:22,527 pysmi: current MIB borrower(s): 


:~$ ls /usr/share/snmp/mibs/I*
/usr/share/snmp/mibs/IANA-ADDRESS-FAMILY-NUMBERS-MIB.txt
/usr/share/snmp/mibs/IANAifType-MIB
/usr/share/snmp/mibs/IANAifType-MIB.py
/usr/share/snmp/mibs/IANAifType-MIB.txt
/usr/share/snmp/mibs/IANA-LANGUAGE-MIB.txt
/usr/share/snmp/mibs/IANA-RTPROTO-MIB.txt
/usr/share/snmp/mibs/IF-MIB
/usr/share/snmp/mibs/IF-MIB.py

:~$ ls /usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs/I*     
/usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs/IANAifType-MIB.py
/usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs/IF-MIB.py
/usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs/INET-ADDRESS-MIB.py

:~$ ls /usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs/__pycache__/I*
/usr/local/lib/python3.5/dist-packages/pysnmp/smi/mibs/__pycache__/INET-ADDRESS-MIB.cpython-35.pyc

我尝试使用以下内容从snmplabs站点导入:

代码语言:javascript
运行
复制
from pysnmp.smi import builder 

# load mibs
MIBDIR = 'http://mibs.snmplabs.com/asn1/@mib@'
mibBuilder = builder.MibBuilder()
mibSources = mibBuilder.getMibSources() + (builder.DirMibSource(MIBDIR),)
mibBuilder.setMibSources(*mibSources)

我还尝试将.addAsn1MibSource('http://mibs.snmplabs.com/asn1/@mib@')附加到cmdgen上我的OID的末尾。

我仍然得到像SNMPv2-SMI::mib-2.2.2.1.2.27 = Ethernet0/1/0.101这样的输出,而不是IF-MIB::ifDescr.27 = STRING: Ethernet0/1/0.101。我还能做些什么来找出我做错了什么?

EN

Stack Overflow用户

发布于 2020-12-15 14:35:05

@Ilya Etingof

对不起,由于没有足够的声誉,无法回复评论................你能为上面的答案提供一个例子吗?我终于明白了

pysnmp.smi.error.SmiError: ObjectType object not fully initialized

ObjectType(ObjectIdentity('1.3.6.1.2.1.25.2.3').loadMibs('HOST-RESOURCES-MIB'))

到目前为止,我遵循的步骤是

代码语言:javascript
运行
复制
from pysnmp.hlapi import ObjectIdentity, ObjectType


mibBuilder = builder.MibBuilder()
mibBuilder.addMibSources(builder.DirMibSource('C://Users//Downloads//HOST-RESOURCES-MIB.txt'))

errorIndication, errorStatus, errorIndex, \
varBindTable = cmdgen.CommandGenerator().bulkCmd(
    cmdgen.CommunityData('test'),
    cmdgen.UdpTransportTarget(('test-ip', 161)),
    0,
    1,
    ObjectType(ObjectIdentity('1.3.6.1.2.1.25.2.3').loadMibs('HOST-RESOURCES-MIB'))
)

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()))
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51956875

复制
相关文章

相似问题

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