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
11 changes: 7 additions & 4 deletions internal/snmp/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,14 @@ func (gs *GosnmpWrapper) SetAgent(agent string) error {
return err
}

// Only allow udp{4,6} and tcp{4,6}.
// Allowing ip{4,6} does not make sense as specifying a port
// requires the specification of a protocol.
// gosnmp does not handle these errors well, which is why
// they can result in cryptic errors by net.Dial.
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 = ["udp4://v4only-snmp-agent"]
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 = ["udp4://v4only-snmp-agent"]
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