From 736322dfc98da1e85461a89e4e53629977664fa7 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Fri, 16 Jun 2017 13:39:55 -0700 Subject: [PATCH] Set default ping count in Windows fixes #2934 --- plugins/inputs/ping/ping_windows.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/plugins/inputs/ping/ping_windows.go b/plugins/inputs/ping/ping_windows.go index fb7cde489..7a9c6b3fa 100644 --- a/plugins/inputs/ping/ping_windows.go +++ b/plugins/inputs/ping/ping_windows.go @@ -3,15 +3,16 @@ package ping import ( "errors" - "github.com/influxdata/telegraf" - "github.com/influxdata/telegraf/internal" - "github.com/influxdata/telegraf/plugins/inputs" "os/exec" "regexp" "strconv" "strings" "sync" "time" + + "github.com/influxdata/telegraf" + "github.com/influxdata/telegraf/internal" + "github.com/influxdata/telegraf/plugins/inputs" ) // HostPinger is a function that runs the "ping" function using a list of @@ -38,14 +39,14 @@ func (s *Ping) Description() string { } const sampleConfig = ` - ## urls to ping - urls = ["www.google.com"] # required + ## List of urls to ping + urls = ["www.google.com"] ## number of pings to send per collection (ping -n ) - count = 4 # required + # count = 1 ## Ping timeout, in seconds. 0.0 means default timeout (ping -w ) - #timeout = 0.0 + # timeout = 0.0 ` func (s *Ping) SampleConfig() string { @@ -145,6 +146,9 @@ func (p *Ping) args(url string) []string { } func (p *Ping) Gather(acc telegraf.Accumulator) error { + if p.Count < 1 { + p.Count = 1 + } var wg sync.WaitGroup errorChannel := make(chan error, len(p.Urls)*2) var pendingError error = nil @@ -218,6 +222,9 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error { func init() { inputs.Add("ping", func() telegraf.Input { - return &Ping{pingHost: hostPinger} + return &Ping{ + pingHost: hostPinger, + Count: 1, + } }) }