diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | python-snmp-passpersist.spec | 501 | ||||
-rw-r--r-- | sources | 1 |
3 files changed, 503 insertions, 0 deletions
@@ -0,0 +1 @@ +/snmp_passpersist-2.1.0.tar.gz diff --git a/python-snmp-passpersist.spec b/python-snmp-passpersist.spec new file mode 100644 index 0000000..e3ac958 --- /dev/null +++ b/python-snmp-passpersist.spec @@ -0,0 +1,501 @@ +%global _empty_manifest_terminate_build 0 +Name: python-snmp-passpersist +Version: 2.1.0 +Release: 1 +Summary: SNMP passpersist backend for Net-SNMP +License: GPLv3 +URL: http://github.com/nagius/snmp_passpersist +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/12/5e/2f3752076571359ec83addf12ecd70ff044fb10d1429b42aa418553de92b/snmp_passpersist-2.1.0.tar.gz +BuildArch: noarch + + +%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 : + +```python +#!/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 + +```python +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. + +```python +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<ENTER>.1.3.6.1.3.53.8.0.1<ENTER>, except PING and DUMP. + +## Credits + +Many thanks to all contributors. + + + + + + +%package -n python3-snmp-passpersist +Summary: SNMP passpersist backend for Net-SNMP +Provides: python-snmp-passpersist +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-snmp-passpersist +# 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 : + +```python +#!/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 + +```python +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. + +```python +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<ENTER>.1.3.6.1.3.53.8.0.1<ENTER>, except PING and DUMP. + +## Credits + +Many thanks to all contributors. + + + + + + +%package help +Summary: Development documents and examples for snmp-passpersist +Provides: python3-snmp-passpersist-doc +%description help +# 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 : + +```python +#!/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 + +```python +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. + +```python +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<ENTER>.1.3.6.1.3.53.8.0.1<ENTER>, except PING and DUMP. + +## Credits + +Many thanks to all contributors. + + + + + + +%prep +%autosetup -n snmp-passpersist-2.1.0 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-snmp-passpersist -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Wed May 31 2023 Python_Bot <Python_Bot@openeuler.org> - 2.1.0-1 +- Package Spec generated @@ -0,0 +1 @@ +1cade04906ebda426b488f6d1b08d84d snmp_passpersist-2.1.0.tar.gz |