pysnmp-sky/README.md

161 lines
5.9 KiB
Markdown
Raw Permalink Normal View History

2016-03-07 22:28:06 +01:00
SNMP library for Python
-----------------------
[![PyPI](https://img.shields.io/pypi/v/pysnmp.svg?maxAge=2592000)](https://pypi.org/project/pysnmp/)
[![Python Versions](https://img.shields.io/pypi/pyversions/pysnmp.svg)](https://pypi.org/project/pysnmp/)
2016-03-12 10:08:18 +01:00
[![Build status](https://travis-ci.org/etingof/pysnmp.svg?branch=master)](https://secure.travis-ci.org/etingof/pysnmp)
2018-08-05 21:27:08 +02:00
[![GitHub license](https://img.shields.io/badge/license-BSD-blue.svg)](https://raw.githubusercontent.com/etingof/pysnmp/master/LICENSE.rst)
2016-03-07 22:28:06 +01:00
This is a pure-Python, open source and free implementation of v1/v2c/v3
SNMP engine distributed under 2-clause [BSD license](http://snmplabs.com/pysnmp/license.html).
2016-03-07 22:28:06 +01:00
The PySNMP project was initially sponsored by a [PSF](http://www.python.org/psf/) grant.
Thank you!
Features
--------
* Complete SNMPv1/v2c and SNMPv3 support
* SMI framework for resolving MIB information and implementing SMI
Managed Objects
* Complete SNMP entity implementation
* USM Extended Security Options support (3DES, 192/256-bit AES encryption)
2017-02-04 19:59:02 +01:00
* Extensible network transports framework (UDP/IPv4, UDP/IPv6)
2016-03-07 22:28:06 +01:00
* Asynchronous socket-based IO API support
* [Twisted](http://twistedmatrix.com), [Asyncio](https://docs.python.org/3/library/asyncio.html)
and [Trollius](http://trollius.readthedocs.org/index.html) integration
* [PySMI](http://snmplabs.com/pysmi/) integration for dynamic MIB compilation
2017-05-27 09:08:39 +02:00
* Built-in instrumentation exposing protocol engine operations
2016-03-07 22:28:06 +01:00
* Python eggs and py2exe friendly
* 100% Python, works with Python 2.4 though 3.7
2017-02-04 19:59:02 +01:00
* MT-safe (if SnmpEngine is thread-local)
2016-03-07 22:28:06 +01:00
Features, specific to SNMPv3 model include:
* USM authentication (MD5/SHA-1/SHA-2) and privacy (DES/AES) protocols (RFC3414, RFC7860)
2016-03-07 22:28:06 +01:00
* View-based access control to use with any SNMP model (RFC3415)
* Built-in SNMP proxy PDU converter for building multi-lingual
SNMP entities (RFC2576)
* Remote SNMP engine configuration
* Optional SNMP engine discovery
2016-03-07 22:40:40 +01:00
* Shipped with standard SNMP applications (RC3413)
2016-03-07 22:28:06 +01:00
2016-03-12 12:50:30 +01:00
2017-02-04 19:39:59 +01:00
Download & Install
------------------
2016-03-12 12:50:30 +01:00
The PySNMP software is freely available for download from [PyPI](https://pypi.org/project/pysnmp/)
2017-02-04 19:39:59 +01:00
and [GitHub](https://github.com/etingof/pysnmp.git).
2016-03-07 22:28:06 +01:00
2016-03-07 22:40:40 +01:00
Just run:
2016-03-12 10:47:48 +01:00
```bash
$ pip install pysnmp
```
2016-03-07 22:40:40 +01:00
to download and install PySNMP along with its dependencies:
* [PyASN1](http://snmplabs.com/pyasn1/)
* [PySMI](http://snmplabs.com/pysmi/) (required for MIB services only)
2018-02-19 00:41:28 +01:00
* Optional [pysnmpcrypto](https://github.com/etingof/pysnmpcrypto) package
whenever strong SNMPv3 encryption is desired
2016-03-07 22:40:40 +01:00
2018-02-16 13:40:46 +01:00
Besides the library, command-line [SNMP utilities](https://github.com/etingof/snmpclitools)
2016-03-07 22:40:40 +01:00
written in pure-Python could be installed via:
2016-03-12 10:47:48 +01:00
```bash
2018-02-16 13:40:46 +01:00
$ pip install snmpclitools
2016-03-12 10:47:48 +01:00
```
2016-03-12 10:42:48 +01:00
2016-03-07 22:48:27 +01:00
and used in the very similar manner as conventional Net-SNMP tools:
2016-03-12 10:47:48 +01:00
```bash
$ snmpget.py -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 demo.snmplabs.com sysDescr.0
2017-02-04 19:59:02 +01:00
SNMPv2-MIB::sysDescr.0 = STRING: Linux zeus 4.8.6.5-smp #2 SMP Sun Nov 13 14:58:11 CDT 2016 i686
2016-03-12 10:47:48 +01:00
```
2016-03-12 10:42:48 +01:00
2016-03-07 22:28:06 +01:00
Examples
--------
2017-02-04 19:59:02 +01:00
PySNMP is designed in a layered fashion. Top-level and easiest to use API is known as
*hlapi*. Here's a quick example on how to SNMP GET:
2016-03-07 22:28:06 +01:00
2016-03-12 10:47:48 +01:00
```python
from pysnmp.hlapi import *
2016-03-12 10:56:45 +01:00
iterator = getCmd(SnmpEngine(),
CommunityData('public'),
UdpTransportTarget(('demo.snmplabs.com', 161)),
ContextData(),
ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)))
2016-03-12 10:47:48 +01:00
errorIndication, errorStatus, errorIndex, varBinds = next(iterator)
if errorIndication: # SNMP engine errors
2016-03-12 10:56:45 +01:00
print(errorIndication)
2016-03-12 10:47:48 +01:00
else:
if errorStatus: # SNMP agent errors
2016-04-12 08:29:22 +02:00
print('%s at %s' % (errorStatus.prettyPrint(), varBinds[int(errorIndex)-1] if errorIndex else '?'))
2016-03-07 22:28:06 +01:00
else:
2016-03-12 10:47:48 +01:00
for varBind in varBinds: # SNMP response contents
2016-03-12 10:56:45 +01:00
print(' = '.join([x.prettyPrint() for x in varBind]))
2016-03-12 10:47:48 +01:00
```
2016-03-07 22:28:06 +01:00
2017-03-23 21:24:17 +01:00
This is how to send SNMP TRAP:
2016-04-12 08:30:52 +02:00
```python
from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(
SnmpEngine(OctetString(hexValue='8000000001020304')),
UsmUserData('usr-sha-aes128', 'authkey1', 'privkey1',
authProtocol=usmHMACSHAAuthProtocol,
privProtocol=usmAesCfb128Protocol),
UdpTransportTarget(('demo.snmplabs.com', 162)),
ContextData(),
'trap',
NotificationType(ObjectIdentity('SNMPv2-MIB', 'authenticationFailure'))
)
)
if errorIndication:
print(errorIndication)
```
2016-03-12 12:50:30 +01:00
We maintain publicly available SNMP Agent and TRAP sink at
[demo.snmplabs.com](http://snmplabs.com/snmpsim/public-snmp-agent-simulator.html). You are
2017-02-04 19:59:02 +01:00
welcome to use it while experimenting with whatever SNMP software you deal with.
2016-03-12 10:42:48 +01:00
2016-03-12 10:47:48 +01:00
```bash
$ python3 examples/hlapi/asyncore/sync/manager/cmdgen/usm-sha-aes128.py
SNMPv2-MIB::sysDescr.0 = SunOS zeus.snmplabs.com 4.1.3_U1 1 sun4m
$
$ python3 examples//hlapi/asyncore/sync/agent/ntforg/v3-inform.py
SNMPv2-MIB::sysUpTime.0 = 0
SNMPv2-MIB::snmpTrapOID.0 = SNMPv2-MIB::warmStart
SNMPv2-MIB::sysName.0 = system name
```
2016-03-12 10:42:48 +01:00
2017-02-04 19:59:02 +01:00
Other than that, PySNMP is capable to automatically fetch and use required MIBs from HTTP, FTP sites
2016-03-12 10:42:48 +01:00
or local directories. You could configure any MIB source available to you (including
[this one](http://mibs.snmplabs.com/asn1/)) for that purpose.
2016-03-07 22:48:27 +01:00
For more example scripts please refer to [examples section](http://snmplabs.com/pysnmp/examples/contents.html#high-level-snmp)
2016-03-07 22:28:06 +01:00
at pysnmp web site.
Documentation
-------------
Library documentation and examples can be found at the [pysnmp project site](http://snmplabs.com/pysnmp/).
2016-03-07 22:28:06 +01:00
2017-05-27 09:08:39 +02:00
If something does not work as expected, please
2017-02-04 19:39:59 +01:00
[open an issue](https://github.com/etingof/pysnmp/issues) at GitHub or
post your question [on Stack Overflow](http://stackoverflow.com/questions/ask)
or try browsing pysnmp
[mailing list archives](https://sourceforge.net/p/pysnmp/mailman/pysnmp-users/).
2016-03-07 22:28:06 +01:00
2017-05-27 09:08:39 +02:00
Bug reports and PRs are appreciated! ;-)
2016-03-07 22:28:06 +01:00
2018-01-03 13:33:05 +01:00
Copyright (c) 2005-2018, [Ilya Etingof](mailto:etingof@gmail.com). All rights reserved.