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
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
## agents = ["udp4://v4only-snmp-agent"]
|
||||
agents = ["udp://127.0.0.1:161"]
|
||||
|
||||
## Timeout for each request.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue