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

Problems polling different kind of string objects (pyasn1?) #73

Closed
kaihil opened this issue Aug 9, 2017 · 5 comments
Closed

Problems polling different kind of string objects (pyasn1?) #73

kaihil opened this issue Aug 9, 2017 · 5 comments
Labels

Comments

@kaihil
Copy link

kaihil commented Aug 9, 2017

Hi,

I experienced some problems when polling string data with pysnmp.

I experienced also altering behavior when changing the following parameters:
a) the pyasn1 version (0.3.2 vs. 0.2.3)
b) the polled object (sysDescr vs. ifName)
c) the type of naming the object (Object Name vs. OID)

I tried to reproduce it somehow with pysnmp-apps and experienced this erroneous and strange behavior. At least for me it makes no sense ;) The following matrix shows, which combinations work and which doesn't.

Short:

  • Case sysDescr
    • pyasn1==0.3.2, via Object Name: ❌
    • pyasn1==0.3.2, via OID: ❌
    • pyasn1==0.2.3, via Object Name: 💚
    • pyasn1==0.2.3, via OID: 💚
  • Case get ifName
    • pyasn1==0.3.2, via Object Name: ❌
    • pyasn1==0.3.2, via OID: ❌
    • pyasn1==0.2.3, via Object Name: 💚
    • pyasn1==0.2.3, via OID: ❌

Prerequisites

env1:

$ pip install pysnmp-apps
$ pip freeze
ply==3.10
pyasn1==0.3.2
pycryptodome==3.4.6
pysmi==0.1.3
pysnmp==4.3.9
pysnmp-apps==0.4.1

env2:

$ pip install pyasn1==0.2.3
$ pip install pysnmp-apps
$ pip freeze
ply==3.10
pyasn1==0.2.3
pycryptodome==3.4.6
pysmi==0.1.3
pysnmp==4.3.9
pysnmp-apps==0.4.1

Case sysDescr

$ snmpget -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com SNMPv2-MIB::sysDescr.0
SNMPv2-MIB::sysDescr.0 = STRING: Linux zeus 4.8.6.5-smp #2 SMP Sun Nov 13 14:58:11 CDT 2016 i686
$ snmpget -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com 1.3.6.1.2.1.1.1.0
SNMPv2-MIB::sysDescr.0 = STRING: Linux zeus 4.8.6.5-smp #2 SMP Sun Nov 13 14:58:11 CDT 2016 i686
(env1) $ snmpget.py -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com SNMPv2-MIB::sysDescr.0
=> crash (for error output see below)
(env1) $ snmpget.py -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com 1.3.6.1.2.1.1.1.0
=> crash (for error output see below)
(env2) $ snmpget.py -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com SNMPv2-MIB::sysDescr.0
SNMPv2-MIB::sysDescr.0 = DisplayString: Linux zeus 4.8.6.5-smp #2 SMP Sun Nov 13 14:58:11 CDT 2016 i686
(env2) $ snmpget.py -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com 1.3.6.1.2.1.1.1.0
SNMPv2-MIB::sysDescr.0 = DisplayString: Linux zeus 4.8.6.5-smp #2 SMP Sun Nov 13 14:58:11 CDT 2016 i686

Case ifName

$ snmpget -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com IF-MIB::ifName.1
IF-MIB::ifName.1 = STRING: lo
$ snmpget -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com 1.3.6.1.2.1.31.1.1.1.1.1
IF-MIB::ifName.1 = STRING: lo
(env1) $ snmpget.py -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com IF-MIB::ifName.1
=> crash (for error output see below)
(env1) $ snmpget.py -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com 1.3.6.1.2.1.31.1.1.1.1.1
=> crash (for error output see below)
(env2) $ snmpget.py -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com IF-MIB::ifName.1
IF-MIB::ifName."1" = DisplayString: lo
(env2) $ snmpget.py -v3 -u usr-md5-des -l authPriv -A authkey1 -X privkey1 demo.snmplabs.com 1.3.6.1.2.1.31.1.1.1.1.1
=> crash (for error output see below)

Example log (from first command)

Error: poll error: Traceback (most recent call last):
;  File "/Users/kaihil/pysnmp-test/env1/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher
    use_poll=True, map=self.__sockMap, count=1)
;  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 207, in loop
    poll_fun(timeout, map)
;  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 188, in poll2
    readwrite(obj, flags)
;  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 123, in readwrite
    obj.handle_error()
;  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 108, in readwrite
    obj.handle_read_event()
;  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/asyncore.py", line 423, in handle_read_event
    self.handle_read()
;  File "/Users/kaihil/pysnmp-test/env1/lib/python3.5/site-packages/pysnmp/carrier/asyncore/dgram/base.py", line 163, in handle_read
    self._cbFun(self, transportAddress, incomingMessage)
;  File "/Users/kaihil/pysnmp-test/env1/lib/python3.5/site-packages/pysnmp/carrier/base.py", line 70, in _cbFun
    self, transportDomain, transportAddress, incomingMessage
;  File "/Users/kaihil/pysnmp-test/env1/lib/python3.5/site-packages/pysnmp/entity/engine.py", line 152, in __receiveMessageCbFun
    self, transportDomain, transportAddress, wholeMsg
;  File "/Users/kaihil/pysnmp-test/env1/lib/python3.5/site-packages/pysnmp/proto/rfc3412.py", line 486, in receiveMessage
    cachedParams['cbCtx'])
;  File "/Users/kaihil/pysnmp-test/env1/lib/python3.5/site-packages/pysnmp/entity/rfc3413/cmdgen.py", line 139, in processResponsePdu
    cbFun(snmpEngine, origSendRequestHandle, None, PDU, cbCtx)
;  File "/Users/kaihil/pysnmp-test/env1/lib/python3.5/site-packages/pysnmp/entity/rfc3413/cmdgen.py", line 207, in processResponseVarBinds
    PDU and v2c.apiPDU.getVarBinds(PDU) or (), cbCtx)
;  File "/Users/kaihil/pysnmp-test/env1/bin/snmpget.py", line 57, in cbFun
    cbCtx['mibViewController'], oid, val
;  File "/Users/kaihil/pysnmp-test/env1/lib/python3.5/site-packages/pysnmp_apps/cli/mibview.py", line 402, in getPrettyOidVal
    out = out + syntax.prettyOut(val)
;  File "<string>", line 176, in prettyOut
;  File "/Users/kaihil/pysnmp-test/env1/lib/python3.5/site-packages/pysnmp/proto/rfc1902.py", line 229, in prettyOut
    return octets.octs2str(value)
;  File "/Users/kaihil/pysnmp-test/env1/lib/python3.5/site-packages/pyasn1/compat/octets.py", line 40, in <lambda>
    octs2str = lambda x: x.decode('iso-8859-1')
;AttributeError: 'OctetString' object has no attribute 'decode'

Usage: /Users/kaihil/pysnmp-test/env1/bin/snmpget.py [OPTIONS] <AGENT> <PARAMETERS>
Command-line SNMP tools version 0.4.1, written by Ilya Etingof <ilya@glas.net>
Foundation libraries: pysmi 0.1.3, pysnmp 4.3.9, pysnmp-mibs N/A, pyasn1 0.3.2
Python interpreter: 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
(...)
@etingof
Copy link
Owner

etingof commented Aug 9, 2017

Thank you for your report!

I can confirm the issue when running with Python 3, but not with Python 2. From the brief glance, it seems to be specific to the snmpget.py tool because functionally similar stand-alone code snippet seems to work for me.

I expect to come up with a fix shortly.

@etingof etingof added the bug label Aug 9, 2017
@kaihil
Copy link
Author

kaihil commented Aug 9, 2017

Thanks for your quick response :)

FYI: When I do the same with snmpbulkwalk.py (using the corresponding parent objects) I get exactly the same results.

@etingof
Copy link
Owner

etingof commented Aug 9, 2017

This should be fixed in pysnmp-apps master. You are welcome to test it before it's released. ;-)

@etingof
Copy link
Owner

etingof commented Aug 9, 2017

pysnmp-apps-0.4.2 has been released on PyPI

@etingof etingof closed this as completed Aug 9, 2017
@kaihil
Copy link
Author

kaihil commented Aug 10, 2017

I can confirm that it works now. Thanks a lot @etingof!

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

No branches or pull requests

2 participants