Skip to content

Commit 1b84ac0

Browse files
phlipsedanielnelson
authored andcommitted
Add support for setting bsd source address to the ping input (#3726)
1 parent bcefe90 commit 1b84ac0

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

plugins/inputs/ping/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ urls = ["www.google.com"] # required
1717
# ping_interval = 1.0
1818
## per-ping timeout, in s. 0 == no timeout (ping -W <TIMEOUT>)
1919
# timeout = 1.0
20-
## interface to send ping from (ping -I <INTERFACE>)
20+
## interface or source address to send ping from (ping -I <INTERFACE/SRC_ADDR>)
21+
## on Darwin and Freebsd only source address possible: (ping -S <SRC_ADDR>)
2122
# interface = ""
2223
```
2324

plugins/inputs/ping/ping.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type Ping struct {
3434
// Ping timeout, in seconds. 0 means no timeout (ping -W <TIMEOUT>)
3535
Timeout float64
3636

37-
// Interface to send ping from (ping -I <INTERFACE>)
37+
// Interface or source address to send ping from (ping -I/-S <INTERFACE/SRC_ADDR>)
3838
Interface string
3939

4040
// URLs to ping
@@ -60,7 +60,8 @@ const sampleConfig = `
6060
# ping_interval = 1.0
6161
## per-ping timeout, in s. 0 == no timeout (ping -W <TIMEOUT>)
6262
# timeout = 1.0
63-
## interface to send ping from (ping -I <INTERFACE>)
63+
## interface or source address to send ping from (ping -I <INTERFACE/SRC_ADDR>)
64+
## on Darwin and Freebsd only source address possible: (ping -S <SRC_ADDR>)
6465
# interface = ""
6566
`
6667

@@ -179,7 +180,15 @@ func (p *Ping) args(url string) []string {
179180
}
180181
}
181182
if p.Interface != "" {
182-
args = append(args, "-I", p.Interface)
183+
switch runtime.GOOS {
184+
case "linux":
185+
args = append(args, "-I", p.Interface)
186+
case "freebsd", "darwin":
187+
args = append(args, "-S", p.Interface)
188+
default:
189+
// Not sure the best option here, just assume GNU ping?
190+
args = append(args, "-I", p.Interface)
191+
}
183192
}
184193
args = append(args, url)
185194
return args

0 commit comments

Comments
 (0)