Skip to main content

SNMP passpersist backend for Net-SNMP

Project description

SNMP-PassPersist

This module is a SNMP passpersist backend for Net-SNMP.

The snmp_passpersist.PassPersist class present a convenient way to creare a MIB subtree and expose it to snmp via its passpersist protocol. Two threads are used, one for talking with snmpd and a second that trigger the update process at a fixed interval.

The keyword 'DUMP' has been added to the protocol for testing purpose.

Installation

The easiest way is using pip :

pip install snmp_passpersist

Example

Usage example: in a file /path/to/your/script.py :

#!/usr/bin/python -u

import snmp_passpersist as snmp

def update():
        pp.add_int('0.1', 123, "This is a label for this integer")
        pp.add_str('0.2', "A string")
        pp.add_oct('0.3', '01 00 1f 0b 00 0b') # MAC address as an octet string

pp=snmp.PassPersist(".1.3.6.1.3.53.8")
pp.start(update,30) # Every 30s

With the following line in Net-SNMP's snmpd.conf :

pass_persist    .1.3.6.1.3.53.8.0     /path/to/your/script.py

A Real-world example is available here: https://github.com/nagius/cxm/blob/master/misc/snmp_xen.py

List of supported types and their helpers

Type Helper
Counter32 add_cnt_32bit()
Counter64 add_cnt_64bit()
GAUGE add_gau()
INTEGER add_int()
IPADDRESS add_ip()
OBJECTID add_oid()
OCTET add_oct()
STRING add_str()
TIMETICKS add_tt()

Special helpers

Labels

You can add a label with each entries, as an optional parameter to all add_*() helpers. This label is not used by Net-SNMP and is only useful for debugging with the DUMP keyword.

add_oid()

This helper allow you to add a simple OID string and give it the proper type. For example, calling this method with

pp.add_oid('.1.3.6.1.2.1.47','1.1.1.1.3.1','0.0')

where "0.0" represents SNMPv2-SMI::zeroDotZero.

This results in the following response when we walk this OID:

ENTITY-MIB::entPhysicalVendorType.1 = OID: SNMPv2-SMI::zeroDotZero

Set an attribute

You can register a helper to allow the recording of value from Net-SNMP.

def my_setter(oid, type, value):
        print("Received %s with value %s for oid %s." % (type, value, oid))
        return True

pp.register_setter('.1.3.6.1.3.53.8.0.4', my_setter)

Example for debugging :

$ /path/to/your/script.py
set
.1.3.6.1.3.53.8.0.4
INTEGER 987
Received INTEGER with value 987 for oid .1.3.6.1.3.53.8.0.4.
DONE
set
.1.3.6.1.3.53.8.0.1
STRING some-random-useless-string
not-writable

Another example that show the usage of the 'set' feature is available in the 'example/' directory.

Debugging example

Run the previous script in a shell and type the commands :

$ /path/to/your/script.py
PING
PONG
DUMP
{'0.1': {'type': 'INTEGER', 'value': '123'}}
get
.1.3.6.1.3.53.8
NONE
get
.1.3.6.1.3.53.8.0.1
.1.3.6.1.3.53.8.0.1
INTEGER
123
getnext
.1.3.6.1.3.53.8
.1.3.6.1.3.53.8.0.1
INTEGER
123

All commands are typed on two lines : get.1.3.6.1.3.53.8.0.1, except PING and DUMP.

Credits

Many thanks to all contributors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snmp_passpersist-2.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

snmp_passpersist-2.1.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file snmp_passpersist-2.1.0.tar.gz.

File metadata

  • Download URL: snmp_passpersist-2.1.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.24.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.15

File hashes

Hashes for snmp_passpersist-2.1.0.tar.gz
Algorithm Hash digest
SHA256 72987dfd7464a6b8210d48d9f9c1071674673f2cc2e1a6a5a6b6226bd8e1e9ea
MD5 1cade04906ebda426b488f6d1b08d84d
BLAKE2b-256 125e2f3752076571359ec83addf12ecd70ff044fb10d1429b42aa418553de92b

See more details on using hashes here.

File details

Details for the file snmp_passpersist-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: snmp_passpersist-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.24.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.15

File hashes

Hashes for snmp_passpersist-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e8aa9a01c2952ab3be8d9255f7ba276d43f253373a75d38fd435042bb3032e3
MD5 269e2f6c4c232924c17ad92e67333aa3
BLAKE2b-256 13515fe7ebb2a1f53836e69c73c9b9e0014a75ebdf6a98d23f707d649d1912c9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page