Installation¶
pip install snmp¶
The simplest way to install snmp is with pip:
pip install snmp
Source Download¶
You can also download snmp directly from GitHub. Copy the snmp
subdirectory to your desired installation location.
Customization¶
The snmp library is written almost exclusively in Python, using only the
standard library. The one exception is the snmp.security.usm.priv module,
which relies on third-party libraries to support encryption in SNMPv3 (under the
User-Based Security Model). There are two provided implementations, one that
depends on the pycryptodome library, and one that uses OpenSSL. The
module initialization code will automatically select an implementation based
on which dependencies are installed.
pycryptodome¶
The default snmp.security.usm.priv implementation uses pycryptodome
to perform the encryption and decryption. pycryptodome will be installed
automatically when you install snmp with pip. There is also a
requirements.txt file provided in snmp/security/usm/priv/pycryptodome,
which specifies the precise requirement.
OpenSSL¶
The other snmp.security.usm.priv implementation uses the EVP_* family
of functions, from OpenSSL. To enable it, you will use the cffi library to
generate and compile a Python module that can interface with OpenSSL. If
present, this module will always take precedence over pycryptodome, based on
the assumption that you would not take the time to install it unless you wanted
to use it.
First, install the cffi library with this command:
pip install -r snmp/cffi/requirements.txt
After installing cffi, run the following commands in the Python interactive
shell:
>>> from snmp.cffi.openssl import ffi
>>> ffi.compile()
If this command fails, the most likely cause is from missing OpenSSL headers. Most Linux distributions provide OpenSSL binaries automatically, but require you to install the headers separately. The precise instructions will vary by system, so it will be up to you to figure it out.
In Ubuntu, it’s as simple as
sudo apt install libssl-dev
You can also download and install OpenSSL from source quite easily (run
Configure, and then make install). If you install in a non-standard
location, then set CPPFLAGS="-isystem <prefix>/include" and
LDFLAGS="-Wl,-rpath,<prefix>/lib" in your environment before opening the
Python interactive shell.
If installing OpenSSL headers doesn’t fix your issue, or you get stuck, please
file a GitHub issue or find my email address in pyproject.toml and email me
directly.