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 5 commits into
base: feature/use-netsnmpy-cffi
Choose a base branch
from

Conversation

lunkwill42
Copy link
Member

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 #3389.

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

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON black 68 0 1.32s
✅ PYTHON isort 68 0 0.53s
✅ 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

Test results

2 tests   0 ✅  2s ⏱️
1 suites  0 💤
1 files    0 ❌  2 🔥

For more details on these errors, see this check.

Results for commit 5665879.

Copy link

codecov bot commented Feb 14, 2025

Codecov Report

Attention: Patch coverage is 44.37500% with 89 lines in your changes missing coverage. Please review.

Project coverage is 34.32%. Comparing base (6e91f30) to head (5665879).

Files with missing lines Patch % Lines
src/zino/trapd/base.py 48.35% 47 Missing ⚠️
src/zino/trapd/netsnmpy_backend.py 29.82% 40 Missing ⚠️
src/zino/trapd/pysnmp_backend.py 66.67% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (6e91f30) and HEAD (5665879). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (6e91f30) HEAD (5665879)
2 1
Additional details and impacted files
@@                      Coverage Diff                       @@
##           feature/use-netsnmpy-cffi     #395       +/-   ##
==============================================================
- Coverage                      98.51%   34.32%   -64.20%     
==============================================================
  Files                             80       52       -28     
  Lines                           9893     3733     -6160     
==============================================================
- Hits                            9746     1281     -8465     
- Misses                           147     2452     +2305     

☔ 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.

1 participant