pysnmp
pysnmp copied to clipboard
caused by <class 'pyasn1.error.PyAsn1Error'>: Duplicate name tftp
Hello!
The Citrix NetScaler MIB (NS-MIB-smiv2.mib) has the string:
EntityProtocolType ::=
INTEGER{ http(0), ftp(1), tcp(2), udp(3), sslBridge(4), monitor(5), monitorUdp(6), nntp(7), httpserver(8), httpclient(9), rpcserver(10), rpcclient(11), nat(12), any(13), ssl(14), dns(16), adns(17), snmp(18), ha(19), monitorPing(20), sslOtherTcp(21), aaa(22), secureMonitor(23), sslvpnUdp(24), rip(25), dnsClient(26), rpcServer(27), rpcClient(28), dhcrpa(36), sipudp(39), siptcp(40), siptls(41), dnstcp(48), adnstcp(49), rtsp(50), push(52), sslPush(53), dhcpClient(54), radius(55), rdp(61), mysql(62), mssql(63), diameter(73), sslDiameter(74), tftp(75), tftp(90), pptp(91), gre(92), fix(95), sslFix(96), userTcp(104), userSslTcp(105), serviceUnknown(112) }
It tftp listed twice tftp(75) and tftp(90).
Compilation passes without errors:
[root@mb app]# mibdump.py --destination-format=pysnmp --debug=reader NS-MIB-smiv2
2019-02-08 11:49:14,744 pysmi: running pysmi version 0.3.2
2019-02-08 11:49:14,744 pysmi: debug category 'reader' enabled
Source MIB repositories: file:///usr/share/snmp/mibs, http://mibs.snmplabs.com/asn1/@mib@
Borrow missing/failed MIBs from: http://mibs.snmplabs.com/pysnmp/notexts/@mib@
Existing/compiled MIB locations: pysnmp.smi.mibs, pysnmp_mibs
Compiled MIBs destination directory: /root/.pysnmp/mibs
MIBs excluded from code generation: INET-ADDRESS-MIB, PYSNMP-USM-MIB, RFC-1212, RFC-1215, RFC1065-SMI, RFC1155-SMI, RFC1158-MIB, RFC1213-MIB, SNMP-FRAMEWORK-MIB, SNMP-TARGET-MIB, SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC, SNMPv2-TM, TRANSPORT-ADDRESS-MIB
MIBs to compile: NS-MIB-smiv2
Destination format: pysnmp
Parser grammar cache directory: not used
Also compile all relevant MIBs: yes
Rebuild MIBs regardless of age: no
Dry run mode: no
Create/update MIBs: yes
Byte-compile Python modules: yes (optimization level no)
Ignore compilation errors: no
Generate OID->MIB index: no
Generate texts in MIBs: no
Keep original texts layout: no
Try various file names while searching for MIB module: yes
2019-02-08 11:49:14,948 pysmi: recursively looking for MIB NS-MIB-smiv2
2019-02-08 11:49:14,953 pysmi: trying MIB /usr/share/snmp/mibs/NS-MIB-smiv2
2019-02-08 11:49:14,953 pysmi: trying MIB /usr/share/snmp/mibs/NS-MIB-smiv2.txt
2019-02-08 11:49:14,953 pysmi: trying MIB /usr/share/snmp/mibs/NS-MIB-smiv2.mib
2019-02-08 11:49:14,954 pysmi: source MIB /usr/share/snmp/mibs/NS-MIB-smiv2.mib mtime is Fri, 08 Feb 2019 08:43:16 GMT, fetching data...
2019-02-08 11:49:17,101 pysmi: recursively looking for MIB INET-ADDRESS-MIB
2019-02-08 11:49:17,104 pysmi: trying MIB /usr/share/snmp/mibs/INET-ADDRESS-MIB
2019-02-08 11:49:17,104 pysmi: trying MIB /usr/share/snmp/mibs/INET-ADDRESS-MIB.txt
2019-02-08 11:49:17,104 pysmi: source MIB /usr/share/snmp/mibs/INET-ADDRESS-MIB.txt mtime is Tue, 30 Oct 2018 23:52:56 GMT, fetching data...
2019-02-08 11:49:17,115 pysmi: recursively looking for MIB IPV6-TC
2019-02-08 11:49:17,118 pysmi: trying MIB /usr/share/snmp/mibs/IPV6-TC
2019-02-08 11:49:17,118 pysmi: trying MIB /usr/share/snmp/mibs/IPV6-TC.txt
2019-02-08 11:49:17,118 pysmi: source MIB /usr/share/snmp/mibs/IPV6-TC.txt mtime is Tue, 30 Oct 2018 23:52:56 GMT, fetching data...
2019-02-08 11:49:17,123 pysmi: recursively looking for MIB SNMPv2-CONF
2019-02-08 11:49:17,125 pysmi: trying MIB /usr/share/snmp/mibs/SNMPv2-CONF
2019-02-08 11:49:17,125 pysmi: trying MIB /usr/share/snmp/mibs/SNMPv2-CONF.txt
2019-02-08 11:49:17,125 pysmi: source MIB /usr/share/snmp/mibs/SNMPv2-CONF.txt mtime is Tue, 30 Oct 2018 23:52:55 GMT, fetching data...
2019-02-08 11:49:17,128 pysmi: recursively looking for MIB SNMPv2-SMI
2019-02-08 11:49:17,130 pysmi: trying MIB /usr/share/snmp/mibs/SNMPv2-SMI
2019-02-08 11:49:17,131 pysmi: trying MIB /usr/share/snmp/mibs/SNMPv2-SMI.txt
2019-02-08 11:49:17,131 pysmi: source MIB /usr/share/snmp/mibs/SNMPv2-SMI.txt mtime is Tue, 30 Oct 2018 23:52:55 GMT, fetching data...
2019-02-08 11:49:17,140 pysmi: recursively looking for MIB SNMPv2-TC
2019-02-08 11:49:17,143 pysmi: trying MIB /usr/share/snmp/mibs/SNMPv2-TC
2019-02-08 11:49:17,143 pysmi: trying MIB /usr/share/snmp/mibs/SNMPv2-TC.txt
2019-02-08 11:49:17,143 pysmi: source MIB /usr/share/snmp/mibs/SNMPv2-TC.txt mtime is Tue, 30 Oct 2018 23:52:55 GMT, fetching data...
Created/updated MIBs:
Pre-compiled MIBs borrowed:
Up to date MIBs: INET-ADDRESS-MIB, IPV6-TC, NS-ROOT-MIB, SNMPv2-CONF, SNMPv2-SMI, SNMPv2-TC
Missing source MIBs:
Ignored MIBs:
Failed MIBs:
I use:
[root@mb app]# cat aaa2.py
from pysnmp.smi import builder, view, rfc1902, error
mibBuilder = builder.MibBuilder()
mibView = view.MibViewController(mibBuilder)
mibVar = rfc1902.ObjectIdentity('NS-ROOT-MIB','sysGateway',1).resolveWithMib(mibView)
[root@mb app]# python aaa2.py
Traceback (most recent call last):
File "aaa2.py", line 9, in <module>
mibVar = rfc1902.ObjectIdentity('NS-ROOT-MIB','sysGateway',1).resolveWithMib(mibView)
File "/usr/lib/python2.7/site-packages/pysnmp/smi/rfc1902.py", line 481, in resolveWithMib
self.__modName, self.__symName
File "/usr/lib/python2.7/site-packages/pysnmp/smi/builder.py", line 406, in importSymbols
self.loadModules(modName, **userCtx)
File "/usr/lib/python2.7/site-packages/pysnmp/smi/builder.py", line 368, in loadModules
self.loadModule(modName, **userCtx)
File "/usr/lib/python2.7/site-packages/pysnmp/smi/builder.py", line 336, in loadModule
'MIB module \"%s\" load error: %s' % (modPath, traceback.format_exception(*sys.exc_info()))
pysnmp.smi.error.MibLoadError: MIB module "/root/.pysnmp/mibs/NS-ROOT-MIB.pyc" load error: ['Traceback (most recent call last):\n', ' File "/usr/lib/python2.7/site-packages/pysnmp/smi/builder.py", line 331, in loadModule\n exec (modData, g)\n', ' File "/root/.pysnmp/mibs/NS-ROOT-MIB.py", line 850, in <module>\n class EntityProtocolType(Integer32):\n', ' File "/root/.pysnmp/mibs/NS-ROOT-MIB.py", line 852, in EntityProtocolType\n namedValues = NamedValues(("http", 0), ("ftp", 1), ("tcp", 2), ("udp", 3), ("sslBridge", 4), ("monitor", 5), ("monitorUdp", 6), ("nntp", 7), ("httpserver", 8), ("httpclient", 9), ("rpcserver", 10), ("rpcclient", 11), ("nat", 12), ("any", 13), ("ssl", 14), ("dns", 16), ("adns", 17), ("snmp", 18), ("ha", 19), ("monitorPing", 20), ("sslOtherTcp", 21), ("aaa", 22), ("secureMonitor", 23), ("sslvpnUdp", 24), ("rip", 25), ("dnsClient", 26), ("rpcServer", 27), ("rpcClient", 28), ("dhcrpa", 36), ("sipudp", 39), ("siptcp", 40), ("siptls", 41), ("dnstcp", 48), ("adnstcp", 49), ("rtsp", 50), ("push", 52), ("sslPush", 53), ("dhcpClient", 54), ("radius", 55), ("rdp", 61), ("mysql", 62), ("mssql", 63), ("diameter", 73), ("sslDiameter", 74), ("tftp", 75), ("tftp", 90), ("pptp", 91), ("gre", 92), ("fix", 95), ("sslFix", 96), ("userTcp", 104), ("userSslTcp", 105), ("serviceUnknown", 112))\n', ' File "/usr/lib/python2.7/site-packages/pyasn1/type/namedval.py", line 74, in __init__\n raise error.PyAsn1Error(\'Duplicate name %s\' % (name,))\n', 'PyAsn1Error: Duplicate name tftp\n']caused by <class 'pyasn1.error.PyAsn1Error'>: Duplicate name tftp
If the MIB database deletes one of the two mentions of tftp (for example, tftp (75)), then everything works fine. But it's not right.
Can I somehow fix the situation?
Thanks!
I believe the proper fix would be to pyasn1 to allow duplicate enumerations.
I believe the proper fix would be to pyasn1 to allow duplicate enumerations.
ok!
The latest pysmi no longer generates ("tftp", 75), ("tftp", 90) in .py file, but only ("tftp", 90). This partially fixes this issue but might not be the best solution.