Skip to content

Commit

Permalink
Add timeout option - solves influxdata#2817
Browse files Browse the repository at this point in the history
  • Loading branch information
Matteo Cerutti committed May 17, 2017
1 parent 7155e90 commit 98c8c92
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
### Features

- [#2773](https://github.com/influxdata/telegraf/pull/2773): Add support for self-signed certs to InfluxDB input plugin
- [#2817](https://github.com/influxdata/telegraf/pull/2817): Added timeout option to IPMI sensor plugin

### Bugfixes

Expand Down
3 changes: 3 additions & 0 deletions plugins/inputs/ipmi_sensor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ The `server` tag will be made available when retrieving stats from remote server
## if no servers are specified, local machine sensor stats will be queried
##
# servers = ["USERID:PASSW0RD@lan(192.168.1.1)"]

## Timeout for the ipmitool command to complete. Default is 30 seconds.
timeout = "30s"
```

## Output
Expand Down
7 changes: 6 additions & 1 deletion plugins/inputs/ipmi_sensor/ipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
type Ipmi struct {
Path string
Servers []string
Timeout internal.Duration
}

var sampleConfig = `
Expand All @@ -33,6 +34,9 @@ var sampleConfig = `
## if no servers are specified, local machine sensor stats will be queried
##
# servers = ["USERID:PASSW0RD@lan(192.168.1.1)"]
## Timeout for the ipmitool command to complete
timeout = "30s"
`

func (m *Ipmi) SampleConfig() string {
Expand Down Expand Up @@ -78,7 +82,7 @@ func (m *Ipmi) parse(acc telegraf.Accumulator, server string) error {

opts = append(opts, "sdr")
cmd := execCommand(m.Path, opts...)
out, err := internal.CombinedOutputTimeout(cmd, time.Second*5)
out, err := internal.CombinedOutputTimeout(cmd, m.Timeout.Duration)
if err != nil {
return fmt.Errorf("failed to run command %s: %s - %s", strings.Join(cmd.Args, " "), err, string(out))
}
Expand Down Expand Up @@ -152,6 +156,7 @@ func init() {
if len(path) > 0 {
m.Path = path
}
m.Timeout = internal.Duration{Duration: time.Second * 30}
inputs.Add("ipmi_sensor", func() telegraf.Input {
m := m
return &m
Expand Down
6 changes: 5 additions & 1 deletion plugins/inputs/ipmi_sensor/ipmi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"os"
"os/exec"
"testing"
"time"

"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -15,6 +17,7 @@ func TestGather(t *testing.T) {
i := &Ipmi{
Servers: []string{"USERID:PASSW0RD@lan(192.168.1.1)"},
Path: "ipmitool",
Timeout: internal.Duration{Duration: time.Second * 5},
}
// overwriting exec commands with mock commands
execCommand = fakeExecCommand
Expand Down Expand Up @@ -118,7 +121,8 @@ func TestGather(t *testing.T) {
}

i = &Ipmi{
Path: "ipmitool",
Path: "ipmitool",
Timeout: internal.Duration{Duration: time.Second * 5},
}

err = acc.GatherError(i.Gather)
Expand Down

0 comments on commit 98c8c92

Please sign in to comment.