Code Monkey home page Code Monkey logo

Comments (9)

sbhattach avatar sbhattach commented on May 18, 2024

pip_list.txt
PIP List added.

from pysnmp.

etingof avatar etingof commented on May 18, 2024

The 1.3.6.1.2.1.1.2.0 OID is in fact part of SNMPv2-MIB (sysObjectID.0), do you have it loaded as well?

The other possibility is that you redefine 1.3.6.1.2.1.1.2.0 OID somewhere in your custom MIBs and that OID has a non-OBJECT-TYPE MIB type.

If you enable pysnmp debugging, the whole MIB lookup process should be reported. That might help figuring out the root cause.

from pysnmp.

sbhattach avatar sbhattach commented on May 18, 2024

I attached the Debug log
debug_log.txt

from pysnmp.

etingof avatar etingof commented on May 18, 2024

It's hard to tell the exact problem without seeing the whole program and relate it to the debug you provided...

Could you please add SNMPv2-MIB to the load_mib_modules list (you can drop SNMPv2-SMI as it's a dependency):

        load_mib_modules = "SNMPv2-MIB, <CUSTOM-MIB-1>,<CUSTOM-MIB-2>"

...and re-run your case?

Also, I am not sure how your code is structured, but if you run more than one SNMP query per process invocation, it makes sense (from performance standpoint) to run MIB loading pieces just once.

from pysnmp.

sbhattach avatar sbhattach commented on May 18, 2024

Hi @etingof with SNMPv2-MIB insted of SNMPv2-SMI its working fine.

The structure of code is something like this:

from pysnmp.entity.rfc3413.oneliner import cmdgen
cmdGen = cmdgen.CommandGenerator()

oid = (1,3,6,1)
errindication, errstatus, errindex,\
varBindTable = cmdgen.nextCmd(auth_data,
                                    transport,
                                    oid, lexicographicMode=True,
                                    ignoreNonIncreasingOid=True, maxRows=5000,
                                    lookupNames=True, lookupValues=True)

def translate_mib(custom_mib_paths, load_mib_modules, name, val):
    if custom_mib_paths and load_mib_modules:
        try:
            mibBuilder = builder.MibBuilder()
            compiler.addMibCompiler(mibBuilder, sources=custom_mib_paths)
            mibViewController = view.MibViewController(mibBuilder)
            for mibs in load_mib_modules.split(','):
                mibBuilder.loadModules(mibs)
        except error.MibNotFoundError:
            print("Mib Not Found!", "Error")
    if custom_mib_paths and load_mib_modules:
        output = rfc1902.ObjectType(rfc1902.ObjectIdentity(name), val).resolveWithMib(mibViewController).prettyPrint()
        op_list = output.split(" = ")
        name = op_list[0].strip()
        val = op_list[1].strip()
        print('%s = %s' %
                         (name,
                          val))
        return name, val
    else:
        print('%s = %s' %
                         (name.prettyPrint(),
                          val.prettyPrint()))
        return name.prettyPrint(), val.prettyPrint()

custom_mib_paths = "/data/users/MIBS/,/usr/share/snmp/mibs/"
load_mib_modules = "SNMPv2-SMI,<CUSTOM-MIB-1>,<CUSTOM-MIB-2>"

for varBindTableRow in varBindTable:
    for name, val in varBindTableRow:
        translate_mib(custom_mib_paths, load_mib_modules, name, val)

from pysnmp.

etingof avatar etingof commented on May 18, 2024

So does that solve you problem or not quite?

I'm not sure why you need the translate_mib() function at all? It's all seem to be implemented inside pysnmp already. Could you just use ObjectIdentity.addAsn1MibSource and ObjectIdentity.loadMibs instead?

If you still need that custom MIB resolver, I'd strongly recommend making the MibBuilder and MibViewController objects initilaized just once rather than inside a loop, as it's currently is.

from pysnmp.

sbhattach avatar sbhattach commented on May 18, 2024

@etingof This solve the problem.
But in my code I have tried the same addAsn1MibSource and .loadMibs when user is providing MIB string(not OID) as a input. which works fine.

But when its with oid for some reason its failing.

>>> ObjectIdentity('1.3.6.1')
ObjectIdentity('1.3.6.1')
>>> ObjectIdentity('1.3.6.1').addAsn1Source('/data/users/sbhattac/MIBS/,/usr/share/snmp/mibs/'.split(','))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sbhattac/VIRT/lib/python2.7/site-packages/pysnmp/smi/rfc1902.py", line 634, in __getattr__
    raise SmiError('%s object not properly initialized for accessing %s' % (self.__class__.__name__, attr))
pysnmp.smi.error.SmiError: ObjectIdentity object not properly initialized for accessing addAsn1Source
>>>
>>> ObjectIdentity('SNMPv2-MIB', 'sysDescr').addAsn1Source('http://mibs.snmplabs.com/asn1/@mib@')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sbhattac/VIRT/lib/python2.7/site-packages/pysnmp/smi/rfc1902.py", line 634, in __getattr__
    raise SmiError('%s object not properly initialized for accessing %s' % (self.__class__.__name__, attr))
pysnmp.smi.error.SmiError: ObjectIdentity object not properly initialized for accessing addAsn1Source
>>>

Can you please confirm its behavior.

from pysnmp.

etingof avatar etingof commented on May 18, 2024

That's because you are using the wrong method. It should be .addAsn1MibSource, not .addAsn1Source.

from pysnmp.

sbhattach avatar sbhattach commented on May 18, 2024

@etingof with addAsn1MibSource its working fine please close it.
Thanks a lot.

from pysnmp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.