Add host to ping timeout log message (#3853)
This commit is contained in:
parent
45c22e42da
commit
c377c8fb7c
|
@ -113,9 +113,9 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
|
||||||
// Combine go err + stderr output
|
// Combine go err + stderr output
|
||||||
out = strings.TrimSpace(out)
|
out = strings.TrimSpace(out)
|
||||||
if len(out) > 0 {
|
if len(out) > 0 {
|
||||||
acc.AddError(fmt.Errorf("%s, %s", out, err))
|
acc.AddError(fmt.Errorf("host %s: %s, %s", u, out, err))
|
||||||
} else {
|
} else {
|
||||||
acc.AddError(err)
|
acc.AddError(fmt.Errorf("host %s: %s", u, err))
|
||||||
}
|
}
|
||||||
acc.AddFields("ping", fields, tags)
|
acc.AddFields("ping", fields, tags)
|
||||||
return
|
return
|
||||||
|
|
|
@ -268,3 +268,26 @@ func TestFatalPingGather(t *testing.T) {
|
||||||
assert.False(t, acc.HasMeasurement("maximum_response_ms"),
|
assert.False(t, acc.HasMeasurement("maximum_response_ms"),
|
||||||
"Fatal ping should not have packet measurements")
|
"Fatal ping should not have packet measurements")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestErrorWithHostNamePingGather(t *testing.T) {
|
||||||
|
params := []struct {
|
||||||
|
out string
|
||||||
|
error error
|
||||||
|
}{
|
||||||
|
{"", errors.New("host www.amazon.com: So very bad")},
|
||||||
|
{"so bad", errors.New("host www.amazon.com: so bad, So very bad")},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, param := range params {
|
||||||
|
var acc testutil.Accumulator
|
||||||
|
p := Ping{
|
||||||
|
Urls: []string{"www.amazon.com"},
|
||||||
|
pingHost: func(timeout float64, args ...string) (string, error) {
|
||||||
|
return param.out, errors.New("So very bad")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
acc.GatherError(p.Gather)
|
||||||
|
assert.True(t, len(acc.Errors) > 0)
|
||||||
|
assert.Contains(t, acc.Errors, param.error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue