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

Expose v4/v6-only connection-schemes through GosnmpWrapper #8804

Merged
merged 10 commits into from
Feb 10, 2021
6 changes: 2 additions & 4 deletions internal/snmp/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@ func (gs *GosnmpWrapper) SetAgent(agent string) error {
}

switch u.Scheme {
case "tcp":
gs.Transport = "tcp"
case "", "udp":
gs.Transport = "udp"
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6":
gs.Transport = u.Scheme
default:
return fmt.Errorf("unsupported scheme: %v", u.Scheme)
}
Expand Down
5 changes: 5 additions & 0 deletions plugins/inputs/snmp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ information.
```toml
[[inputs.snmp]]
## Agent addresses to retrieve values from.
## format: agents = ["<scheme://><hostname>:<port>"]
## scheme: optional, either udp, udp4, udp6, tcp, tcp4, tcp6.
## default is udp
## port: optional
## example: agents = ["udp://127.0.0.1:161"]
## agents = ["tcp://127.0.0.1:161"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I would keep the tcp example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have re-added the example.

## agents = ["udpv4://v4only-snmp-agent"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an extra "v" in the scheme in this example?

Suggested change
## agents = ["udpv4://v4only-snmp-agent"]
## agents = ["udp4://v4only-snmp-agent"]

Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, good catch!

agents = ["udp://127.0.0.1:161"]

## Timeout for each request.
Expand Down
8 changes: 7 additions & 1 deletion plugins/inputs/snmp/snmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ import (
const description = `Retrieves SNMP values from remote agents`
const sampleConfig = `
## Agent addresses to retrieve values from.
## format: agents = ["<scheme://><hostname>:<port>"]
## scheme: optional, either udp, udp4, udp6, tcp, tcp4, tcp6.
## default is udp
## port: optional
## example: agents = ["udp://127.0.0.1:161"]
## agents = ["tcp://127.0.0.1:161"]
## agents = ["udpv4://v4only-snmp-agent"]
Copy link
Contributor

Choose a reason for hiding this comment

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

extra v here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uhhh.
How many Typos can there be in a few-line-change!
Thanks for your input! :)

Copy link
Contributor

Choose a reason for hiding this comment

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

That's what reviews are for!

Hey I noticed you said you're just getting started with go. If you're looking for more opportunities to write go code, feel free to grab issues with the "enhancement" or "good first issue" label. The influx and community devs and I are happy to give you feedback on PRs.

Thanks again for this PR!

agents = ["udp://127.0.0.1:161"]

## Timeout for each request.
Expand Down Expand Up @@ -560,7 +565,8 @@ func (s *Snmp) getConnection(idx int) (snmpConnection, error) {
if err != nil {
return nil, err
}
gs.SetAgent(agent)

err = gs.SetAgent(agent)
if err != nil {
return nil, err
}
Expand Down