Expose v4/v6-only connection-schemes through GosnmpWrapper (#8804)
This commit is contained in:
parent
6804cfcfef
commit
198bcc8f36
|
|
@ -164,11 +164,14 @@ func (gs *GosnmpWrapper) SetAgent(agent string) error {
|
||||||
return err
|
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 {
|
switch u.Scheme {
|
||||||
case "tcp":
|
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6":
|
||||||
gs.Transport = "tcp"
|
gs.Transport = u.Scheme
|
||||||
case "", "udp":
|
|
||||||
gs.Transport = "udp"
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported scheme: %v", u.Scheme)
|
return fmt.Errorf("unsupported scheme: %v", u.Scheme)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,13 @@ information.
|
||||||
```toml
|
```toml
|
||||||
[[inputs.snmp]]
|
[[inputs.snmp]]
|
||||||
## Agent addresses to retrieve values from.
|
## 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"]
|
## example: agents = ["udp://127.0.0.1:161"]
|
||||||
## agents = ["tcp://127.0.0.1:161"]
|
## agents = ["tcp://127.0.0.1:161"]
|
||||||
|
## agents = ["udp4://v4only-snmp-agent"]
|
||||||
agents = ["udp://127.0.0.1:161"]
|
agents = ["udp://127.0.0.1:161"]
|
||||||
|
|
||||||
## Timeout for each request.
|
## Timeout for each request.
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,13 @@ import (
|
||||||
const description = `Retrieves SNMP values from remote agents`
|
const description = `Retrieves SNMP values from remote agents`
|
||||||
const sampleConfig = `
|
const sampleConfig = `
|
||||||
## Agent addresses to retrieve values from.
|
## 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"]
|
## example: agents = ["udp://127.0.0.1:161"]
|
||||||
## agents = ["tcp://127.0.0.1:161"]
|
## agents = ["tcp://127.0.0.1:161"]
|
||||||
|
## agents = ["udp4://v4only-snmp-agent"]
|
||||||
agents = ["udp://127.0.0.1:161"]
|
agents = ["udp://127.0.0.1:161"]
|
||||||
|
|
||||||
## Timeout for each request.
|
## Timeout for each request.
|
||||||
|
|
@ -560,7 +565,8 @@ func (s *Snmp) getConnection(idx int) (snmpConnection, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
gs.SetAgent(agent)
|
|
||||||
|
err = gs.SetAgent(agent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue