telegraf/plugins/inputs/ipmi_sensor/command.go

36 lines
693 B
Go
Raw Permalink Normal View History

package ipmi_sensor
2016-03-17 15:45:29 +00:00
import (
"fmt"
"os/exec"
"strings"
"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...)
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)",
cmd.Path, strings.Join(cmd.Args, " "), string(output), err)
2016-03-17 15:45:29 +00:00
}
return string(output), err
2016-03-17 15:45:29 +00:00
}