简体   繁体   中英

How to add new MIB text file in pysnmp?

Unable to MIB of external device.

I have a IP power bar which can be controlled using SNMP. I am trying to switch off and on outlets using Python script. I have saved new mib at d:\\mib I am trying to set on of the OID to 0. I am calling setCmd function as below

errorIndication, errorStatus, errorIndex, varBinds = next(setCmd(SnmpEngine(),CommunityData('write_public'),UdpTransportTarget(('xx.xx.xx.xx', 161)),ContextData(),ObjectType(ObjectIdentity('1.3.6.1.4.1.13742.6.4.1.2.1.2.1.3',0).addAsn1MibSource('d:/mib'))))

I am getting errors Traceback (most recent call last):

  File "<pyshell#11>", line 1, in <module>
    errorIndication, errorStatus, errorIndex, varBinds = next(setCmd(SnmpEngine(),CommunityData('write_public'),UdpTransportTarget(('xx.xxx.xx.x', 161)),ContextData(),ObjectType(ObjectIdentity('SNMPv2-MIB','1.3.6.1.4.1.13742.6.4.1.2.1.2.1.3',0).addAsn1MibSource('d:/mib'))))
  File "C:\Users\mahemad\AppData\Local\Programs\Python\Python37\lib\site-packages\pysnmp\hlapi\asyncore\sync\cmdgen.py", line 217, in setCmd
    lookupMib=options.get('lookupMib', True)))
  File "C:\Users\mahemad\AppData\Local\Programs\Python\Python37\lib\site-packages\pysnmp\hlapi\asyncore\cmdgen.py", line 241, in setCmd
    contextData.contextName, vbProcessor.makeVarBinds(snmpEngine, varBinds),
  File "C:\Users\mahemad\AppData\Local\Programs\Python\Python37\lib\site-packages\pysnmp\hlapi\varbinds.py", line 39, in makeVarBinds
    __varBinds.append(varBind.resolveWithMib(mibViewController))
  File "C:\Users\mahemad\AppData\Local\Programs\Python\Python37\lib\site-packages\pysnmp\smi\rfc1902.py", line 847, in resolveWithMib
    self.__args[0].resolveWithMib(mibViewController)
  File "C:\Users\mahemad\AppData\Local\Programs\Python\Python37\lib\site-packages\pysnmp\smi\rfc1902.py", line 368, in resolveWithMib
    ifNotAdded=self.__asn1SourcesOptions.get('ifNotAdded')
  File "C:\Users\mahemad\AppData\Local\Programs\Python\Python37\lib\site-packages\pysnmp\smi\compiler.py", line 55, in addMibCompiler
    compiler.addSources(*getReadersFromUrls(*kwargs.get('sources') or defaultSources))
  File "C:\Users\mahemad\AppData\Local\Programs\Python\Python37\lib\site-packages\pysmi\reader\url.py", line 68, in getReadersFromUrls
    raise error.PySmiError('Unsupported URL scheme %s' % sourceUrl)
pysmi.error.PySmiError: Unsupported URL scheme d:/mib

First of all, MIBs are not required with SNMP for as long as you use bare OIDs and values (this is what you seem to do).

If you want to set that OID to value 0 the following managed object specification should produce SNMP SET PDU you might need:

ObjectType(ObjectIdentity('1.3.6.1.4.1.13742.6.4.1.2.1.2.1.3'), 0)

If you want to use MIBs you should addAsn1MibSource method, but pass it a valid URL .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM