Skip to main content

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.

Release files for snmp-passpersist 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for snmp-passpersist 2.1.0
File Size Uploaded
snmp_passpersist-2.1.0.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for snmp-passpersist 2.1.0
File Interpreter ABI Platform
snmp_passpersist-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.2 kB

Release files / snmp_passpersist-2.1.0.tar.gz

Download URL snmp_passpersist-2.1.0.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
72987dfd7464a6b8210d48d9f9c1071674673f2cc2e1a6a5a6b6226bd8e1e9ea
BLAKE2b-256 checksum
How to use checksums
125e2f3752076571359ec83addf12ecd70ff044fb10d1429b42aa418553de92b
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / snmp_passpersist-2.1.0-py3-none-any.whl

Download URL snmp_passpersist-2.1.0-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e8aa9a01c2952ab3be8d9255f7ba276d43f253373a75d38fd435042bb3032e3
BLAKE2b-256 checksum
How to use checksums
13515fe7ebb2a1f53836e69c73c9b9e0014a75ebdf6a98d23f707d649d1912c9
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.0

2 release files

1.3.0

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page