2016-03-23 15:40:38 +00:00
|
|
|
package ipmi_sensor
|
2016-03-17 15:45:29 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
2016-04-29 01:23:45 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/influxdata/telegraf/internal"
|
2016-03-17 15:45:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type CommandRunner struct{}
|
|
|
|
|
|
|
|
func (t CommandRunner) cmd(conn *Connection, args ...string) *exec.Cmd {
|
|
|
|
path := conn.Path
|
|
|
|
opts := append(conn.options(), args...)
|
|
|
|
|
|
|
|
if path == "" {
|
|
|
|
path = "ipmitool"
|
|
|
|
}
|
|
|
|
|
|
|
|
return exec.Command(path, opts...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t CommandRunner) Run(conn *Connection, args ...string) (string, error) {
|
|
|
|
cmd := t.cmd(conn, args...)
|
|
|
|
|
2016-04-29 01:23:45 +00:00
|
|
|
output, err := internal.CombinedOutputTimeout(cmd, time.Second*5)
|
2016-03-17 15:45:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("run %s %s: %s (%s)",
|
2016-04-29 01:23:45 +00:00
|
|
|
cmd.Path, strings.Join(cmd.Args, " "), string(output), err)
|
2016-03-17 15:45:29 +00:00
|
|
|
}
|
|
|
|
|
2016-04-29 01:23:45 +00:00
|
|
|
return string(output), err
|
2016-03-17 15:45:29 +00:00
|
|
|
}
|