From 90efb9c844314b226fdcf81cbf944bbe1a0af008 Mon Sep 17 00:00:00 2001 From: Philipp Weber <6884041+phlipse@users.noreply.github.com> Date: Mon, 29 Jan 2018 23:01:00 +0100 Subject: [PATCH] Add support for setting bsd source address to the ping input (#3726) --- plugins/inputs/ping/README.md | 3 ++- plugins/inputs/ping/ping.go | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/plugins/inputs/ping/README.md b/plugins/inputs/ping/README.md index 914477c54..5e4c637f5 100644 --- a/plugins/inputs/ping/README.md +++ b/plugins/inputs/ping/README.md @@ -17,7 +17,8 @@ urls = ["www.google.com"] # required # ping_interval = 1.0 ## per-ping timeout, in s. 0 == no timeout (ping -W ) # timeout = 1.0 -## interface to send ping from (ping -I ) +## interface or source address to send ping from (ping -I ) +## on Darwin and Freebsd only source address possible: (ping -S ) # interface = "" ``` diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index cae575bfd..4ed36bd05 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -34,7 +34,7 @@ type Ping struct { // Ping timeout, in seconds. 0 means no timeout (ping -W ) Timeout float64 - // Interface to send ping from (ping -I ) + // Interface or source address to send ping from (ping -I/-S ) Interface string // URLs to ping @@ -60,7 +60,8 @@ const sampleConfig = ` # ping_interval = 1.0 ## per-ping timeout, in s. 0 == no timeout (ping -W ) # timeout = 1.0 - ## interface to send ping from (ping -I ) + ## interface or source address to send ping from (ping -I ) + ## on Darwin and Freebsd only source address possible: (ping -S ) # interface = "" ` @@ -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