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)
}
for _, ip := range p.Urls {
_, err := net.LookupHost(ip)
for _, host := range p.Urls {
_, err := net.LookupHost(host)
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)
return nil
continue
}
if p.Method == "native" {
p.wg.Add(1)
go func(ip string) {
defer p.wg.Done()
p.pingToURLNative(ip, acc)
}(ip)
} else {
p.wg.Add(1)
go func(ip string) {
defer p.wg.Done()
p.pingToURL(ip, acc)
}(ip)
}
p.wg.Add(1)
go func(host string) {
defer p.wg.Done()
switch p.Method {
case "native":
p.pingToURLNative(host, acc)
default:
p.pingToURL(host, acc)
}
}(host)
}
p.wg.Wait()