-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Cleanup snmp plugins #9055
Cleanup snmp plugins #9055
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.
🤝 ✅ CLA has been signed. Thank you!
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.
Looks like new artifacts were built from this PR. Get them here!
Artifact URLs
Looks okay, I'm not sure that the regular expression is any clearer, but it's fine. Looks like we don't have test coverage of this conditional branch? Are you able to add a test for this? |
@ssoroka Tests that use this part of the code:
|
Great, will try to do that. It will also be good as preparation to switch to using gosmi. |
Looks like new artifacts were built from this PR. Get them here!Artifact URLs |
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.
Not sure I'm of help here. Code change looks sensible, but I've not been much into SNMP. :-)
Hi @Hipska is this meant to be a draft still? Maybe you're keeping it as a draft until you can move things to internal/snmp? |
Yes indeed, but don’t have much time for it now. |
As I understood @MyaLongmire will work on implementing gosmi, and so also move |
objs := strings.TrimPrefix(line, "::= { ") | ||
objs = strings.TrimSuffix(objs, " }") | ||
re := regexp.MustCompile(`(?:\w+\()?(\d+)\)?`) | ||
|
||
for _, obj := range strings.Split(objs, " ") { | ||
if len(obj) == 0 { | ||
continue | ||
} | ||
if i := strings.Index(obj, "("); i != -1 { | ||
obj = obj[i+1:] | ||
oidNum += "." + obj[:strings.Index(obj, ")")] | ||
} else { | ||
oidNum += "." + obj | ||
} | ||
for _, match := range re.FindAllStringSubmatch(line, -1) { | ||
oidNum += "." + match[1] |
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 makes the code shorter but I'm not sure it's more maintainable to use regexp instead of manually splitting the string. Do we have unit tests that cover this? I'm not sure it does the exact same thing as before.
Closing since it will mostly be irrelevant when #9518 is merged |
Okay, I will reopen since that PR is now creating a new snmp plugin, so my improvements here are again relevant. @reimda can you finally merge please? |
@@ -9,6 +9,7 @@ import ( | |||
"math" | |||
"net" | |||
"os/exec" | |||
"regexp" |
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.
@Hipska maybe in this cleanup you can include fixing linters findings?
plugins/inputs/snmp/snmp.go:1:9 revive import-shadowing: The name 'snmp' shadows an import name
plugins/inputs/snmp/snmp.go:8:2 revive imports-blacklist: should not use the following blacklisted import: "log"
plugins/inputs/snmp/snmp.go:376:27 revive flag-parameter: parameter 'walk' seems to be a control flag, avoid control coupling
plugins/inputs/snmp/snmp.go:406:21 revive flag-parameter: parameter 'walk' seems to be a control flag, avoid control coupling
plugins/inputs/snmp/snmp.go:594:15 unconvert unnecessary conversion
plugins/inputs/snmp/snmp.go:692:10 revive early-return: if c {...} else {... return } can be simplified to if !c { ... return } ...
plugins/inputs/snmp/snmp.go:748:1 revive function-result-limit: maximum number of return results per function exceeded; max 3 but got 5
plugins/inputs/snmp/snmp.go:765:1 revive function-result-limit: maximum number of return results per function exceeded; max 3 but got 5
plugins/inputs/snmp/snmp.go:836:1 revive function-result-limit: maximum number of return results per function exceeded; max 3 but got 5
plugins/inputs/snmp/snmp.go:862:1 revive function-result-limit: maximum number of return results per function exceeded; max 3 but got 5
plugins/inputs/snmp/snmp_mocks_test.go:47:3 revive unhandled-error: Unhandled error in call to function fmt.Fprintf
plugins/inputs/snmp/snmp_mocks_test.go:48:3 revive deep-exit: calls to os.Exit only in main() or init() functions
plugins/inputs/snmp/snmp_mocks_test.go:50:2 revive unhandled-error: Unhandled error in call to function fmt.Printf
plugins/inputs/snmp/snmp_mocks_test.go:51:2 revive unhandled-error: Unhandled error in call to function fmt.Fprintf
plugins/inputs/snmp/snmp_mocks_test.go:53:3 revive deep-exit: calls to os.Exit only in main() or init() functions
plugins/inputs/snmp/snmp_mocks_test.go:55:2 revive deep-exit: calls to os.Exit only in main() or init() functions
plugins/inputs/snmp/snmp_test.go:2:9 revive import-shadowing: The name 'snmp' shadows an import name
plugins/inputs/snmp/snmp_test.go:15:2 revive duplicated-imports: Package "github.com/influxdata/telegraf/internal/snmp" already imported
plugins/inputs/snmp/snmp_test.go:476:2 staticcheck SA5001: should check returned error before deferring srvr.Close()
plugins/inputs/snmp/snmp_test.go:495:16 errcheck Error return value of `srvr.WriteTo` is not checked
plugins/inputs/snmp/snmp_test.go:515:2 revive unhandled-error: Unhandled error in call to function srvr.Close
plugins/inputs/snmp/snmp_test.go:526:2 staticcheck SA5001: should check returned error before deferring srvr.Close()
plugins/inputs/snmp/snmp_test.go:545:16 errcheck Error return value of `srvr.WriteTo` is not checked
plugins/inputs/snmp/snmp_test.go:565:2 revive unhandled-error: Unhandled error in call to function srvr.Close
plugins/inputs/snmp/snmp_test.go:748:10 errcheck Error return value of `s.Gather` is not checked
plugins/inputs/snmp/snmp_test.go:795:10 errcheck Error return value of `s.Gather` is not checked
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.
Ouch, I think I'm afraid I'm not able to do that. I could give it a try if really wanted.
Closing again since #9518 got merged and did a lot of cleanup as well |
Required for all PRs:
Are there any more tests or parts of the plugin that could need cleanup?