NAS-140368 / 27.0.0-BETA.1 / Add SNMP trap C extension using net-snmp#1
Open
NAS-140368 / 27.0.0-BETA.1 / Add SNMP trap C extension using net-snmp#1
Conversation
Contributor
anodos325
reviewed
Mar 26, 2026
anodos325
reviewed
Mar 26, 2026
|
Can we add a github runner pipeline that minimally builds the debian package and runs mypy stub tests? https://github.com/truenas/truenas_pyos/tree/master/.github/workflows For example. Though in this case we probably don't need to use a qemu VM. I think a tests dir with some basic pytest tests might also be useful. |
Member
Author
|
@anodos325 - Yeah, that's a very good point. Will add. |
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.
CI pipeline builds debian package, runs mypy stubtest for stub validation, and pytest for argument validation and constants. Tests cover validation errors, engine ID, and constants sync with the C module. Network/receiver tests are not included as they require a running snmptrapd instance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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(), andget_engine_id(). OIDs derived from TRUENAS-MIB notification section.Testing
Tested with snmptrapd (net-snmp 5.9.4) as trap receiver:
v2c:
v3:
Verified against upstream:
snmptrapCLI outputsnmptrap.capproachNext steps
snmp_trap.pyand replacepysnmp