Fix ping skips remaining hosts after dns lookup error (#6743)
This commit is contained in:
parent
cf78f4e11e
commit
63b047c91a
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue