Skip to content

Commit f437d41

Browse files
committed
Add SNMP trap C extension using net-snmp
Replace pysnmp with a native C extension for sending SNMP trap notifications. Uses net-snmp's libnetsnmp for session management, PDU construction, and SNMPv3 USM authentication. Exposes send_alert(), send_alert_cancellation(), and get_engine_id() to Python. Supports SNMPv2c (community), SNMPv3 authNoPriv (MD5/SHA), and SNMPv3 authPriv (DES/AES). OIDs derived from TRUENAS-MIB notification section.
1 parent d5077e7 commit f437d41

File tree

12 files changed

+954
-0
lines changed

12 files changed

+954
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea/
2+
__pycache__/
3+
*.egg-info/
4+
*.so

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# truenas_pysnmp
2+
3+
Python C extension for SNMP functionality using net-snmp's libnetsnmp.
4+
5+
Currently provides SNMP trap sending (`send_alert`, `send_alert_cancellation`, `get_engine_id`). Supports SNMPv2c and SNMPv3 (USM auth/priv). Notification OIDs (`alert`, `alertCancellation`, `alertId`, `alertLevel`, `alertMessage`) are derived from the notification section of [TRUENAS-MIB](https://github.com/truenas/middleware/blob/master/src/freenas/usr/local/share/snmp/mibs/TRUENAS-MIB.txt) and compiled as constants, so no runtime MIB parsing is required.
6+
7+
## Building
8+
9+
```bash
10+
sudo apt install libsnmp-dev python3-dev
11+
pip install -e .
12+
```

debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
truenas-pysnmp (0.1.0-1) unstable; urgency=medium
2+
3+
* Initial release.
4+
5+
-- Ameer Hamza <ahamza@truenas.com> Fri, 27 Mar 2026 17:00:00 +0000

debian/control

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Source: truenas-pysnmp
2+
Section: contrib/python
3+
Priority: optional
4+
Maintainer: TrueNAS Engineering <dev@truenas.com>
5+
Build-Depends: debhelper-compat (= 12),
6+
dh-python,
7+
pybuild-plugin-pyproject,
8+
python3-all-dev,
9+
python3-setuptools,
10+
libsnmp-dev
11+
Standards-Version: 4.4.1
12+
Homepage: https://github.com/truenas/truenas_pysnmp
13+
14+
Package: python3-truenas-pysnmp
15+
Architecture: any
16+
Depends: ${shlibs:Depends}, ${misc:Depends}, ${python3:Depends}
17+
Description: TrueNAS SNMP C extension using net-snmp
18+
This package provides a Python C extension for sending SNMP trap
19+
notifications using net-snmp's libnetsnmp. Supports SNMPv2c and SNMPv3.

debian/rules

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/make -f
2+
3+
#export DH_VERBOSE = 1
4+
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
5+
export PYBUILD_NAME=truenas-pysnmp
6+
export PYBUILD_SYSTEM=pyproject
7+
8+
%:
9+
dh $@ --with python3 --buildsystem=pybuild
10+
11+
override_dh_auto_configure:
12+
dh_auto_configure
13+
14+
override_dh_install:
15+
dh_install

pyproject.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "truenas_pysnmp"
7+
version = "0.1.0"
8+
description = "TrueNAS SNMP C extension using net-snmp"
9+
readme = "README.md"
10+
requires-python = ">=3.11"
11+
authors = [
12+
{name = "TrueNAS Engineering", email = "dev@truenas.com"},
13+
]
14+
license = {text = "LGPL-3.0-or-later"}
15+
classifiers = [
16+
"Development Status :: 3 - Alpha",
17+
"Intended Audience :: Developers",
18+
"Programming Language :: Python :: 3",
19+
"Programming Language :: C",
20+
"Operating System :: POSIX :: Linux",
21+
"Topic :: System :: Networking :: Monitoring",
22+
]

setup.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from setuptools import setup, Extension
2+
3+
truenas_pysnmp_ext = Extension(
4+
'truenas_pysnmp._native',
5+
sources=['src/cext/truenas_pysnmp.c'],
6+
include_dirs=['src/cext'],
7+
libraries=['netsnmp'],
8+
)
9+
10+
setup(
11+
ext_modules=[truenas_pysnmp_ext],
12+
packages=['truenas_pysnmp'],
13+
package_dir={
14+
'truenas_pysnmp': 'stubs',
15+
},
16+
package_data={
17+
'truenas_pysnmp': ['*.pyi', 'py.typed'],
18+
},
19+
)

0 commit comments

Comments
 (0)