Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snimpy.snmp.SNMPNoSuchObject: No such object was found #61

Open
edouard-lopez opened this issue Oct 3, 2016 · 3 comments
Open

snimpy.snmp.SNMPNoSuchObject: No such object was found #61

edouard-lopez opened this issue Oct 3, 2016 · 3 comments

Comments

@edouard-lopez
Copy link
Contributor

edouard-lopez commented Oct 3, 2016

I'm having an exception raised, but I don't get why

snimpy.snmp.SNMPNoSuchObject: No such object was found

Code

from snimpy import manager as snimpy

def snmp(hostname, oids, mibs):
    logger.debug(hostname)
    logger.debug(oids)
    logger.debug(mibs)
    for mib in mibs:
        snimpy.load(mib)

    session = snimpy.snmp.Session(hostname, "public", 1)
    details = session.get(*oids)

    return [{
                'oid': '.' + '.'.join(repr(node) for node in oid[0]),
                'value': oid[1]
            } for oid in details]

oids = ['.1.3.6.1.2.1.25.3.2.1.3.1', '.1.3.6.1.2.1.43.10.2.1.4.1.1.1.3.6.1.2.1.1.4.0', '.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.5.0', '.1.3.6.1.2.1.1.3.0']
hostname = '192.168.2.250'
mibs = ['DISMAN-EVENT-MIB', 'HOST-RESOURCES-MIB', 'SNMPv2-MIB', 'SNMPv2-SMI']
snmp(hostname, oids, mibs)

Error

>>> scanner.get_device_infos('192.168.2.250')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "~/project/daemon/api/scanner.py", line 62, in get_device_infos
    infos = self.network_tools.snmp(hostname, oids, mibs)
  File "~/project/daemon/api/network_tools.py", line 26, in snmp
    logger.debug(type(oids))
  File "~/project/env/lib/python3.5/site-packages/snimpy/snmp.py", line 286, in get
    return self._op(self._cmdgen.getCmd, *oids)
  File "~/project/env/lib/python3.5/site-packages/snimpy/snmp.py", line 278, in _op
    return tuple([(oid, self._convert(val)) for oid, val in results])
  File "~/project/env/lib/python3.5/site-packages/snimpy/snmp.py", line 278, in <listcomp>
    return tuple([(oid, self._convert(val)) for oid, val in results])
  File "~/project/env/lib/python3.5/site-packages/snimpy/snmp.py", line 249, in _convert
    self._check_exception(value)
  File "~/project/env/lib/python3.5/site-packages/snimpy/snmp.py", line 217, in _check_exception
    raise SNMPNoSuchObject("No such object was found")  # nopep8
snimpy.snmp.SNMPNoSuchObject: No such object was found

Doing it in bash works

Reaching the equipment using bash and snmpget command works fine:

declare -a oids=(
'.1.3.6.1.2.1.25.3.2.1.3.1'  # HOST-RESOURCES-MIB::hrDeviceDescr.1
'.1.3.6.1.2.1.43.10.2.1.4.1.1'  # SNMPv2-SMI::mib-2.43.10.2.1.4.1.1 page count
'.1.3.6.1.2.1.1.4.0'  # SNMPv2-MIB::sysContact.0
'.1.3.6.1.2.1.1.1.0'  # SNMPv2-MIB::sysDescr.0
'.1.3.6.1.2.1.1.5.0'  # SNMPv2-MIB::sysName.0
'.1.3.6.1.2.1.1.3.0'  # DISMAN-EVENT-MIB::sysUpTimeInstance
)

for oid in ${oids[@]}; do
    echo "$oid"
    snmpget -v 1 -t .3 -r 2 -c public 192.168.2.250 -m +SNMPv2-MIB "$oid"
    echo
done

output:

.1.3.6.1.2.1.25.3.2.1.3.1
HOST-RESOURCES-MIB::hrDeviceDescr.1 = STRING: Brother HL-5250DN series

.1.3.6.1.2.1.43.10.2.1.4.1.1
SNMPv2-SMI::mib-2.43.10.2.1.4.1.1 = Counter32: 22629

.1.3.6.1.2.1.1.4.0
SNMPv2-MIB::sysContact.0 = STRING: 

.1.3.6.1.2.1.1.1.0
SNMPv2-MIB::sysDescr.0 = STRING: Brother NC-6400h, Firmware Ver.1.01  (05.08.31),MID 84UZ92

.1.3.6.1.2.1.1.5.0
SNMPv2-MIB::sysName.0 = STRING: BRN_7D3B43

.1.3.6.1.2.1.1.3.0
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (168019770) 19 days, 10:43:17.70

Question

What's the matter here?

@edouard-lopez
Copy link
Contributor Author

I check to see if one of the oid was problematic and it '.1.3.6.1.2.1.43.10.2.1.4.1.1' is the culprit

Fails

oids = [
    '.1.3.6.1.2.1.43.10.2.1.4.1.1'  # SNMPv2-SMI::mib-2.43.10.2.1.4.1.1 page count
    '.1.3.6.1.2.1.25.3.2.1.3.1',  # HOST-RESOURCES-MIB::hrDeviceDescr.1
]

Works

oids = [
    '.1.3.6.1.2.1.25.3.2.1.3.1',  # HOST-RESOURCES-MIB::hrDeviceDescr.1
    '.1.3.6.1.2.1.43.10.2.1.4.1.1'  # SNMPv2-SMI::mib-2.43.10.2.1.4.1.1 page count
]

I tried again with the full list and putting the problematic oid as the last item of the list and it work…

oids = [
    '.1.3.6.1.2.1.25.3.2.1.3.1',  # HOST-RESOURCES-MIB::hrDeviceDescr.1
    '.1.3.6.1.2.1.1.4.0',  # SNMPv2-MIB::sysContact.0
    '.1.3.6.1.2.1.1.1.0',  # SNMPv2-MIB::sysDescr.0
    '.1.3.6.1.2.1.1.5.0',  # SNMPv2-MIB::sysName.0
    '.1.3.6.1.2.1.1.3.0',  # DISMAN-EVENT-MIB::sysUpTimeInstance
    '.1.3.6.1.2.1.43.10.2.1.4.1.1'  # SNMPv2-SMI::mib-2.43.10.2.1.4.1.1 page count
]

Why is the oids order relevant to session.get(*oids)? cc @vincentbernat

@vincentbernat
Copy link
Owner

Error reporting with SNMPv1 is misleading. You could first try with SNMPv2 instead.

Your snmpget is not equivalent. Try this instead:

declare -a oids=(
'.1.3.6.1.2.1.25.3.2.1.3.1'  # HOST-RESOURCES-MIB::hrDeviceDescr.1
'.1.3.6.1.2.1.43.10.2.1.4.1.1'  # SNMPv2-SMI::mib-2.43.10.2.1.4.1.1 page count
'.1.3.6.1.2.1.1.4.0'  # SNMPv2-MIB::sysContact.0
'.1.3.6.1.2.1.1.1.0'  # SNMPv2-MIB::sysDescr.0
'.1.3.6.1.2.1.1.5.0'  # SNMPv2-MIB::sysName.0
'.1.3.6.1.2.1.1.3.0'  # DISMAN-EVENT-MIB::sysUpTimeInstance
)

snmpget -v 1 -t .3 -r 2 -c public 192.168.2.250 -m +SNMPv2-MIB ${oids[@]}

I suspect you'll also get the same kind of error. Order is unimportant but there can be a bug in the agent side (server side).

@edouard-lopez
Copy link
Contributor Author

Bash is working fine, it's the python code that's not working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants