diff --git a/plugins/inputs/ping/ping.go b/plugins/inputs/ping/ping.go index 9c8c9bba8..b415c6d4d 100644 --- a/plugins/inputs/ping/ping.go +++ b/plugins/inputs/ping/ping.go @@ -1,3 +1,5 @@ +// +build !windows + package ping import ( @@ -41,6 +43,9 @@ func (_ *Ping) Description() string { } var sampleConfig = ` + # NOTE: this plugin forks the ping command. You may need to set capabilities + # via setcap cap_net_raw+p /bin/ping + # urls to ping urls = ["www.google.com"] # required # number of pings to send (ping -c ) @@ -111,7 +116,11 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { } func hostPinger(args ...string) (string, error) { - c := exec.Command("ping", args...) + bin, err := exec.LookPath("ping") + if err != nil { + return "", err + } + c := exec.Command(bin, args...) out, err := c.CombinedOutput() return string(out), err } diff --git a/plugins/inputs/ping/ping_test.go b/plugins/inputs/ping/ping_test.go index be603a49c..64da15b51 100644 --- a/plugins/inputs/ping/ping_test.go +++ b/plugins/inputs/ping/ping_test.go @@ -1,3 +1,5 @@ +// +build !windows + package ping import ( diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go new file mode 100644 index 000000000..b1d3ef06f --- /dev/null +++ b/plugins/inputs/ping/ping_windows.go @@ -0,0 +1,3 @@ +// +build windows + +package ping