From d266dad1f41686384c4f206aab0af7d6ed7fd851 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Mon, 1 Feb 2016 16:36:08 -0700 Subject: [PATCH] Don't compile ping plugin on windows. closes #496 --- plugins/inputs/ping/ping.go | 11 ++++++++++- plugins/inputs/ping/ping_test.go | 2 ++ plugins/inputs/ping/ping_windows.go | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 plugins/inputs/ping/ping_windows.go 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