From e8461fe27aa647ec4d2078b1b7ec05bc3424bcd8 Mon Sep 17 00:00:00 2001 From: Ricardo Ribalda Delgado Date: Tue, 23 Jun 2020 20:40:53 +0200 Subject: [PATCH] Skip overs errors in the output of the sensors command (#7718) --- internal/exec.go | 14 ++++++++++++++ plugins/inputs/sensors/sensors.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/exec.go b/internal/exec.go index 795822f46..7fe95c0b9 100644 --- a/internal/exec.go +++ b/internal/exec.go @@ -20,6 +20,20 @@ func CombinedOutputTimeout(c *exec.Cmd, timeout time.Duration) ([]byte, error) { return b.Bytes(), err } +// StdOutputTimeout runs the given command with the given timeout and +// returns the output of stdout. +// If the command times out, it attempts to kill the process. +func StdOutputTimeout(c *exec.Cmd, timeout time.Duration) ([]byte, error) { + var b bytes.Buffer + c.Stdout = &b + c.Stderr = nil + if err := c.Start(); err != nil { + return nil, err + } + err := WaitTimeout(c, timeout) + return b.Bytes(), err +} + // RunTimeout runs the given command with the given timeout. // If the command times out, it attempts to kill the process. func RunTimeout(c *exec.Cmd, timeout time.Duration) error { diff --git a/plugins/inputs/sensors/sensors.go b/plugins/inputs/sensors/sensors.go index 864da8121..1df88466b 100644 --- a/plugins/inputs/sensors/sensors.go +++ b/plugins/inputs/sensors/sensors.go @@ -60,7 +60,7 @@ func (s *Sensors) parse(acc telegraf.Accumulator) error { fields := map[string]interface{}{} chip := "" cmd := execCommand(s.path, "-A", "-u") - out, err := internal.CombinedOutputTimeout(cmd, s.Timeout.Duration) + out, err := internal.StdOutputTimeout(cmd, s.Timeout.Duration) if err != nil { return fmt.Errorf("failed to run command %s: %s - %s", strings.Join(cmd.Args, " "), err, string(out)) }