-
Notifications
You must be signed in to change notification settings - Fork 329
feat(snmp_zabbix): use WalkAll for SNMPv1 discovery #1377
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds support for SNMPv1 devices in the discovery process by using WalkAll (GETNEXT) instead of BulkWalkAll (GETBULK), which is not supported in SNMPv1. The change also adds a fallback mechanism for non-v1 versions when BulkWalkAll fails.
Key changes:
- Added SNMPv1 version detection to use appropriate SNMP walk method
- Implemented fallback from
BulkWalkAlltoWalkAllfor error recovery in SNMPv2/v3
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2031e7b to
c22ec9d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
inputs/snmp_zabbix/discovery.go
Outdated
| var pdus []gosnmp.SnmpPDU | ||
| var err error | ||
|
|
||
| // SNMPv1 do not support GETBULK,use WalkAll (GETNEXT) |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixed punctuation: The comment uses a Chinese comma (,) instead of a standard comma (,). Should be: 'GETBULK, use WalkAll'.
| // SNMPv1 do not support GETBULK,use WalkAll (GETNEXT) | |
| // SNMPv1 do not support GETBULK, use WalkAll (GETNEXT) |
inputs/snmp_zabbix/discovery.go
Outdated
| if err != nil { | ||
| pdusRetry, errRetry := client.WalkAll(oid) | ||
| if errRetry == nil { | ||
| pdus = pdusRetry | ||
| err = nil | ||
| } else { | ||
| err = fmt.Errorf("bulk walk failed: %v, fallback walk failed: %w", err, errRetry) | ||
| } | ||
| } |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fallback logic is duplicated in three places (lines 228-236, 280-289, 392-400). Consider extracting this into a helper function to reduce code duplication and improve maintainability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
inputs/snmp_zabbix/discovery.go
Outdated
| if client.Version == gosnmp.Version1 { | ||
| pdus, err = client.WalkAll(oid) | ||
| } else { | ||
| pdus, err = client.BulkWalkAll(oid) | ||
| if err != nil { | ||
| pdusRetry, errRetry := client.WalkAll(oid) | ||
| if errRetry == nil { | ||
| pdus = pdusRetry | ||
| err = nil | ||
| } else { | ||
| err = fmt.Errorf("bulk walk failed: %v, fallback walk failed: %w", err, errRetry) | ||
| } | ||
| } | ||
| } |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same version check and fallback logic is duplicated across three functions (performMultiOidWalkDiscovery, performZabbixDependentDiscovery, and performStandardDiscovery). Consider extracting this into a helper function to improve maintainability and reduce code duplication. For example, a function like performWalkWithFallback(client *gosnmp.GoSNMP, oid string) ([]gosnmp.SnmpPDU, error) would centralize this logic.
inputs/snmp_zabbix/discovery.go
Outdated
| err = nil | ||
| } else { | ||
| err = fmt.Errorf("bulk walk failed: %v, fallback walk failed: %w", err, errRetry) | ||
| log.Printf("W!: %v", err) |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error is logged here but not in the other two places where the same fallback logic is used (lines 234 and 398). This inconsistency makes debugging more difficult. Either remove this logging statement for consistency, or add it to the other locations as well.
| log.Printf("W!: %v", err) |
5dcfe67 to
22f8477
Compare
No description provided.