0

I'm having problems with the pysnmp package.

I want to connect to the OLT device from Huawei MA5600. I have his MIBs in text format * .mib the idea is to get the temperature, energy consumption among others

I have the following code

from pysnmp.hlapi import *
from pysmi import debug
#debug.setLogger(debug.Debug('compiler'))


errorIndication, errorStatus, errorIndex, varBinds = next(
    getCmd(SnmpEngine(),
           CommunityData('MyCommunity'),
           UdpTransportTarget(('192.168.1.2', 161)),
           ContextData(),
           ObjectType(ObjectIdentity('1.3.6.1.2.1.1.6.0')),
           ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0')),
           ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.10')),
           ObjectType(ObjectIdentity('1.3.6.1.4.1.2011.2.6.7.1.1.1.1.11'))\
           .addAsn1MibSource('file:///home/devel/mib/',
                 'file:///home/devel/mib'
                 'http://mibs.snmplabs.com/asn1/@mib@',
                 'http://mibs.snmplabs.com/asn1/',
                 'file:///home/devel/mib/public/',
                 'file:///home/devel/mib/public')
           )

)



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

In this case I have the following answer:

(sent) C:\DESARROLLOS\system>python v2c-get.py
SNMPv2-MIB::sysLocation.0 = EPL
SNMPv2-MIB::sysDescr.0 = Huawei Integrated Access Software
SNMPv2-SMI::mib-2.2.2.1.10 = No Such Instance currently exists at this OID
SNMPv2-SMI::enterprises.2011.2.6.7.1.1.1.1.11 = No Such Instance currently exists at this OID

I have also tried to use the addMibSource function to add the python mibs, I have the pysnmp_mibs package but it does not work either.

It should be noted that with the command I get the information I request:

snmpwalk -v 2c -c MyCommunity 192.168.1.2 1.3.6.1.4.1.2011.2.6.7.1.1.1.1.1

It should be noted that with the command I get the information I request.

snmpwalk -v 2c -c MyCommunity 192.168.1.2 1.3.6.1.4.1.2011.2.6.7.1.1.1.1.1

I would be grateful if someone happened to something similar and knows what to do. I am using python 3.6, pysmi == 0.3.2, pysnmp == 4.4.6 and pysnmp-mibs == 0.1.6

1 Answers1

0

If you think that you should get some value in response instead of 'No such instance', then the problem is that you are querying the object (OID) which does not exist at the device or you do not have access to it.

If you want the OIDs in response to be resolved into human-friendly names, you should pre-load the MIB(s) that define those OIDs e.g. ObjectType(ObjectIdentity('1.3.6.1.2.1.2.2.1.10')).loadMibs('MY-MIB', 'MY-OTHER-MIB').

Either way, probably the best solution is to query the object(s) by name(s):

ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0))

...rather than by OID. Querying by name would automatically load the MIB you reference.

The quick doc is here.

Ilya Etingof
  • 5,440
  • 1
  • 17
  • 21