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(ip string) {
|
go func(host string) {
|
||||||
defer p.wg.Done()
|
defer p.wg.Done()
|
||||||
p.pingToURLNative(ip, acc)
|
|
||||||
}(ip)
|
switch p.Method {
|
||||||
} else {
|
case "native":
|
||||||
p.wg.Add(1)
|
p.pingToURLNative(host, acc)
|
||||||
go func(ip string) {
|
default:
|
||||||
defer p.wg.Done()
|
p.pingToURL(host, acc)
|
||||||
p.pingToURL(ip, acc)
|
|
||||||
}(ip)
|
|
||||||
}
|
}
|
||||||
|
}(host)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.wg.Wait()
|
p.wg.Wait()
|
||||||
|
|
Loading…
Reference in New Issue