Skip to content

Commit

Permalink
Add support for setting bsd source address to the ping input (#3726)
Browse files Browse the repository at this point in the history
  • Loading branch information
phlipse authored and danielnelson committed Jan 29, 2018
1 parent a6e100f commit 90efb9c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion plugins/inputs/ping/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ urls = ["www.google.com"] # required
# ping_interval = 1.0
## per-ping timeout, in s. 0 == no timeout (ping -W <TIMEOUT>)
# timeout = 1.0
## interface to send ping from (ping -I <INTERFACE>)
## interface or source address to send ping from (ping -I <INTERFACE/SRC_ADDR>)
## on Darwin and Freebsd only source address possible: (ping -S <SRC_ADDR>)
# interface = ""
```

Expand Down
15 changes: 12 additions & 3 deletions plugins/inputs/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Ping struct {
// Ping timeout, in seconds. 0 means no timeout (ping -W <TIMEOUT>)
Timeout float64

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

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

Expand Down Expand Up @@ -179,7 +180,15 @@ func (p *Ping) args(url string) []string {
}
}
if p.Interface != "" {
args = append(args, "-I", p.Interface)
switch runtime.GOOS {
case "linux":
args = append(args, "-I", p.Interface)
case "freebsd", "darwin":
args = append(args, "-S", p.Interface)
default:
// Not sure the best option here, just assume GNU ping?
args = append(args, "-I", p.Interface)
}
}
args = append(args, url)
return args
Expand Down

0 comments on commit 90efb9c

Please sign in to comment.