Giter VIP home page Giter VIP logo

easysnmp's Introduction

Easy SNMP

Python Code Style Build Status Join the Discussions! License

Easy SNMP Logo

Artwork courtesy of Open Clip Art Library

Introduction

Easy SNMP is a fork of Net-SNMP Python Bindings that attempts to bring a more Pythonic interface to the library. Check out the Net-SNMP website for more information about SNMP.

This module provides a full-featured SNMP client API and supports all dialects of the SNMP protocol.

Why Another Library?

  • The original Net-SNMP Python library is a great starting point but is quite un-Pythonic and lacks proper unit tests and documentation.
  • PySNMP is entirely written in Python and therefore has a huge performance hit. In some brief tests, I estimate that both the Net-SNMP Python bindings and Easy SNMP are more than 4 times faster than PySNMP. Further to this, PySNMP has an even less Pythonic interface than the official Net-SNMP bindings.
  • Many other libraries like Snimpy are sadly based on PySNMP, so they also suffer performance penalty.

Quick Start

There are primarily two ways you can use the Easy SNMP library:

1. By using a Session object which is most suitable when you want to request multiple pieces of SNMP data from a source:

from easysnmp import Session

# Create an SNMP session to be used for all our requests
session = Session(hostname='localhost', community='public', version=2)

# You may retrieve an individual OID using an SNMP GET
location = session.get('sysLocation.0')

# You may also specify the OID as a tuple (name, index)
# Note: the index is specified as a string as it can be of other types than
# just a regular integer
contact = session.get(('sysContact', '0'))

# And of course, you may use the numeric OID too
description = session.get('.1.3.6.1.2.1.1.1.0')

# Set a variable using an SNMP SET
session.set('sysLocation.0', 'The SNMP Lab')

# Perform an SNMP walk
system_items = session.walk('system')

# Each returned item can be used normally as its related type (str or int)
# but also has several extended attributes with SNMP-specific information
for item in system_items:
    print '{oid}.{oid_index} {snmp_type} = {value}'.format(
        oid=item.oid,
        oid_index=item.oid_index,
        snmp_type=item.snmp_type,
        value=item.value
    )

2. By using Easy SNMP via its simple interface which is intended for one-off operations (where you wish to specify all details in the request):

from easysnmp import snmp_get, snmp_set, snmp_walk

# Grab a single piece of information using an SNMP GET
snmp_get('sysDescr.0', hostname='localhost', community='public', version=1)

# Perform an SNMP SET to update data
snmp_set(
    'sysLocation.0', 'My Cool Place',
    hostname='localhost', community='public', version=1
)

# Perform an SNMP walk
snmp_walk('system', hostname='localhost', community='public', version=1)

Documentation

Please check out the Easy SNMP documentation at Read the Docs. This includes installation instructions for various operating systems.

You may generate the documentation as follows:

# Install Sphinx
pip install sphinx

# You may optionally export the READTHEDOCS environment variable to build docs
# on systems where you haven't built the C interface
export READTHEDOCS=1

# Build the documentation into static HTML pages
cd docs
make html

Acknowledgments

I'd like to say thanks to the following folks who have made this project possible:

  • Giovanni Marzot: the original author
  • ScienceLogic, LLC: sponsored the initial development of this module
  • Wes Hardaker and the net-snmp-coders: for their hard work and dedication
  • fgimian and nnathan: the original contributors to this codebase

Running Tests

Tests use Pytest. You can run them with the following:

git clone https://github.com/easysnmp/easysnmp.git
cd easysnmp
pip install pytest
pytest

License

Easy SNMP is released under the BSD license. Please see the LICENSE file for more details.

The original version of this library is copyright (c) 2006 G. S. Marzot. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Net-SNMP itself.

Copyright (c) 2006 SPARTA, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Net-SNMP itself.

easysnmp's People

Contributors

carlkidcrypto avatar cybersol795 avatar fgimian avatar kamakazikamikaze avatar larsmichelsen avatar nnathan avatar sthomen avatar uedvt359 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easysnmp's Issues

HOW-TO decode OCTET STR

hi @fgimian, and thank you a lot for the easysnmp library is indeed the easiest one to use :)

could you possibly advise on how to decode the following walk ?
example:

for x in ipNetToMediaPhysAddress:
    print x.oid, x.oid_index, x.value, repr(x.value), ':'.join([i.encode("hex") for i in repr(x.value)])
   .....:     
ipNetToMediaPhysAddress 768.194.146.118.1�ô�oÀ u'\x08\x81\xf4\x9bo\xc0' 75:27:5c:78:30:38:5c:78:38:31:5c:78:66:34:5c:78:39:62:6f:5c:78:63:30:27
ipNetToMediaPhysAddress 768.194.146.118.3   ·f@@ u'\x00\t\xb7f@@' 75:27:5c:78:30:30:5c:74:5c:78:62:37:66:40:40:27
ipNetToMediaPhysAddress 768.194.146.118.8 ³Ü¬ u'\x00\x1f\x12\xb3\xdc\xac' 75:27:5c:78:30:30:5c:78:31:66:5c:78:31:32:5c:78:62:33:5c:78:64:63:5c:78:61:63:27

snmp walk returns empty list, while walk on polled device does not

Hi,

I am very happy user of easysnmp :) but
today i encountered the following weird thing:

when I do a poll/snmpwalk to a juniper router I get:

In [14]: dot3adAggPortSelectedAggID = sess.walk("1.2.840.10006.300.43.1.2.1.1.12")

In [15]: dot3adAggPortSelectedAggID
Out[15]: []

while on the router itself:

> show snmp mib walk 1.2.840.10006.300.43.1.2.1.1.12 
dot3adAggPortSelectedAggID.682 = 607
dot3adAggPortSelectedAggID.683 = 607
dot3adAggPortSelectedAggID.684 = 607
dot3adAggPortSelectedAggID.685 = 597
dot3adAggPortSelectedAggID.686 = 611
dot3adAggPortSelectedAggID.687 = 611
dot3adAggPortSelectedAggID.688 = 611
dot3adAggPortSelectedAggID.689 = 597

Could you please advise on what is going wrong ?

Nikos

Implementation of bulkwalk and trap

I am missing a library native implementation of bulkwalks. The origin NetSNMP python bindings don't implement the bulkwalk either. I wonder if you plan to directly implement a bulkwalk API call?

UnicodeDecodeError on Python 3

The following code works with Python 2.7.10:

from easysnmp import Session
sess = Session(hostname='localhost', community='public', version=2)
sess.walk('.1.3.6.1.2.1')

This same code fails with Python 3.4.3 with the following error:

/usr/lib/python3.4/site-packages/easysnmp/session.py in walk(self, oids)
    446 
    447         # Perform the SNMP walk using GETNEXT operations
--> 448         interface.walk(self, varlist)
    449 
    450         # Validate the variable list returned

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

Installing EasySNMP on windows - encountering some error

I'm trying to install EasySNMP but I'm getting some error.
Below is the command and result.
Thank you.

C:\Users\Ronnie>pip install easysnmp

Collecting easysnmp
Using cached easysnmp-0.2.4.tar.gz
Installing collected packages: easysnmp
Running setup.py install for easysnmp ... error
Complete output from command c:\users\ronnie\appdata\local\programs\python\python36-32\python.exe -u -c "import setuptools, tokenize;file='C:\Users\Ronnie\AppData\Local\Temp\pip-build-es3m88_j\easysnmp\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record C:\Users\Ronnie\AppData\Local\Temp\pip-oyuhwisc-record\install-record.txt --single-version-externally-managed --compile:
'net-snmp-config' is not recognized as an internal or external command,
operable program or batch file.
running install
running build
running build_py
creating build
creating build\lib.win32-3.6
creating build\lib.win32-3.6\easysnmp
copying easysnmp\compat.py -> build\lib.win32-3.6\easysnmp
copying easysnmp\easy.py -> build\lib.win32-3.6\easysnmp
copying easysnmp\exceptions.py -> build\lib.win32-3.6\easysnmp
copying easysnmp\helpers.py -> build\lib.win32-3.6\easysnmp
copying easysnmp\session.py -> build\lib.win32-3.6\easysnmp
copying easysnmp\utils.py -> build\lib.win32-3.6\easysnmp
copying easysnmp\variables.py -> build\lib.win32-3.6\easysnmp
copying easysnmp_init_.py -> build\lib.win32-3.6\easysnmp
running build_ext
building 'easysnmp.interface' extension
creating build\temp.win32-3.6
creating build\temp.win32-3.6\Release
creating build\temp.win32-3.6\Release\easysnmp
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\ronnie\appdata\local\programs\python\python36-32\include -Ic:\users\ronnie\appdata\local\programs\python\python36-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tceasysnmp/interface.c /Fobuild\temp.win32-3.6\Release\easysnmp/interface.obj -Wno-unused-function
cl : Command line error D8021 : invalid numeric argument '/Wno-unused-function'
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe' failed with exit status 2

----------------------------------------

Command "c:\users\ronnie\appdata\local\programs\python\python36-32\python.exe -u -c "import setuptools, tokenize;file='C:\Users\Ronnie\AppData\Local\Temp\pip-build-es3m88_j\easysnmp\setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record C:\Users\Ronnie\AppData\Local\Temp\pip-oyuhwisc-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Ronnie\AppData\Local\Temp\pip-build-es3m88_j\easysnmp\

SNMPVariable.oid_index set incorrectly for multi-index variables

When doing an SNMP get/walk/etc and either the use_numeric flag is True, or if the MIB is not loaded, the .oid_index incorrectly steals the last component of the .oid instead of being left blank as expected.

oid_index_example.py -

from easysnmp.easy import Session

session = Session(hostname='localhost', version=2)

for use_numeric in (False, True):
    session.use_numeric = use_numeric
    var = session.get('.1.3.6.1.2.1.25.3.7.1.1.60.1')
    print(repr(var)))

output -

<SNMPVariable value='1' (oid='hrPartitionIndex', oid_index='60.1', snmp_type='INTEGER')>
<SNMPVariable value='1' (oid='.1.3.6.1.2.1.25.3.7.1.1.60', oid_index='1', snmp_type='INTEGER')>

expected output -

<SNMPVariable value='1' (oid='hrPartitionIndex', oid_index='60.1', snmp_type='INTEGER')>
<SNMPVariable value='1' (oid='.1.3.6.1.2.1.25.3.7.1.1.60.1', oid_index='', snmp_type='INTEGER')>

It appears that easysnmp.helpers.normalize_oid() does the right thing with numeric OIDs, but maybe interface.c is doing something odd?

easysnmp.exceptions.EasySNMPUnknownObjectIDError: unknown object id (sysLocation)

I'm just new to python and SNMP. I'm trying to follow:
https://pypi.python.org/pypi/easysnmp/0.2.3

Command
from easysnmp import Session
session = Session(hostname='localhost', community='public', version=2)
location = session.get('sysLocation.0')

Error:
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/easysnmp/session.py", line 315, in get
interface.get(self, varlist)
easysnmp.exceptions.EasySNMPUnknownObjectIDError: unknown object id (sysLocation)

Convert snmp_get return value to string

Hello,
I am currently using "snmp_get" from easysnmp in Python!

First of all, the SNMP request works as it should, but I found out that the returned value is type "SNMPVariable" as you'll see here:
error_snmpvariable

I used len() to find out whether it's a string so don't wonder..

Now my question is if there is any function to convert this returned type into a string so I can use the string manipulation of python! The aim is to get the temperature value only. (marked in red)
snmp_return

Here's the command I use to get the snmp information:
snmp_get('1.3.6.1.4.1.21796.4.1.3.1.4.1', hostname='10.48.1.201', community='public', version=1)

Thank you for your help!

Best regards,
Stephan Schrenk

No differentiation HEX-String and String

With snmpwalk I have this example output:
iso.0.8802.1.1.2.1.4.1.1.7.2520.9.1 = Hex-STRING: 31 2F 33 00
iso.0.8802.1.1.2.1.4.1.1.7.70039082.5.24 = Hex-STRING: 6C 20 56 54 93 D8
iso.0.8802.1.1.2.1.4.1.1.9.70039082.5.24 = STRING: "CISCO ATA SPA122"

With easysnmp I have unicode headache because of stupid compat module, which convert all to unicode even hex string, which is usually mac address.
Please add Hex-STRING snmp_type and return value as encode('hex') from latin1 string (not unicode string).
In this example '31 2F 33 00 ' is a normal string, but I dont see a way for now how to detect it, but what i defenetly need - preserve mac address as hex string (better non unicode).

If I use use_sprint_value=True, I have additionally double quotes, which not needed.

And integer type i want as integer, not unicode string.

net-snmp-config.h: No such file or directory

Hi Guys,

can you advise on the following issue?

$ pip install easysnmp
Collecting easysnmp
Using cached easysnmp-0.2.5.tar.gz
Building wheels for collected packages: easysnmp
Running setup.py bdist_wheel for easysnmp ... error
Complete output from command /home/gmckee/anaconda2/envs/ansible-dev/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-cxSoNe/easysnmp/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/tmp3bwjNJpip-wheel- --python-tag cp27:
sh: net-snmp-config: command not found
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/init.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/compat.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/easy.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/exceptions.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/helpers.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/session.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/utils.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/variables.py -> build/lib.linux-x86_64-2.7/easysnmp
running build_ext
building 'easysnmp.interface' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/easysnmp
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/gmckee/anaconda2/envs/ansible-dev/include/python2.7 -c easysnmp/interface.c -o build/temp.linux-x86_64-2.7/easysnmp/interface.o -Wno-unused-function
easysnmp/interface.c:24:38: fatal error: net-snmp/net-snmp-config.h: No such file or directory
#include <net-snmp/net-snmp-config.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1


Failed building wheel for easysnmp
Running setup.py clean for easysnmp
Failed to build easysnmp
Installing collected packages: easysnmp
Running setup.py install for easysnmp ... error
Complete output from command /home/gmckee/anaconda2/envs/ansible-dev/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-cxSoNe/easysnmp/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-6KJFlq-record/install-record.txt --single-version-externally-managed --compile:
sh: net-snmp-config: command not found
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/init.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/compat.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/easy.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/exceptions.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/helpers.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/session.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/utils.py -> build/lib.linux-x86_64-2.7/easysnmp
copying easysnmp/variables.py -> build/lib.linux-x86_64-2.7/easysnmp
running build_ext
building 'easysnmp.interface' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/easysnmp
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/gmckee/anaconda2/envs/ansible-dev/include/python2.7 -c easysnmp/interface.c -o build/temp.linux-x86_64-2.7/easysnmp/interface.o -Wno-unused-function
easysnmp/interface.c:24:38: fatal error: net-snmp/net-snmp-config.h: No such file or directory
#include <net-snmp/net-snmp-config.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1

----------------------------------------

Command "/home/gmckee/anaconda2/envs/ansible-dev/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-cxSoNe/easysnmp/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-6KJFlq-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-cxSoNe/easysnmp/

snmpset hex value in python 2.7

Hi.
I've got a problem trying to set hex value via easysnmp and python 2.7.10.
For example:

snmpset -v2c -c xxx xx.xx.xx.xx Q-BRIDGE-MIB::dot1qVlanStaticEgressPorts.1 x 80C000000000
Q-BRIDGE-MIB::dot1qVlanStaticEgressPorts.1 = Hex-STRING: 80 C0 00 00 00 00

And when i use easysnmp getting:

Python 2.7.10 (default, Mar 16 2016, 16:34:50)
[GCC 4.9.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
from easysnmp import snmp_set
snmp_set("Q-BRIDGE-MIB::dot1qVlanStaticEgressPorts.1", "\x80\xc0\x00\x00\x00\x00", hostname='xx.xx.xx.xx', community='xxx', version=2, type='OCTETSTRING')
False
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

Everything is fine with python 3.4:

Python 3.4.3 (default, Mar 10 2016, 03:25:56)
[GCC 4.9.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
from easysnmp import snmp_set
snmp_set("Q-BRIDGE-MIB::dot1qVlanStaticEgressPorts.1", "\x80\xc0\x00\x00\x00\x00", hostname='xx.xx.xx.xx', community='xxx', version=2, type='OCTETSTING')
True

It seems to me that the problem in utils.py\tostr function, coz it converts my hex values into latin-1.
My temp hack for this problem is to add one more check in tostr function:

try: if int(value.encode("hex"),16): return value except: pass

Any ideas how to fix this in right way or how to set properly hex values?

ImportError: cannot import name interface

Hi everyone! I have a trouble with easysnmp. The example above is using easysnmp installed with pip:

(snmp) ⋊> ~/sandbox snmpget -V                                          19:35:44
NET-SNMP version: 5.7.3
(snmp) ⋊> ~/sandbox python                                              19:35:52
Python 2.7.11 (default, Jan 22 2016, 08:28:37)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import easysnmp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/denis/env/snmp/lib/python2.7/site-packages/easysnmp/__init__.py", line 1, in <module>
    from .easy import (  # noqa
  File "/Users/denis/env/snmp/lib/python2.7/site-packages/easysnmp/easy.py", line 3, in <module>
    from .session import Session
  File "/Users/denis/env/snmp/lib/python2.7/site-packages/easysnmp/session.py", line 8, in <module>
    from . import interface
ImportError: dlopen(/Users/denis/env/snmp/lib/python2.7/site-packages/easysnmp/interface.so, 2): Symbol not found: _netsnmp_transport_config_compare
  Referenced from: /Users/denis/env/snmp/lib/python2.7/site-packages/easysnmp/interface.so
  Expected in: flat namespace
 in /Users/denis/env/snmp/lib/python2.7/site-packages/easysnmp/interface.so

And some test results

/Users/denis/env/containers/bin/python "/Applications/PyCharm CE.app/Contents/helpers/pycharm/pytestrunner.py" -p pytest_teamcity /Users/denis/sandbox/easysnmp/tests/test_session_build_varlist.py
Testing started at 19:28 ...
Test session starts (platform: darwin, Python 2.7.11, pytest 2.9.1, pytest-sugar 0.7.1)
rootdir: /Users/denis/sandbox/easysnmp, inifile: setup.cfg
plugins: cov-2.2.1, flake8-0.4, sugar-0.7.1

――――――――――――― ERROR collecting tests/test_session_build_varlist.py ―――――――――――――
/Users/denis/sandbox/easysnmp/tests/test_session_build_varlist.py:3: in <module>
    from easysnmp.session import build_varlist
/Users/denis/sandbox/easysnmp/easysnmp/__init__.py:1: in <module>
    from .easy import (  # noqa
/Users/denis/sandbox/easysnmp/easysnmp/easy.py:3: in <module>
    from .session import Session
/Users/denis/sandbox/easysnmp/easysnmp/session.py:8: in <module>
    from . import interface
E   ImportError: cannot import name interface

 tests/test_session_build_varlist.py ✓                           100% ██████████

--------------- coverage: platform darwin, python 2.7.11-final-0 ---------------
Name                                                 Stmts   Miss  Cover   Missing
----------------------------------------------------------------------------------
/Users/denis/sandbox/easysnmp/easysnmp/__init__.py       4      3    25%   5-11
/Users/denis/sandbox/easysnmp/easysnmp/easy.py          20     18    10%   6-121
/Users/denis/sandbox/easysnmp/easysnmp/session.py      131    126     4%   10-478
----------------------------------------------------------------------------------
TOTAL                                                  155    147     5%   

Results (0.19s):
       1 passed

This traceback occurred after I installed easysnmp manually from github sources

(snmp) ⋊> ~/s/easysnmp on master ⨯ python                                           19:39:00
Python 2.7.11 (default, Jan 22 2016, 08:28:37)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import easysnmp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "easysnmp/__init__.py", line 1, in <module>
    from .easy import (  # noqa
  File "easysnmp/easy.py", line 3, in <module>
    from .session import Session
  File "easysnmp/session.py", line 8, in <module>
    from . import interface
ImportError: cannot import name interface
>>>

Mac OS X 10.10.5
Can you say what I do incorrect?

way to get opaque data ?

is there a way to get/set opaque values?

For instance here's a few snippets from calling the snmp command line tools:

snmptranslate -On -Td WIENER-CRATE-MIB::outputVoltage
.1.3.6.1.4.1.19947.1.3.2.1.10
outputVoltage OBJECT-TYPE
  -- FROM   WIENER-CRATE-MIB
  -- TEXTUAL CONVENTION Float
  SYNTAX    Opaque (WIENER-CRATE-MIB) 
  UNITS     "V"
  MAX-ACCESS    read-write
  STATUS    current
  DESCRIPTION   "The nominal output voltage of the channel."

Pull the value:

snmpget -v 2c -m +WIENER-CRATE-MIB -c public localhost outputVoltage.u0
WIENER-CRATE-MIB::outputVoltage.u0 = Opaque: Float: 8.000000 V

Set the value as a float:

snmpset -v 2c -m +WIENER-CRATE-MIB -c higher localhost outputVoltage.u0 F 8
WIENER-CRATE-MIB::outputVoltage.u0 = Opaque: Float: 8.000000 V

When i try to do the same thing via python and easysnmp, i get a "wrongEncoding" error if i try float.

And if i do a walk snmp_type is empty, along with all the values:

session.walk('WIENER-CRATE-MIB::outputVoltage')
Out[29]:
SNMPVariable value='' (oid='outputVoltage', oid_index='1', snmp_type='')
SNMPVariable value='' (oid='outputVoltage', oid_index='2', snmp_type='')
SNMPVariable value='' (oid='outputVoltage', oid_index='3', snmp_type='')
SNMPVariable value='' (oid='outputVoltage', oid_index='4', snmp_type='')

Even though i know they are set from the command line version of walk:

snmpwalk -v 2c -m +WIENER-CRATE-MIB -c public localhost outputVoltage
WIENER-CRATE-MIB::outputVoltage.u0 = Opaque: Float: 8.000000 V
WIENER-CRATE-MIB::outputVoltage.u1 = Opaque: Float: 8.000000 V
WIENER-CRATE-MIB::outputVoltage.u2 = Opaque: Float: 8.000000 V
WIENER-CRATE-MIB::outputVoltage.u3 = Opaque: Float: 8.000000 V
WIENER-CRATE-MIB::outputVoltage.u4 = Opaque: Float: 8.000000 V

I had to assume this is from the Opaque part of the data because i can get/set INTEGERS normally:

In [30]: session.set('WIENER-CRATE-MIB::outputSwitch.1','0',snmp_type='i')
Out[30]: True
In [31]: session.get('WIENER-CRATE-MIB::outputSwitch.1')
Out[31]: <SNMPVariable value='0' (oid='outputSwitch', oid_index='1', snmp_type='INTEGER')>

Any help is appreciated because this seems the logical way of moving forward rather than reaching out to snmpset with subprocess. Thanks.

ImportError: No module named 'MySQLdb'

I have a MySQL running already on my Raspberry Pi. I have created a DB and tables in it.
On python program, I tried to connect to it but I got this error.

image

remote_port in session API not used

Hi devs,

today I found out that in the original NetSNMP library the remote_port, which is meant to configure SNMP to contact devices on different ports than 161, is not used at all.

However, I recognized that specifying "hostaddress:port" as destination host made NetSNMP use the custom port.

From a quick look at your docs and interface.c I think the problem remains in Easy SNMP code. So I just wanted to let you know in case you like to make your library a bit better than the original one ;-)

I think this could be solved by implement handling the remote_port option or dropping that parameter and document the fact that the Session() parametere "hostname" might also contain a port specification.

No IPv6 support

If you try to use an IPv6 as hostname (such as udp6:[2801:84d:0:ab250::32:5060]), you get a

ValueError: too many values to unpack (expected 2)

as the Session object mistankely tries to unpack the ':' as the specification of a remote port.

As a quick fix I wrote two functions to detect remote ports and extract them:

def has_remote_port(hostname):
    if hostname.startswith('udp6:['):
        return ']:' in hostname

    return ':' in hostname


def extract_remote_port(hostname):
    if ']:' in hostname:
        hostname, remote_port = hostname.split(']:')
        hostname = hostname + ']'
    else:
        hostname, remote_port = hostname.split(':')

    return (hostname, int(remote_port))

And use them in the Session object constructor:

        if has_remote_port(hostname):
            if remote_port:
                raise ValueError(
                    'a remote port was specified yet the hostname appears '
                    'to have a port defined too'
                )
            else:
                hostname, remote_port = extract_remote_port(hostname)

easysnmp.exceptions.EasySNMPNoSuchNameError

I have already installed EasySNMP. But I am getting the error below when I try to use it.
Thanks in advance.

Code :
from easysnmp import snmp_get
snmp_get('1.3.6.1.2.1.1.5', hostname='192.168.254.3', community='public', version=2)

Result :
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "copyright", "credits" or "license()" for more information.

================================ RESTART ================================

Traceback (most recent call last):
File "/home/pi/Desktop/ronnie/test.py", line 3, in
snmp_get('1.3.6.1.2.1.1.5', hostname='192.168.254.3', community='public', version=2)
File "/usr/local/lib/python3.4/dist-packages/easysnmp/easy.py", line 22, in snmp_get
return session.get(oids)
File "/usr/local/lib/python3.4/dist-packages/easysnmp/session.py", line 315, in get
interface.get(self, varlist)
easysnmp.exceptions.EasySNMPNoSuchNameError: no such name error encountered

Different result on Pi Terminal and .PY file

When I run this script on the Pi Terminal, I am getting a result but once I put in on .py file and run it, it doesn't give a result.

from easysnmp import snmp_get
snmp_get('iso.3.6.1.2.1.1.5.0', hostname='192.168.254.3', community='public',version=2)

Here's the screenshot of the Pi Terminal and the .py file with output.
snmp_get no result

installed easysnmp is not working

Hello

I have tried to install easysnmp to RHEL 6.7 server. I installed net-snmp 5.7.3 from source and then tried to install easysnmp with following log. As far as I could see I did not get error while the module's installation. But when I try to use I got following errors

Could you help me about the issue?

Thanks

Python 2.6.6 (r266:84292, May 22 2015, 08:34:51)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from easysnmp import Session
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "easysnmp/__init__.py", line 1, in <module>
    from .easy import (  # noqa
  File "easysnmp/easy.py", line 3, in <module>
    from .session import Session
  File "easysnmp/session.py", line 8, in <module>
    from . import interface
ImportError: cannot import name interface



[root@max02 easysnmp-master]# python
Python 2.6.6 (r266:84292, May 22 2015, 08:34:51)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import easysnmp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "easysnmp/__init__.py", line 1, in <module>
    from .easy import (  # noqa
  File "easysnmp/easy.py", line 3, in <module>
    from .session import Session
  File "easysnmp/session.py", line 8, in <module>
    from . import interface
ImportError: cannot import name interface


[root@max02 easysnmp-master]# python setup.py install
running install
running bdist_egg
running egg_info
writing easysnmp.egg-info/PKG-INFO
writing top-level names to easysnmp.egg-info/top_level.txt
writing dependency_links to easysnmp.egg-info/dependency_links.txt
reading manifest file 'easysnmp.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'easysnmp.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/easysnmp
copying build/lib.linux-x86_64-2.6/easysnmp/interface.so -> build/bdist.linux-x86_64/egg/easysnmp
copying build/lib.linux-x86_64-2.6/easysnmp/__init__.py -> build/bdist.linux-x86_64/egg/easysnmp
copying build/lib.linux-x86_64-2.6/easysnmp/session.py -> build/bdist.linux-x86_64/egg/easysnmp
copying build/lib.linux-x86_64-2.6/easysnmp/compat.py -> build/bdist.linux-x86_64/egg/easysnmp
copying build/lib.linux-x86_64-2.6/easysnmp/exceptions.py -> build/bdist.linux-x86_64/egg/easysnmp
copying build/lib.linux-x86_64-2.6/easysnmp/variables.py -> build/bdist.linux-x86_64/egg/easysnmp
copying build/lib.linux-x86_64-2.6/easysnmp/utils.py -> build/bdist.linux-x86_64/egg/easysnmp
copying build/lib.linux-x86_64-2.6/easysnmp/easy.py -> build/bdist.linux-x86_64/egg/easysnmp
copying build/lib.linux-x86_64-2.6/easysnmp/helpers.py -> build/bdist.linux-x86_64/egg/easysnmp
byte-compiling build/bdist.linux-x86_64/egg/easysnmp/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/easysnmp/session.py to session.pyc
byte-compiling build/bdist.linux-x86_64/egg/easysnmp/compat.py to compat.pyc
byte-compiling build/bdist.linux-x86_64/egg/easysnmp/exceptions.py to exceptions.pyc
byte-compiling build/bdist.linux-x86_64/egg/easysnmp/variables.py to variables.pyc
byte-compiling build/bdist.linux-x86_64/egg/easysnmp/utils.py to utils.pyc
byte-compiling build/bdist.linux-x86_64/egg/easysnmp/easy.py to easy.pyc
byte-compiling build/bdist.linux-x86_64/egg/easysnmp/helpers.py to helpers.pyc
creating stub loader for easysnmp/interface.so
byte-compiling build/bdist.linux-x86_64/egg/easysnmp/interface.py to interface.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying easysnmp.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying easysnmp.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying easysnmp.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying easysnmp.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
zip_safe flag not set; analyzing archive contents...
creating 'dist/easysnmp-0.2.5_dev-py2.6-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing easysnmp-0.2.5_dev-py2.6-linux-x86_64.egg
removing '/usr/lib64/python2.6/site-packages/easysnmp-0.2.5_dev-py2.6-linux-x86_64.egg' (and everything under it)
creating /usr/lib64/python2.6/site-packages/easysnmp-0.2.5_dev-py2.6-linux-x86_64.egg
Extracting easysnmp-0.2.5_dev-py2.6-linux-x86_64.egg to /usr/lib64/python2.6/site-packages
easysnmp 0.2.5-dev is already the active version in easy-install.pth

Installed /usr/lib64/python2.6/site-packages/easysnmp-0.2.5_dev-py2.6-linux-x86_64.egg




[root@max02 easysnmp-master]# snmpget --version
NET-SNMP version: 5.7.3
[root@max02 easysnmp-master]#

Do you move the branch?

Obtaining easysnmp from git+git://github.com/kamakazikamikaze/easysnmp.git@44c62317dbd38b9f3bccf90fac9078b2434c00d9#egg=easysnmp (from -r requirements.txt (line 7))
  Cloning git://github.com/kamakazikamikaze/easysnmp.git (to 44c62317dbd38b9f3bccf90fac9078b2434c00d9) to ./src/easysnmp
  Could not find a tag or branch '44c62317dbd38b9f3bccf90fac9078b2434c00d9', assuming commit.
fatal: reference is not a tree: 44c62317dbd38b9f3bccf90fac9078b2434c00d9

Implement snmp_walk as an iterator.

snmpwalk descends the the OID tree performing an SNMP request/response for each OID. Therefore if snmpwalk is to descend an OID tree with 10000 values, it must send/receive 10000 packets for each OID, aggregate all the responses, and return the list of values.

This is memory inefficient as all the OIDs need to be stored in memory before they're returned. It also means that to select only a few values from the OID tree, you will need to wait until the snmp_walk() method returns, which may take minutes for some agents.

The interface can remain mostly the same by having the netsnmp_snmpwalk function in interface.c return an iterator object. Then for each next() method called, it will query and return the next OID until no more OIDs are left to query. This will be both time and memory efficient, but requires defining an iterator object in the C code and a major refactor of the snmpwalk routine, moving most of the guts into the next() method of the iterator object.

The above is mostly a braindump of how to implement the iterator protocol for snmpwalk. It is probably one of the lowest priorities since the feature works as expected (albeit inefficient). New features/enhancements such as bulkwalk and traps should be implemented first.

Release v0.2.5 update

Since v0.2.4, a handful of small and large updates have been pulled into the project. bulkwalk is the most notable addition with memory leak patches following just behind it.

While this series of tests is overkill, I want to be very certain that my changes will not break existing code, nor introduce additional leaks. Python 3 behavior appears to be fine, however Python 2 seems to still have some odd reports — of which I cannot determine if it is normal or not. This is all to ensure that we will not break anyone's projects that are in production.

Due to some of the code refactoring, and the addition of OS X/macOS brew support, I would like to perform some intensive and thorough tests before proceeding:

Platform Py Version Test Description
Mint 18 2.7.x Memory Leak Checks Frequent equipment polling will take place. No manual GC calls. 4GB RAM will be dedicated to the system. Run for 48 hours; check memory usage and monitor for system failure due to exhausted RAM
Mint 18 3.x Memory Leak Checks Frequent equipment polling will take place. No manual GC calls. 4GB RAM will be dedicated to the system. Run for 48 hours; check memory usage and monitor for system failure due to exhausted RAM
OS X El Capitan 2.7.x Memory Leak Checks Frequent equipment polling will take place. No manual GC calls. 8 GB RAM will be dedicated to the system. Run for 48 hours; check memory usage and monitor for system failure due to exhausted RAM
mac OS Sierra 3.x Memory Leak Checks Frequent equipment polling will take place. No manual GC calls. 8 GB RAM will be dedicated to the system. Run for 48 hours; check memory usage and monitor for system failure due to exhausted RAM
Ubuntu 14.04 LTS 2.7.x Memory Leak Checks A Raspberry Pi will be set up and will be used for testing errors. A lot of set and walk calls will be done on bad OIDs. This will check if PDUs are being released properly in all scenarios. Valid OIDs will also be checked.

Tests will be conducted on Cisco C3560CG, C3750V2, and C3650X models.

Due to time constraints I will be out this weekend, so testing the Pi will be the first to run.

v0.2.5 will be released no later than June 10th

Create a new release

Hi @fgimian,

Can you push out a new release. All changes since 0.2.2 have been bugfixes (with the exception of introducing a README.md).

I would like to do this before delving deep into the enhancement issues.

Exception TypeError: 'expected string or Unicode object, NoneType found'

Hi I test this code

session = Session(hostname='x.x.x.x', community='PTSsnmpCacti', version=2, retries=3, timeout=40)
#for use change dslam port admin status:
session.set('1.3.6.1.2.1.2.2.1.7.101', '2')

I gave this error:
Exception TypeError: 'expected string or Unicode object, NoneType found' in <module 'threading' from '/usr/lib/python2.7/threading.pyc'> ignored

Compile error

I am on CentOS 6.7 with python 2.6, gcc, python-devel and net-snmp-devel installed

I get this error with pip install easysnmp

    Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-EZAtKZ/easysnmp/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-YDzXRK-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.6
    creating build/lib.linux-x86_64-2.6/easysnmp
    copying easysnmp/utils.py -> build/lib.linux-x86_64-2.6/easysnmp
    copying easysnmp/compat.py -> build/lib.linux-x86_64-2.6/easysnmp
    copying easysnmp/session.py -> build/lib.linux-x86_64-2.6/easysnmp
    copying easysnmp/exceptions.py -> build/lib.linux-x86_64-2.6/easysnmp
    copying easysnmp/variables.py -> build/lib.linux-x86_64-2.6/easysnmp
    copying easysnmp/helpers.py -> build/lib.linux-x86_64-2.6/easysnmp
    copying easysnmp/__init__.py -> build/lib.linux-x86_64-2.6/easysnmp
    copying easysnmp/easy.py -> build/lib.linux-x86_64-2.6/easysnmp
    running build_ext
    building 'easysnmp.interface' extension
    creating build/temp.linux-x86_64-2.6
    creating build/temp.linux-x86_64-2.6/easysnmp
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.6 -c easysnmp/interface.c -o build/temp.linux-x86_64-2.6/easysnmp/interface.o -Wno-unused-function
    easysnmp/interface.c: In function ‘netsnmp_create_session_tunneled’:
    easysnmp/interface.c:1723: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1726: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1728: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1735: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1736: error: ‘netsnmp_transport_config_compare’ undeclared (first use in this function)
    easysnmp/interface.c:1736: error: (Each undeclared identifier is reported only once
    easysnmp/interface.c:1736: error: for each function it appears in.)
    easysnmp/interface.c:1740: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1741: warning: implicit declaration of function ‘netsnmp_transport_create_config’
    easysnmp/interface.c:1742: warning: passing argument 2 of ‘CONTAINER_INSERT’ makes pointer from integer without a cast
    /usr/include/net-snmp/library/container.h:391: note: expected ‘const void *’ but argument is of type ‘int’
    easysnmp/interface.c:1745: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1747: warning: passing argument 2 of ‘CONTAINER_INSERT’ makes pointer from integer without a cast
    /usr/include/net-snmp/library/container.h:391: note: expected ‘const void *’ but argument is of type ‘int’
    easysnmp/interface.c:1750: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1752: warning: passing argument 2 of ‘CONTAINER_INSERT’ makes pointer from integer without a cast
    /usr/include/net-snmp/library/container.h:391: note: expected ‘const void *’ but argument is of type ‘int’
    easysnmp/interface.c:1755: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1757: warning: passing argument 2 of ‘CONTAINER_INSERT’ makes pointer from integer without a cast
    /usr/include/net-snmp/library/container.h:391: note: expected ‘const void *’ but argument is of type ‘int’
    error: command 'gcc' failed with exit status 1

Unknown Object ID

I'm not suppose to have to load any Mibs, at least I thought? How info here?

[bijenkins@bmograba ssh_interactions]$ python2.7
Python 2.7.9 (default, Feb  1 2015, 21:31:28) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> oids = ['1.3.6.1.4.1.9.9.42']
>>> 
>>> print easysnmp.easy.snmp_get(
...         oids,
...         hostname='10.8.25.65',
...         version=2,
...         community='nunya'
... )
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/usr/local/lib/python2.7/site-packages/easysnmp/easy.py", line 22, in snmp_get
    return session.get(oids)
  File "/usr/local/lib/python2.7/site-packages/easysnmp/session.py", line 304, in get
    interface.get(self, varlist)
easysnmp.exceptions.EasySNMPUnknownObjectIDError: unknown object id (1.3.6.1.4.1.9.9.42)
>>> 
[bijenkins@bmograba ssh_interactions]$ date
Wed Jun 24 20:41:27 CDT 2015
[bijenkins@bmograba ssh_interactions]$ 
[bijenkins@bmograba ssh_interactions]$ 
[bijenkins@bmograba ssh_interactions]$ snmpwalk -v2c -c nunya 10.8.25.65 1.3.6.1.4.1.9.9.42
SNMPv2-SMI::enterprises.9.9.42.1.1.1.0 = STRING: "2.2.0 Round Trip Time MIB"
SNMPv2-SMI::enterprises.9.9.42.1.1.2.0 = INTEGER: 16384
SNMPv2-SMI::enterprises.9.9.42.1.1.3.0 = Timeticks: (695948803) 80 days, 13:11:28.03
SNMPv2-SMI::enterprises.9.9.42.1.1.4.0 = INTEGER: 41421
SNMPv2-SMI::enterprises.9.9.42.1.1.5.0 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.6.0 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.0 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.1 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.2 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.3 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.4 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.5 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.6 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.7 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.8 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.9 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.10 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.11 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.12 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.13 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.14 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.15 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.16 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.17 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.18 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.19 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.20 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.21 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.7.1.2.22 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.8.1.2.0 = INTEGER: 2
SNMPv2-SMI::enterprises.9.9.42.1.1.8.1.2.1 = INTEGER: 2
SNMPv2-SMI::enterprises.9.9.42.1.1.8.1.2.2 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.8.1.2.3 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.8.1.2.4 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.8.1.2.5 = INTEGER: 1
SNMPv2-SMI::enterprises.9.9.42.1.1.8.1.2.6 = INTEGER: 2
SNMPv2-SMI::enterprises.9.9.42.1.1.8.1.2.7 = INTEGER: 2
SNMPv2-SMI::enterprises.9.9.42.1.1.8.1.2.8 = INTEGER: 2
SNMPv2-SMI::enterprises.9.9.42.1.1.8.1.2.9 = INTEGER: 2...

Memory leak

se = session(...)
while True:
res = se.get(...)
...
sleep(n)

increases the memory foot print -- memory leek
is there a work around?

Segfault in multi-threaded script

Hello,

I am working with EasySNMP for a while now, and created a script using it. It worked fine but the SNMP queries were slow thus I started threading it as the same code is executed 3 times in a row. The situation now is that threads are automatically created execute the same code including SNMP queries and the main thread wait for each one to stop to proceed the end of the code.
While executing it, sometimes everything works perfectly and other times I get a segfault. I have launched it using GDB to get more informations about it.

Here are the logs :

$0 0x00000000005e9d59 in PyUnicodeUCS4_FromFormatV ()
$1 0x00007ffff5ca652b in py_log_msg (log_level=3, printf_fmt=) at easysnmp/interface.c:3397
$2 0x00007ffff5ca9c25 in netsnmp_walk (self=0x0, args=0x0) at easysnmp/interface.c:2786
$3 0x00000000004c9e05 in PyEval_EvalFrameEx ()
$4 0x00000000004c87a1 in PyEval_EvalCodeEx ()
$5 0x00000000004ca31a in PyEval_EvalFrameEx ()
$6 0x00000000004ca592 in PyEval_EvalFrameEx ()
$7 0x00000000004e5fe8 in ?? ()
$8 0x00000000004cc36b in PyEval_EvalFrameEx ()
$9 0x00000000004ca592 in PyEval_EvalFrameEx ()
$10 0x00000000004ca592 in PyEval_EvalFrameEx ()
$11 0x00000000004e5fe8 in ?? ()
$12 0x00000000005045d8 in ?? ()
$13 0x00000000004d1a1b in PyEval_CallObjectWithKeywords ()
$14 0x00000000005bc102 in ?? ()
$15 0x00007ffff7bc70a4 in start_thread (arg=0x7fffeef74700) at pthread_create.c:309
$16 0x00007ffff6fd904d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

I have tried to keep the same code and making it run with only one thread creation. In this very case I don't get any segfault. Thus the problem really is when there are two new threads running at the same time.

I know EasySNMP is not said to be thread safe but if you could help me find a solution it would be very nice.

Thanks guys !

Error installing easysnmp through pip on docker container with python 2.7

Hi,

I'm getting an error of file not found when attempted to install this library on my docker container.
can someone give me some advice on how to fix this?

pip install easysnmp
Collecting easysnmp
  Downloading easysnmp-0.2.4.tar.gz
Building wheels for collected packages: easysnmp
  Running setup.py bdist_wheel for easysnmp: started
  Running setup.py bdist_wheel for easysnmp: finished with status 'error'
  Complete output from command /usr/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-jO26Xl/easysnmp/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpSHS6Jfpip-wheel- --python-tag cp27:
  sh: 1: net-snmp-config: not found
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  creating build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/easy.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/session.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/helpers.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/utils.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/__init__.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/variables.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/compat.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/exceptions.py -> build/lib.linux-x86_64-2.7/easysnmp
  running build_ext
  building 'easysnmp.interface' extension
  creating build/temp.linux-x86_64-2.7
  creating build/temp.linux-x86_64-2.7/easysnmp
  gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c easysnmp/interface.c -o build/temp.linux-x86_64-2.7/easysnmp/interface.o -Wno-unused-function
  easysnmp/interface.c:3:38: fatal error: net-snmp/net-snmp-config.h: No such file or directory
   #include <net-snmp/net-snmp-config.h>
                                        ^
  compilation terminated.
  error: command 'gcc' failed with exit status 1

Thanks

container.h:391

Failing to install easysnmp via pip

 easysnmp/interface.c: In function ‘netsnmp_create_session_tunneled’:
    easysnmp/interface.c:1723: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1726: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1728: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1735: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1736: error: ‘netsnmp_transport_config_compare’ undeclared (first use in this function)
    easysnmp/interface.c:1736: error: (Each undeclared identifier is reported only once
    easysnmp/interface.c:1736: error: for each function it appears in.)
    easysnmp/interface.c:1740: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1741: warning: implicit declaration of function ‘netsnmp_transport_create_config’
    easysnmp/interface.c:1742: warning: passing argument 2 of ‘CONTAINER_INSERT’ makes pointer from integer without a cast
    /usr/include/net-snmp/library/container.h:391: note: expected ‘const void *’ but argument is of type ‘int’
    easysnmp/interface.c:1745: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1747: warning: passing argument 2 of ‘CONTAINER_INSERT’ makes pointer from integer without a cast
    /usr/include/net-snmp/library/container.h:391: note: expected ‘const void *’ but argument is of type ‘int’
    easysnmp/interface.c:1750: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1752: warning: passing argument 2 of ‘CONTAINER_INSERT’ makes pointer from integer without a cast
    /usr/include/net-snmp/library/container.h:391: note: expected ‘const void *’ but argument is of type ‘int’
    easysnmp/interface.c:1755: error: ‘SnmpSession’ has no member named ‘transport_configuration’
    easysnmp/interface.c:1757: warning: passing argument 2 of ‘CONTAINER_INSERT’ makes pointer from integer without a cast
    /usr/include/net-snmp/library/`container.h:391`: note: expected ‘const void *’ but argument is of type ‘int’
    error: command 'gcc' failed with exit status 1

undefined symbol: netsnmp_transport_config_compare - error

Python 2.7.10
RHEL 6.7
GCC

Looks to a issue with the way the interface.c file is compiled to interace.so... Any ideas here?

from CLI:

Python 2.7.10 (default, Jul 21 2015, 10:07:01) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> from easysnmp import Session
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/JKHY/bijenkins/.pyenv/versions/because-the-internet/lib/python2.7/site-packages/easysnmp/__init__.py", line 1, in <module>
    from .easy import (  # noqa
  File "/home/JKHY/bijenkins/.pyenv/versions/because-the-internet/lib/python2.7/site-packages/easysnmp/easy.py", line 3, in <module>
    from .session import Session
  File "/home/JKHY/bijenkins/.pyenv/versions/because-the-internet/lib/python2.7/site-packages/easysnmp/session.py", line 8, in <module>
    from . import interface
ImportError: /home/JKHY/bijenkins/.pyenv/versions/because-the-internet/lib/python2.7/site-packages/easysnmp/interface.so: undefined symbol: netsnmp_transport_config_compare
>>> 

From python:

(because-the-internet)[bijenkins@bmograbadev ~]$ pip install easysnmp
Collecting easysnmp
Installing collected packages: easysnmp
Successfully installed easysnmp-0.2.4
(because-the-internet)[bijenkins@bmograbadev ~]$ 
(because-the-internet)[bijenkins@bmograbadev ~]$ 
(because-the-internet)[bijenkins@bmograbadev ~]$ 
(because-the-internet)[bijenkins@bmograbadev ~]$ python easysnmptest.py
Traceback (most recent call last):
  File "easysnmptest.py", line 1, in <module>
    from easysnmp import Session
  File "/home/JKHY/bijenkins/.pyenv/versions/because-the-internet/lib/python2.7/site-packages/easysnmp/__init__.py", line 1, in <module>
    from .easy import (  # noqa
  File "/home/JKHY/bijenkins/.pyenv/versions/because-the-internet/lib/python2.7/site-packages/easysnmp/easy.py", line 3, in <module>
    from .session import Session
  File "/home/JKHY/bijenkins/.pyenv/versions/because-the-internet/lib/python2.7/site-packages/easysnmp/session.py", line 8, in <module>
    from . import interface
ImportError: /home/JKHY/bijenkins/.pyenv/versions/because-the-internet/lib/python2.7/site-packages/easysnmp/interface.so: undefined symbol: netsnmp_transport_config_compare

ImportError: easysnmp/interface.so: undefined symbol: netsnmp_transport_config_compare

Hi Fotis,

I moved this issue off email and into your formal support at your request.
I have python 2.6.6 and I installed easysnmp using pip as requested

pip install easysnmp

Any idea why the error?

Thanks,
Mike

# pwd
/usr/lib64/python2.6/site-packages
[root@scaleha-chef site-packages]# ls -ltr | grep easy
drwxr-xr-x   2 root root   4096 Jun  5 11:31 easysnmp
drwxr-xr-x   2 root root   4096 Jun  5 11:31 easysnmp-0.2.2-py2.6.egg-info

# python
Python 2.6.6 (r266:84292, Jun  5 2015, 10:33:19)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from easysnmp import Session
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "easysnmp/__init__.py", line 1, in <module>
    from .easy import (  # noqa
  File "easysnmp/easy.py", line 3, in <module>
    from .session import Session
  File "easysnmp/session.py", line 8, in <module>
    from . import interface
ImportError: easysnmp/interface.so: undefined symbol: netsnmp_transport_config_compare
>>>
# python --version
Python 2.6.6

Exception EasySNMPUnknownObjectIDError raised for an OID that exists

I haven't investigated the code yet, but I found the following bug in easysnmp.

I have installed the stock SNMP agent with the default configuration.

I fetch a single OID using snmpget command:

$ snmpget -On -v 2c -c redacted localhost 1.3.6.1.4.1.2021.11.53.0
.1.3.6.1.4.1.2021.11.53.0 = Counter32: 444734235

Now, when I use easysnmp with the following script:

import easysnmp

oids = ['1.3.6.1.4.1.2021.11.53.0']

print easysnmp.easy.snmp_get(
        oids,
        hostname='localhost',
        version=2,
        community='redacted'
)

I get the following exception:

Traceback (most recent call last):
  File "test_easysnmp.py", line 9, in <module>
    community='redacted'
  File "/srv/virtualenvs/bpl-poll-consumer/local/lib/python2.7/site-packages/easysnmp/easy.py", line 20, in snmp_get
    return session.get(oids)
  File "/srv/virtualenvs/bpl-poll-consumer/local/lib/python2.7/site-packages/easysnmp/session.py", line 299, in get
    interface.get(self, varlist)
easysnmp.exceptions.EasySNMPUnknownObjectIDError: unknown object id (1.3.6.1.4.1.2021.11.53.0)

So the easysnmp.interface is raising the exception except the OID itself does exist as demonstrated by the above snmpget command.

MAC address displaying in binary

I am lodging this issue on behalf of someone else.

Below I'm querying a standard Cisco device for the MAC addresses of each interface, all MIBs enabled.

$ cat ~/.snmp/snmp.conf
mibs +ALL
$ snmpwalk  -On -v2c -c public redacted ifPhysAddress
.1.3.6.1.2.1.2.2.1.6.1 = STRING: 7c:ad:74:f1:84:0
.1.3.6.1.2.1.2.2.1.6.2 = STRING: 7c:ad:74:f1:84:1
.1.3.6.1.2.1.2.2.1.6.3 = STRING:
.1.3.6.1.2.1.2.2.1.6.4 = STRING:
.1.3.6.1.2.1.2.2.1.6.5 = STRING: 7c:ad:74:f1:84:0
.1.3.6.1.2.1.2.2.1.6.6 = STRING: 7c:ad:74:f1:84:0
.1.3.6.1.2.1.2.2.1.6.7 = STRING: 7c:ad:74:f1:84:1

With MIBs disabled:

$ mv ~/.snmp ~/.snmp.bak
$ snmpwalk -m'' -On -v2c -c public redacted .1.3.6.1.2.1.2.2.1.6
.1.3.6.1.2.1.2.2.1.6.1 = Hex-STRING: 7C AD 74 F1 84 00
.1.3.6.1.2.1.2.2.1.6.2 = Hex-STRING: 7C AD 74 F1 84 01
.1.3.6.1.2.1.2.2.1.6.3 = ""
.1.3.6.1.2.1.2.2.1.6.4 = ""
.1.3.6.1.2.1.2.2.1.6.5 = Hex-STRING: 7C AD 74 F1 84 00
.1.3.6.1.2.1.2.2.1.6.6 = Hex-STRING: 7C AD 74 F1 84 00
.1.3.6.1.2.1.2.2.1.6.7 = Hex-STRING: 7C AD 74 F1 84 01

Note the latter represents the MAC address as a Hex String. I believe SNMP is not processing the "textual convention" (I'll explain this soon) and showing the raw data in hex form.

Easysnmp doesn't honour the textual conventions when MIBs are loaded.

In [46]: v = snmp_get(('ifPhysAddress', 1), hostname='redacted', community='public', version=2)

# this is the binary representation of the MAC address bytes
In [48]: v.value
Out[48]: u'|\xadt\xf1\x84\x00'

# convert into a hex string separated by :
In [49]: ':'.join('{:02x}'.format(ord(x)) for x in v.value)
Out[49]: '7c:ad:74:f1:84:00'

The reason snmpwalk displayed it as a STRING in the standard convention is because it is defined this way in the MIBs:

$ snmptranslate -On -Td IF-MIB::ifPhysAddress
.1.3.6.1.2.1.2.2.1.6
ifPhysAddress OBJECT-TYPE
  -- FROM       IF-MIB, RFC1213-MIB
  -- TEXTUAL CONVENTION PhysAddress
  SYNTAX        OCTET STRING
  DISPLAY-HINT  "1x:"
  MAX-ACCESS    read-only
  STATUS        current
  DESCRIPTION   "The interface's address at its protocol sub-layer.  For
            example, for an 802.x interface, this object normally
            contains a MAC address.  The interface's media-specific MIB
            must define the bit and byte ordering and the format of the
            value of this object.  For interfaces which do not have such
            an address (e.g., a serial line), this object should contain
            an octet string of zero length."
::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) interfaces(2) ifTable(2) ifEntry(1) 6 }

The PhysAddress TEXTUAL CONVENTION is a MIB thing that appears to be honoured by both pysnmp when pysnmp-mibs are loaded and the standard NET-SNMP commands.

I'm not sure if this is something that could be sorted from the underlying C interface or in the Python side.

close() method

Hi, thanks for working on this very useful body of code.

We are trying to issue GET requests for 12 OIDs to about 170 devices, using Python process-based multiprocessing (mp.Pool(), pool.apply_async()), set up to run between 4- and 32-way parallel. We previously tried multithreading but ran into inconsistencies in the results (specifically, returned VarBinds missing OIDs, the values may have been correct; but this is another topic).

After creating around 90 sessions we run into some resource limit and are unable to collect from the remaining 80 or so devices.

After some experimentation we added a Session.close() method and modified the Session.del() method to check the self.sess_ptr against None. Calling Session.close() after each GET allows us to read all target devices without encountering the resource limit.

Here's the relevant section of session.py:

  def close(self):
        if self.sess_ptr is not None:
            status = interface.delete_session(self)
            self.sess_ptr = None
        return status

    def __del__(self):
        """Deletes the session and frees up memory"""
        if self.sess_ptr is not None:
            status = interface.delete_session(self)
            self.sess_ptr = None
        return

Please let us know what you think of this.

Also, a detail, the descriptive string for the Python delete_session method in interface.c is incorrect:

    {
            "delete_session",
            netsnmp_delete_session,
            METH_VARARGS,
            "create a netsnmp session."
        },

Best
Tim

New maintainer requested

Hey there guys,

Originally @nnathan and I re-developed this library for use in one of our projects at work. Unfortunately, I am no longer working on the project at all and Nav (and the guys) have decided not to use this library in the end.

AS such, we are unlikely to continue developing it, although we do feel it has great potential and is a far better starting point than the original Net-SNMP Python bindings with proper unit tests and a Pythonic interface, along with documentation and an installer which is accessible via pip.

I would like to open the floor to anyone who would be interested in taking over this project and owning it moving forward.

Thanks so much for your time
Fotis

Make EasySNMPNoSuchObjectError exception optional

I'm running the following script:

#!/usr/bin/python

import easysnmp
oids = [
    '1.3.6.1.4.1.2021.13.15.1.1.6.15',
    '1.3.6.1.2.1.31.1.1.1.7.3',
    '1.3.6.1.2.1.11.5.0',
    '1.3.6.1.4.1.2021.11.55.0',
    '1.3.6.1.4.1.2021.13.15.1.1.6.13',
    '1.3.6.1.2.1.11.16.0',
    '1.3.6.1.4.1.2021.11.60.0',
    '1.3.6.1.4.1.2021.10.1.5.2',
    '1.3.6.1.4.1.2021.13.15.1.1.5.8',
    '1.3.6.1.4.1.2021.13.15.1.1.5.9',
    '1.3.6.1.4.1.4502.1.11.101.1',
    '1.3.6.1.2.1.11.13.0',
    '1.3.6.1.4.1.2021.13.15.1.1.6.11',
    '1.3.6.1.2.1.11.14.0',
    '1.3.6.1.4.1.2021.13.15.1.1.5.1',
    '1.3.6.1.4.1.2021.13.15.1.1.5.2',
    '1.3.6.1.4.1.2021.13.15.1.1.5.3',
    '1.3.6.1.4.1.2021.13.15.1.1.5.4',
    '1.3.6.1.4.1.2021.13.15.1.1.5.5',
    '1.3.6.1.4.1.2021.11.58.0'
]

values = easysnmp.easy.snmp_get(
    oids,
    hostname='10.255.30.133',
    version=2,
    community='public'
)

I get the following error:

$ python test_snmp.py
Traceback (most recent call last):
  File "test_snmp.py", line 31, in <module>
    community='enf0r5er'
  File "/srv/virtualenvs/bpl-poll-consumer/local/lib/python2.7/site-packages/easysnmp/easy.py", line 22, in snmp_get
    return session.get(oids)
  File "/srv/virtualenvs/bpl-poll-consumer/local/lib/python2.7/site-packages/easysnmp/session.py", line 308, in get
    validate_results(varlist)
  File "/srv/virtualenvs/bpl-poll-consumer/local/lib/python2.7/site-packages/easysnmp/session.py", line 73, in validate_results
    raise EasySNMPNoSuchObjectError('no such object could be found')

For shits and giggles, here is the tcpdump:

$ sudo tcpdump -ni eth0 host 10.255.30.133
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
14:41:35.440681 IP 10.183.23.54.40022 > 10.255.30.133.161:  C=public GetRequest(361)  .1.3.6.1.4.1.2021.13.15.1.1.6.15 .1.3.6.1.2.1.31.1.1.1.7.3 .1.3.6.1.2.1.11.5.0 .1.3.6.1.4.1.2021.11.55.0 .1.3.6.1.4.1.2021.13.15.1.1.6.13 .1.3.6.1.2.1.11.16.0 .1.3.6.1.4.1.2021.11.60.0 .1.3.6.1.4.1.2021.10.1.5.2 .1.3.6.1.4.1.2021.13.15.1.1.5.8 .1.3.6.1.4.1.2021.13.15.1.1.5.9 .1.3.6.1.4.1.4502.1.11.101.1 .1.3.6.1.2.1.11.13.0 .1.3.6.1.4.1.2021.13.15.1.1.6.11 .1.3.6.1.2.1.11.14.0 .1.3.6.1.4.1.2021.13.15.1.1.5.1 .1.3.6.1.4.1.2021.13.15.1.1.5.2 .1.3.6.1.4.1.2021.13.15.1.1.5.3 .1.3.6.1.4.1.2021.13.15.1.1.5.4 .1.3.6.1.4.1.2021.13.15.1.1.5.5 .1.3.6.1.4.1.2021.11.58.0
14:41:35.455465 IP 10.255.30.133.161 > 10.183.23.54.40022:  C=public GetResponse(393)  .1.3.6.1.4.1.2021.13.15.1.1.6.15=0 .1.3.6.1.2.1.31.1.1.1.7.3=104046 .1.3.6.1.2.1.11.5.0=0 .1.3.6.1.4.1.2021.11.55.0=0 .1.3.6.1.4.1.2021.13.15.1.1.6.13=0 .1.3.6.1.2.1.11.16.0=88 .1.3.6.1.4.1.2021.11.60.0=1896669006 .1.3.6.1.4.1.2021.10.1.5.2=356 .1.3.6.1.4.1.2021.13.15.1.1.5.8=0 .1.3.6.1.4.1.2021.13.15.1.1.5.9=0 .1.3.6.1.4.1.4502.1.11.101.1=[noSuchObject] .1.3.6.1.2.1.11.13.0=8923579 .1.3.6.1.4.1.2021.13.15.1.1.6.11=0 .1.3.6.1.2.1.11.14.0=0 .1.3.6.1.4.1.2021.13.15.1.1.5.1=0 .1.3.6.1.4.1.2021.13.15.1.1.5.2=0 .1.3.6.1.4.1.2021.13.15.1.1.5.3=0 .1.3.6.1.4.1.2021.13.15.1.1.5.4=0 .1.3.6.1.4.1.2021.13.15.1.1.5.5=0 .1.3.6.1.4.1.2021.11.58.0=2176755532

Since the SNMP agent responds, the easysnmp interface should respond to the application with a way to identify which OIDs return noSuchObject, rather than raise an exception.

session.get truncates return value to 4096 bytes

I use snmpget to retrieve the result of measurements returning a large number of bytes. For example in Linux shell:
snmpget -v2c -c public 10.10.237.48 1.3.6.1.4.1.637.61.1.39.7.4.1.2.100958208 | wc -w
and it returns
17419 octets.
The same command, using session.get for the same OID returns only 4096 bytes. If the measurement result has a number of bytes, less than 4096, the same number is found for both command shell and for session.get. Is there any limitation on the maximum number of bytes that can return session.get function?

Thank you,
Octavian

Non-increasing oids support

Hello

Can you please add support for non-increasing OIDs? (like -Cc key for snmpwalk)
This is sometimes needed for situation like this:

$ snmpwalk -v2c -c private 10.90.90.90 1.0.8802.1.1.2.1.4.1.1.7
iso.0.8802.1.1.2.1.4.1.1.7.286983865.1.49 = Hex-STRING: F0 7D 68 87 8D 7F
iso.0.8802.1.1.2.1.4.1.1.7.286985056.2.41 = Hex-STRING: F0 7D 68 87 86 F4
iso.0.8802.1.1.2.1.4.1.1.7.286985685.3.28 = Hex-STRING: F0 7D 68 87 89 E2
iso.0.8802.1.1.2.1.4.1.1.7.286983323.4.47 = Hex-STRING: F0 7D 68 87 7F 56
Error: OID not increasing: iso.0.8802.1.1.2.1.4.1.1.7.286985685.3.28

= iso.0.8802.1.1.2.1.4.1.1.7.286983323.4.47

$ python noninctest.py
[<SNMPVariable value='}h (contains binary)' (oid='.1.0.8802.1.1.2.1.4.1.1.7.286992899.1', oid_index='49', snmp_type='OCTETSTR')>]

$ cat noninctest.py
from easysnmp import Session

current_session = Session('10.90.90.90', community='private', version=2, use_numeric=True)
print(current_session.walk(['1.0.8802.1.1.2.1.4.1.1.7']))

no spoof ip source?

Hello, great lib
much simpler and easier than pysnmp, well done!

but I could not find a way to spoof ip source, would be nice to have that implemented

Win32 Install Error

Hi All,

Stumbled on a install problem on windows 7 which I'm guessing has something to do with the native windows compiler but google search does not seem to have a fix. Install output bellow, any suggestions on how to fix this is appreciated. Thanks, Phil

C:\scripts\GIT\easysnmp>python setup.py install
'net-snmp-config' is not recognized as an internal or external command,
operable program or batch file.
C:\Python34\lib\site-packages\setuptools-18.2-py3.4.egg\setuptools\dist.py:285: UserWarning: Normalizing '0.2.5-dev' to '0.2.5.dev
0'
running install
running bdist_egg
running egg_info
creating easysnmp.egg-info
writing dependency_links to easysnmp.egg-info\dependency_links.txt
writing top-level names to easysnmp.egg-info\top_level.txt
writing easysnmp.egg-info\PKG-INFO
writing manifest file 'easysnmp.egg-info\SOURCES.txt'
reading manifest file 'easysnmp.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'easysnmp.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
creating build
creating build\lib.win32-3.4
creating build\lib.win32-3.4\easysnmp
copying easysnmp\compat.py -> build\lib.win32-3.4\easysnmp
copying easysnmp\easy.py -> build\lib.win32-3.4\easysnmp
copying easysnmp\exceptions.py -> build\lib.win32-3.4\easysnmp
copying easysnmp\helpers.py -> build\lib.win32-3.4\easysnmp
copying easysnmp\session.py -> build\lib.win32-3.4\easysnmp
copying easysnmp\utils.py -> build\lib.win32-3.4\easysnmp
copying easysnmp\variables.py -> build\lib.win32-3.4\easysnmp
copying easysnmp__init__.py -> build\lib.win32-3.4\easysnmp
running build_ext
building 'easysnmp.interface' extension
creating build\temp.win32-3.4
creating build\temp.win32-3.4\Release
creating build\temp.win32-3.4\Release\easysnmp
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python34\include -IC:
Python34\include /Tceasysnmp/interface.c /Fobuild\temp.win32-3.4\Release\easysnmp/interface.obj -Wno-unused-function
cl : Command line error D8021 : invalid numeric argument '/Wno-unused-function'
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.exe' failed with exit status 2

C:\scripts\GIT\easysnmp>python setup.py build
'net-snmp-config' is not recognized as an internal or external command,
operable program or batch file.
C:\Python34\lib\site-packages\setuptools-18.2-py3.4.egg\setuptools\dist.py:285: UserWarning: Normalizing '0.2.5-dev' to '0.2.5.dev
0'
running build
running build_py
running build_ext
building 'easysnmp.interface' extension
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python34\include -IC:
Python34\include /Tceasysnmp/interface.c /Fobuild\temp.win32-3.4\Release\easysnmp/interface.obj -Wno-unused-function
cl : Command line error D8021 : invalid numeric argument '/Wno-unused-function'
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.exe' failed with exit status 2

easysnmp session.set problem

Hi,

I have the following code:

    session = Session(hostname=Hostname, community=Community, version=2)

.................................................
session.set('1.3.6.1.4.1.637.61.1.39.3.7.1.13.67108864', '2','i')

For the last line I get the error:
session.set('.1.3.6.1.4.1.637.61.1.39.3.7.1.13.67108864', '2','i')
File "/usr/lib64/python2.7/site-packages/easysnmp/session.py", line 351, in set
success = interface.set(self, varlist)
easysnmp.exceptions.EasySNMPUndeterminedTypeError: a type could not be determine for the object

Thank you for your help.

Python 3 support

First off, this library is excellent!!! Thank you for overhauling the terrible official bindings.

The library works perfectly for me with Python 2.7.10, but interface.c doesn't compile for Python 3. Is there any chance that Python 3 support is on the roadmap?

OSX - flat namespace in /usr/local/lib/python2.7/site-packages/easysnmp/interface.so

I can see a similar issue in this post here #42 but I'm not sure if that same issues applies to me or not.

basically i have installs python via home-brew

alexs-mbp:~ alex$ which python
/usr/local/bin/python
alexs-mbp:~ alex$

and have install easysnmp via pip and net-snmp via home-brew

alexs-mbp:~alex$ python
Python 2.7.13 (default, Dec 18 2016, 07:03:39) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import easysnmp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/easysnmp/__init__.py", line 1, in <module>
    from .easy import (  # noqa
  File "/usr/local/lib/python2.7/site-packages/easysnmp/easy.py", line 3, in <module>
    from .session import Session
  File "/usr/local/lib/python2.7/site-packages/easysnmp/session.py", line 8, in <module>
    from . import interface
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/easysnmp/interface.so, 2): Symbol not found: _netsnmp_transport_config_compare
  Referenced from: /usr/local/lib/python2.7/site-packages/easysnmp/interface.so
  Expected in: flat namespace
 in /usr/local/lib/python2.7/site-packages/easysnmp/interface.so

I also get this message when using brew to check

 Warning: net-snmp is a keg-only and another version is linked to opt.
Use `brew install --force` if you want to install this version
alexs-mbp:~ alex$ brew install net-snmp --force
Warning: net-snmp-5.7.3 already installed, it's just not linked.
alexs-mbp:~ alex$ 

i did a brew link which gives me the below

Warning: net-snmp is a keg-only and another version is linked to opt.
Use `brew install --force` if you want to install this version
alexs-mbp:~ alex$ brew install net-snmp --force
Warning: net-snmp-5.7.3 already installed, it's just not linked.
alexs-mbp:~ alex$ brew link net-snmp
Warning: net-snmp is keg-only and must be linked with --force
Note that doing so can interfere with building software.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/net-snmp/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/net-snmp/sbin:$PATH"' >> ~/.bash_profile
alexs-mbp:~ alexwilloughby$ brew link net-snmp --force
Linking /usr/local/Cellar/net-snmp/5.7.3... 182 symlinks created

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/net-snmp/bin:$PATH"' >> ~/.bash_profile
  echo 'export PATH="/usr/local/opt/net-snmp/sbin:$PATH"' >> ~/.bash_profile
alexs-mbp:~ alex$ 

starting python and importing easysnmp still gives me the same error does anyone know how to fix this?

Thanks

easysnmp-0.2.3 on PyPi does not include simple_bitarray.h

After installing the dependencies, installing Easy SNMP with pip in a virtualenv fails because it can't find simple_bitarray.h:

(snmp)longb4@varyag:~$ pip install easysnmp
Collecting easysnmp
  Using cached easysnmp-0.2.3.tar.gz
Building wheels for collected packages: easysnmp
  Running setup.py bdist_wheel for easysnmp
  Complete output from command /home/longb4/.virtualenvs/snmp/bin/python -c "import setuptools;__file__='/tmp/pip-build-plNWI0/easysnmp/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpDK9tOHpip-wheel-:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  creating build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/utils.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/exceptions.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/__init__.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/session.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/easy.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/helpers.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/variables.py -> build/lib.linux-x86_64-2.7/easysnmp
  copying easysnmp/compat.py -> build/lib.linux-x86_64-2.7/easysnmp
  running build_ext
  building 'easysnmp.interface' extension
  creating build/temp.linux-x86_64-2.7
  creating build/temp.linux-x86_64-2.7/easysnmp
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c easysnmp/interface.c -o build/temp.linux-x86_64-2.7/easysnmp/interface.o -Wno-unused-function
  easysnmp/interface.c:25:29: fatal error: simple_bitarray.h: No such file or directory
   #include "simple_bitarray.h"
                               ^
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for easysnmp
Failed to build easysnmp
Installing collected packages: easysnmp
  Running setup.py install for easysnmp
    Complete output from command /home/longb4/.virtualenvs/snmp/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-plNWI0/easysnmp/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-J5Bi_M-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/longb4/.virtualenvs/snmp/include/site/python2.7/easysnmp:
    running install
    running build
    running build_py
    running build_ext
    building 'easysnmp.interface' extension
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c easysnmp/interface.c -o build/temp.linux-x86_64-2.7/easysnmp/interface.o -Wno-unused-function
    easysnmp/interface.c:25:29: fatal error: simple_bitarray.h: No such file or directory
     #include "simple_bitarray.h"
                                 ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/home/longb4/.virtualenvs/snmp/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-build-plNWI0/easysnmp/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-J5Bi_M-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/longb4/.virtualenvs/snmp/include/site/python2.7/easysnmp" failed with error code 1 in /tmp/pip-build-plNWI0/easysnmp

Manually downloading and extracting the version of Easy SNMP that pip tried to install (0.2.3) shows that simple_bitarray.h is not in the archive, despite existing in the 0.2.3 release on GitHub:

longb4@varyag:~/tmp$ wget https://pypi.python.org/packages/source/e/easysnmp/easysnmp-0.2.3.tar.gz
--2015-07-08 10:15:19--  https://pypi.python.org/packages/source/e/easysnmp/easysnmp-0.2.3.tar.gz
Resolving pypi.python.org (pypi.python.org)... 23.235.47.223
Connecting to pypi.python.org (pypi.python.org)|23.235.47.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 28846 (28K) [application/octet-stream]
Saving to: ‘easysnmp-0.2.3.tar.gz’

easysnmp-0.2.3.tar.gz                                                100%[======================================================================================================================================================================>]  28.17K  --.-KB/s   in 0.001s 

2015-07-08 10:15:19 (37.1 MB/s) - ‘easysnmp-0.2.3.tar.gz’ saved [28846/28846]

longb4@varyag:~/tmp$ tar xzvf easysnmp-0.2.3.tar.gz 
easysnmp-0.2.3/
easysnmp-0.2.3/easysnmp/
easysnmp-0.2.3/easysnmp/__init__.py
easysnmp-0.2.3/easysnmp/compat.py
easysnmp-0.2.3/easysnmp/easy.py
easysnmp-0.2.3/easysnmp/exceptions.py
easysnmp-0.2.3/easysnmp/helpers.py
easysnmp-0.2.3/easysnmp/interface.c
easysnmp-0.2.3/easysnmp/session.py
easysnmp-0.2.3/easysnmp/utils.py
easysnmp-0.2.3/easysnmp/variables.py
easysnmp-0.2.3/easysnmp.egg-info/
easysnmp-0.2.3/easysnmp.egg-info/dependency_links.txt
easysnmp-0.2.3/easysnmp.egg-info/PKG-INFO
easysnmp-0.2.3/easysnmp.egg-info/SOURCES.txt
easysnmp-0.2.3/easysnmp.egg-info/top_level.txt
easysnmp-0.2.3/PKG-INFO
easysnmp-0.2.3/setup.cfg
easysnmp-0.2.3/setup.py
longb4@varyag:~/tmp$ cd easysnmp-0.2.3
longb4@varyag:~/tmp/easysnmp-0.2.3$ grep -nR simple_bitarray.h                                                                                                                                                                                                                    
easysnmp/interface.c:25:#include "simple_bitarray.h"
longb4@varyag:~/tmp/easysnmp-0.2.3$ find . -name simple_bitarray.h
longb4@varyag:~/tmp/easysnmp-0.2.3$

Having pip install Easy SNMP 0.2.3 as hosted on GitHub succeeds:

(snmp)longb4@varyag:~$ pip install https://github.com/fgimian/easysnmp/zipball/0.2.3
Collecting https://github.com/fgimian/easysnmp/zipball/0.2.3
  Downloading https://github.com/fgimian/easysnmp/zipball/0.2.3 (78kB)
    100% |████████████████████████████████| 81kB 3.1MB/s 
Installing collected packages: easysnmp
  Running setup.py install for easysnmp
Successfully installed easysnmp-0.2.3

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.