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

Clean up issues with IP address parsing in several places #322

Merged
merged 4 commits into from
Aug 27, 2024

Conversation

lunkwill42
Copy link
Member

@lunkwill42 lunkwill42 commented Jul 18, 2024

Scope and purpose

Mainly this fixes the issue of parsing the values of InetAddress and IpAddress type MIB objects at the level of the zino.snmp._mib_value_to_python() function. Once fixed there, using the parse_ip utility function becomes superfluous, so these instances can be removed.

There was also some strange issue with comparing strings to IP address objects which was resolved.

There may be similar updates to had in the trap observers (some of which parse the raw object values for IP address itself).

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

Copy link

github-actions bot commented Jul 18, 2024

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON black 6 0 0.63s
✅ PYTHON isort 6 0 0.21s
✅ PYTHON ruff 6 0 0.01s

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 Jul 18, 2024

Test results

    3 files      3 suites   1m 23s ⏱️
  564 tests   564 ✅ 0 💤 0 ❌
1 644 runs  1 642 ✅ 2 💤 0 ❌

Results for commit ee31ed7.

♻️ This comment has been updated with latest results.

@lunkwill42
Copy link
Member Author

I have not tested this extensively against real-world equipment, as I ran out of time: Gotta go on vacation :)

@lunkwill42 lunkwill42 marked this pull request as ready for review July 18, 2024 14:13
Copy link

codecov bot commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.61%. Comparing base (a0ffdb9) to head (ee31ed7).
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #322      +/-   ##
==========================================
+ Coverage   98.57%   98.61%   +0.05%     
==========================================
  Files          77       77              
  Lines        9699     9671      -28     
==========================================
- Hits         9560     9537      -23     
+ Misses        139      134       -5     

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

Copy link

sonarcloud bot commented Jul 22, 2024

Copy link
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would only want this to be merged after testing against real-life equipment, otherwise it looks good. I have removed the parse_ip function from utils since it is not used now.

Copy link
Contributor

@stveit stveit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without having done any testing myself this looks fine 👍
I'll probably run some manual tests tomorrow

@lunkwill42
Copy link
Member Author

So, have any of you tested, @stveit or @johannaengland , or I should I go ahead? I see I have a potential uncommitted simplification of the BGP trap processing code that would parse an IP address as well...

@johannaengland
Copy link
Contributor

So, have any of you tested, @stveit or @johannaengland , or I should I go ahead? I see I have a potential uncommitted simplification of the BGP trap processing code that would parse an IP address as well...

I have not. But I remember @stveit saying in a standup meeting last week that he was planning on testing it

@stveit
Copy link
Contributor

stveit commented Aug 21, 2024

Zino seems to be running fine with these changes from what I can tell

PySNMP doesn't necessarily pretty-print InetAddress and IpAddress
value types as anything useful for us (This are textual conventions
of an OctetString, and PySNMP tends to just raw-dog the octet string
into something like a hexadecimal string representation of the content).

If the value type is `InetAddress` or `IpAddress` we can expect
`ipaddress.ip_address()` to properly parse the raw bytes into an
IPv4Address or IPv6Address object.
`InetAddress` and `IpAddress` MIB values are now expected to be
returned as IPv4Address or IPv6Address objects from the SNMP layer.
The BGP state monitor task would test for membership in this list
using IPv4Address or IPv6Address objects, but the list contained raw
strings, so the tests would never match.
@lunkwill42 lunkwill42 force-pushed the feature/translate-ip-values-at-lower-level branch from 3da1744 to eedf00b Compare August 27, 2024 10:01
@lunkwill42
Copy link
Member Author

I rebased this on the latest master due to conflicts. Have tested myself against real-world equipment now and found no issues.

@lunkwill42 lunkwill42 force-pushed the feature/translate-ip-values-at-lower-level branch from eedf00b to 94bba1d Compare August 27, 2024 10:05
@lunkwill42 lunkwill42 force-pushed the feature/translate-ip-values-at-lower-level branch from 94bba1d to ee31ed7 Compare August 27, 2024 10:37
Copy link

sonarcloud bot commented Aug 27, 2024

@lunkwill42 lunkwill42 merged commit 1bc253d into master Aug 27, 2024
7 of 8 checks passed
@lunkwill42 lunkwill42 deleted the feature/translate-ip-values-at-lower-level branch August 27, 2024 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants