etingof / pysnmp

Python SNMP library
http://snmplabs.com/pysnmp/
BSD 2-Clause "Simplified" License
582 stars 200 forks source link

pysnmp.smi.error.SmiError: MIB object ObjectIdentity('1.3.6.1.4.1.9.9.96.1.1.1.1.2.100') is not OBJECT-TYPE (MIB not loaded?) #10

Closed iargue closed 8 years ago

iargue commented 8 years ago

I am attempting to use an SNMP set command to copy config files on a Cisco device.

I am attempting to use the OID for Cisco Config Copy MIB.

The first OID is 1.3.6.1.4.1.9.9.96.1.1.1.1.2.x.

I simply cannot get it to work.

from pysnmp.hlapi import *

for (errorIndication,
     errorStatus,
     errorIndex,
     varBinds) in setCmd(SnmpEngine(),
                          CommunityData('private'),
                          UdpTransportTarget(('10.18.15.120', 161)),
                          ContextData(),
                          ObjectType(ObjectIdentity('1.3.6.1.4.1.9.9.96.1.1.1.1.2.100'), 2),
                          lookupMib=False):

    if errorIndication:
        print(errorIndication)
        break
    elif errorStatus:
        print('%s at %s' % (errorStatus.prettyPrint(),
                            errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
        break
    else:
        for varBind in varBinds:
            print(' = '.join([x.prettyPrint() for x in varBind]))

Traceback (most recent call last): File "C:\Project Files\snmptest.py", line 11, in lookupMib=False): File "C:\Python27\lib\site-packages\pysnmp\hlapi\asyncore\sync\cmdgen.py", line 210, in setCmd lookupMib=options.get('lookupMib', True))) File "C:\Python27\lib\site-packages\pysnmp\hlapi\asyncore\cmdgen.py", line 235, in setCmd contextData.contextName, vbProcessor.makeVarBinds(snmpEngine, varBinds), File "C:\Python27\lib\site-packages\pysnmp\hlapi\varbinds.py", line 36, in makeVarBinds varBinds.append(varBind.resolveWithMib(mibViewController)) File "C:\Python27\lib\site-packages\pysnmp\smi\rfc1902.py", line 845, in resolveWithMib raise SmiError('MIB object %r is not OBJECT-TYPE (MIB not loaded?)' % (self.args[0],)) pysnmp.smi.error.SmiError: MIB object ObjectIdentity('1.3.6.1.4.1.9.9.96.1.1.1.1.2.100') is not OBJECT-TYPE (MIB not loa ded?)

If I'm using OID why do I need an MIB? Why does it not have this MIB anyways if its on http://mibs.snmplabs.com/asn1/CISCO-CONFIG-COPY-MIB, and how do I fix?

etingof commented 8 years ago

If I'm using OID why do I need an MIB?

That's because you are passing a value (2) along with the OID. The value is untyped (to SNMP). To send a well formed packet, pysnmp needs to figure out SNMP type of the value you are sending. The only way for pysnmp to handle this is to look up the MIB. But pysnmp can't [yet] figure what MIB it should load to get hold of MIB object identified by that OID (e.g. OID->MIB mapping is not implemented).

To fix that you simply need to give it SNMP type for your value:

ObjectType(ObjectIdentity('1.3.6.1.4.1.9.9.96.1.1.1.1.2.100'), Integer32(2))

Why does it not have this MIB anyways if its on http://mibs.snmplabs.com/asn1/CISCO-CONFIG-COPY-MIB, and how do I fix?

We need someone to implement OID->MIB map so that pysnmp could download and use proper MIB in some cases. I'd happily merge such kind of PR. ;-)

premananda8 commented 6 years ago

Help ful

premananda8 commented 6 years ago

Best to copy mib_file_name.py to "\venv\Lib\site-packages\pysnmp\smi\mibs"