Skip to content

IP::fromHexString handle ascii#15504

Merged
murrant merged 2 commits intolibrenms:masterfrom
murrant:ip_from_hex_ascii
Oct 26, 2023
Merged

IP::fromHexString handle ascii#15504
murrant merged 2 commits intolibrenms:masterfrom
murrant:ip_from_hex_ascii

Conversation

@murrant
Copy link
Copy Markdown
Member

@murrant murrant commented Oct 25, 2023

Some bad MIBs convert the hex to ascii on display.
Attempt to decode that if the situation is detected.

fixes #15501

Please give a short description what your pull request is for

DO NOT DELETE THE UNDERLYING TEXT

Please note

Please read this information carefully. You can run ./lnms dev:check to check your code before submitting.

  • Have you followed our code guidelines?
  • If my Pull Request does some changes/fixes/enhancements in the WebUI, I have inserted a screenshot of it.
  • If my Pull Request makes discovery/polling/yaml changes, I have added/updated test data.

Testers

If you would like to test this pull request then please run: ./scripts/github-apply <pr_id>, i.e ./scripts/github-apply 5926
After you are done testing, you can remove the changes with ./scripts/github-remove. If there are schema changes, you can ask on discord how to revert.

Some bad MIBs convert the hex to ascii on display.
Attempt to decode that if the situation is detected.

fixes librenms#15501

// check if hex was incorrectly converted to ascii
$len = strlen($hex);
if (($len == 4 || $len == 16) && preg_match('/[^0-9a-fA-F]/', $hex)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have some tests for this? It’s really hard to understand why it’s needed else, or what the length check is

Copy link
Copy Markdown
Member Author

@murrant murrant Oct 25, 2023

Choose a reason for hiding this comment

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

Juniper doesn't know how to set their MIB display hint correctly.

From the linked issue: https://supportportal.juniper.net/s/article/Junos-Values-for-show-snmp-mib-walk-jnxBgpM2PeerLocalAddr-don-t-appear-correct?language=en_US

Basically any hex in the ascii range gets converted to ascii. Because IPs are fixed length, IPv4 will be 4 characters and IPv6 will be 16 characters. The length check is to avoid running the preg_match every time and improve the accuracy of the check.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Tests would be a good idea ;)

@murrant murrant merged commit 7e0b41a into librenms:master Oct 26, 2023
@murrant murrant deleted the ip_from_hex_ascii branch October 26, 2023 15:03
gdepeyrot pushed a commit to gdepeyrot/librenms that referenced this pull request Nov 29, 2023
* IP::fromHexString handle ascii
Some bad MIBs convert the hex to ascii on display.
Attempt to decode that if the situation is detected.

fixes librenms#15501

* add ascii tests
gunkaaa pushed a commit to gunkaaa/librenms that referenced this pull request Jan 8, 2024
* IP::fromHexString handle ascii
Some bad MIBs convert the hex to ascii on display.
Attempt to decode that if the situation is detected.

fixes librenms#15501

* add ascii tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SNMP query of Juniper BGP peers has variable response types causing polling failure.

2 participants