Skip to content

Conversation

@kongfei605
Copy link
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings December 23, 2025 08:29
Copy link
Contributor

Copilot AI left a 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 BulkWalkAll to WalkAll for error recovery in SNMPv2/v3

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings December 23, 2025 08:39
Copy link
Contributor

Copilot AI left a 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.

Copy link
Contributor

Copilot AI left a 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.

var pdus []gosnmp.SnmpPDU
var err error

// SNMPv1 do not support GETBULK,use WalkAll (GETNEXT)
Copy link

Copilot AI Dec 23, 2025

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

Suggested change
// SNMPv1 do not support GETBULKuse WalkAll (GETNEXT)
// SNMPv1 do not support GETBULK, use WalkAll (GETNEXT)

Copilot uses AI. Check for mistakes.
Comment on lines 228 to 236
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)
}
}
Copy link

Copilot AI Dec 23, 2025

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.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings December 23, 2025 09:03
Copy link
Contributor

Copilot AI left a 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.

Comment on lines 224 to 237
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)
}
}
}
Copy link

Copilot AI Dec 23, 2025

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.

Copilot uses AI. Check for mistakes.
err = nil
} else {
err = fmt.Errorf("bulk walk failed: %v, fallback walk failed: %w", err, errRetry)
log.Printf("W!: %v", err)
Copy link

Copilot AI Dec 23, 2025

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.

Suggested change
log.Printf("W!: %v", err)

Copilot uses AI. Check for mistakes.
@kongfei605 kongfei605 merged commit 5137433 into flashcatcloud:main Dec 23, 2025
3 checks passed
@kongfei605 kongfei605 deleted the snmp_zbx_v1 branch December 23, 2025 09:23
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