Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ping exit code handling on non-Linux #7658

Merged
merged 1 commit into from
Jun 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions plugins/inputs/ping/ping_notwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ func (p *Ping) pingToURL(u string, acc telegraf.Accumulator) {

out, err := p.pingHost(p.Binary, 60.0, p.args(u, runtime.GOOS)...)
if err != nil {
// Some implementations of ping return a 1 exit code on
// Some implementations of ping return a non-zero exit code on
// timeout, if this occurs we will not exit and try to parse
// the output.
// Linux iputils-ping returns 1, BSD-derived ping returns 2.
status := -1
if exitError, ok := err.(*exec.ExitError); ok {
if ws, ok := exitError.Sys().(syscall.WaitStatus); ok {
Expand All @@ -32,7 +33,17 @@ func (p *Ping) pingToURL(u string, acc telegraf.Accumulator) {
}
}

if status != 1 {
var timeoutExitCode int
switch runtime.GOOS {
case "freebsd", "netbsd", "openbsd", "darwin":
timeoutExitCode = 2
case "linux":
timeoutExitCode = 1
default:
timeoutExitCode = 1
}

if status != timeoutExitCode {
// Combine go err + stderr output
out = strings.TrimSpace(out)
if len(out) > 0 {
Expand Down