Fix ping skips remaining hosts after dns lookup error (#6743)

This commit is contained in:
Daniel Nelson 2019-12-03 11:27:33 -08:00 committed by GitHub
parent cf78f4e11e
commit 63b047c91a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 17 deletions

View File

@ -122,27 +122,25 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
p.listenAddr = getAddr(p.Interface) p.listenAddr = getAddr(p.Interface)
} }
for _, ip := range p.Urls { for _, host := range p.Urls {
_, err := net.LookupHost(ip) _, err := net.LookupHost(host)
if err != nil { if err != nil {
acc.AddFields("ping", map[string]interface{}{"result_code": 1}, map[string]string{"ip": ip}) acc.AddFields("ping", map[string]interface{}{"result_code": 1}, map[string]string{"url": host})
acc.AddError(err) acc.AddError(err)
return nil continue
} }
if p.Method == "native" { p.wg.Add(1)
p.wg.Add(1) go func(host string) {
go func(ip string) { defer p.wg.Done()
defer p.wg.Done()
p.pingToURLNative(ip, acc) switch p.Method {
}(ip) case "native":
} else { p.pingToURLNative(host, acc)
p.wg.Add(1) default:
go func(ip string) { p.pingToURL(host, acc)
defer p.wg.Done() }
p.pingToURL(ip, acc) }(host)
}(ip)
}
} }
p.wg.Wait() p.wg.Wait()