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