Skip to content

Commit

Permalink
Remove log message on ping timeout (#3126)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored Aug 16, 2017
1 parent 09153c8 commit eb0215c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
29 changes: 25 additions & 4 deletions plugins/inputs/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ package ping

import (
"errors"
"fmt"
"os/exec"
"runtime"
"strconv"
"strings"
"sync"
"syscall"
"time"

"github.com/influxdata/telegraf"
Expand Down Expand Up @@ -76,17 +78,36 @@ func (p *Ping) Gather(acc telegraf.Accumulator) error {
defer wg.Done()
args := p.args(u)
totalTimeout := float64(p.Count)*p.Timeout + float64(p.Count-1)*p.PingInterval

out, err := p.pingHost(totalTimeout, args...)
if err != nil {
// Combine go err + stderr output
acc.AddError(errors.New(
strings.TrimSpace(out) + ", " + err.Error()))
// Some implementations of ping return a 1 exit code on
// timeout, if this occurs we will not exit and try to parse
// the output.
status := -1
if exitError, ok := err.(*exec.ExitError); ok {
if ws, ok := exitError.Sys().(syscall.WaitStatus); ok {
status = ws.ExitStatus()
}
}

if status != 1 {
// Combine go err + stderr output
out = strings.TrimSpace(out)
if len(out) > 0 {
acc.AddError(fmt.Errorf("%s, %s", out, err))
} else {
acc.AddError(err)
}
return
}
}

tags := map[string]string{"url": u}
trans, rec, min, avg, max, stddev, err := processPingOutput(out)
if err != nil {
// fatal error
acc.AddError(err)
acc.AddError(fmt.Errorf("%s: %s", err, u))
return
}
// Calculate packet loss percentage
Expand Down
3 changes: 2 additions & 1 deletion plugins/inputs/ping/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ Request timeout for icmp_seq 0
`

func mockErrorHostPinger(timeout float64, args ...string) (string, error) {
return errorPingOutput, errors.New("No packets received")
// This error will not trigger correct error paths
return errorPingOutput, nil
}

// Test that Gather works on a ping with no transmitted packets, even though the
Expand Down

0 comments on commit eb0215c

Please sign in to comment.