Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add netsnmp-cffi as alternative SNMP trap receiver back-end #395

Draft
wants to merge 6 commits into
base: feature/use-netsnmpy-cffi
Choose a base branch
from

Conversation

lunkwill42
Copy link
Member

@lunkwill42 lunkwill42 commented Feb 14, 2025

Scope and purpose

Fixes the trap part of #383. Dependent on #389.

#389 works on its own, without touching the trap implementation. This builds on that to add just the trap implementation, using many of the same refactoring techniques as #389.

Contributor Checklist

Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to Zino can be found in the
README.

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with black, ruff and isort, easiest by using pre-commit
  • The first line of the commit message continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done

In preparation for making an alternative trap back-end based on
netsnmp-cffi, this moves the existing module to a submodule that
can be selectively imported, just as we did with `zino.snmp`.
This extracts from `zino.trapd.pysnmp_backend` all auxiliary classes and
type definitions that are not specific to the PySNMP back-end and moves
them to `zino.trapd.base` so they can be re-used by other back-ends.
This changes the `localhost_receiver` fixture to use 1163 as its trap
port, and then updates tests that sends external traps to the fixture so
that they will use the port assigned to the fixture.

This will better enable the test suite to change trap ports dynamically,
which might become necessary when running tests for multiple back-ends
in the same test session.
A PySNMP-based and a netsnmp-cffi-based `TrapReceiver` implementation
will share a lot of common functionality that is unrelated to the
specifics of the underlying SNMP libraries.  This factors those things
out in to a base class that can be common to the implementations, to
avoid redundancies.
@lunkwill42 lunkwill42 self-assigned this Feb 14, 2025
Copy link

github-actions bot commented Feb 14, 2025

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON black 68 0 1.32s
✅ PYTHON isort 68 0 0.52s
✅ PYTHON ruff 68 0 0.02s

See detailed report in MegaLinter reports
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

Copy link

github-actions bot commented Feb 14, 2025

Test results

    3 files      3 suites   1m 13s ⏱️
  631 tests   631 ✅ 0 💤 0 ❌
1 869 runs  1 867 ✅ 2 💤 0 ❌

Results for commit a97452c.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 78.12500% with 35 lines in your changes missing coverage. Please review.

Project coverage is 98.11%. Comparing base (6e91f30) to head (a97452c).

Files with missing lines Patch % Lines
src/zino/trapd/netsnmpy_backend.py 38.60% 35 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                      @@
##           feature/use-netsnmpy-cffi     #395      +/-   ##
=============================================================
- Coverage                      98.51%   98.11%   -0.40%     
=============================================================
  Files                             80       83       +3     
  Lines                           9893     9966      +73     
=============================================================
+ Hits                            9746     9778      +32     
- Misses                           147      188      +41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants