diff --git a/internal/snmp/wrapper.go b/internal/snmp/wrapper.go
index 065528506..c1dad9fe7 100644
--- a/internal/snmp/wrapper.go
+++ b/internal/snmp/wrapper.go
@@ -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)
}
diff --git a/plugins/inputs/snmp/README.md b/plugins/inputs/snmp/README.md
index c4aa3367f..fa96150b9 100644
--- a/plugins/inputs/snmp/README.md
+++ b/plugins/inputs/snmp/README.md
@@ -22,8 +22,13 @@ information.
```toml
[[inputs.snmp]]
## Agent addresses to retrieve values from.
+ ## format: agents = [":"]
+ ## 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.
diff --git a/plugins/inputs/snmp/snmp.go b/plugins/inputs/snmp/snmp.go
index 9aac89b8d..c1dda901b 100644
--- a/plugins/inputs/snmp/snmp.go
+++ b/plugins/inputs/snmp/snmp.go
@@ -25,8 +25,13 @@ import (
const description = `Retrieves SNMP values from remote agents`
const sampleConfig = `
## Agent addresses to retrieve values from.
+ ## format: agents = [":"]
+ ## 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
}