diff --git a/config/types.go b/config/types.go index 5703c84117196..3acf3d1d6019e 100644 --- a/config/types.go +++ b/config/types.go @@ -18,14 +18,14 @@ type Size int64 type Number float64 // UnmarshalTOML parses the duration from the TOML config file -func (d Duration) UnmarshalTOML(b []byte) error { +func (d *Duration) UnmarshalTOML(b []byte) error { var err error b = bytes.Trim(b, `'`) // see if we can directly convert it dur, err := time.ParseDuration(string(b)) if err == nil { - d = Duration(dur) + *d = Duration(dur) return nil } @@ -33,7 +33,7 @@ func (d Duration) UnmarshalTOML(b []byte) error { if uq, err := strconv.Unquote(string(b)); err == nil && len(uq) > 0 { dur, err := time.ParseDuration(uq) if err == nil { - d = Duration(dur) + *d = Duration(dur) return nil } } @@ -42,27 +42,27 @@ func (d Duration) UnmarshalTOML(b []byte) error { sI, err := strconv.ParseInt(string(b), 10, 64) if err == nil { dur := time.Second * time.Duration(sI) - d = Duration(dur) + *d = Duration(dur) return nil } // Second try parsing as float seconds sF, err := strconv.ParseFloat(string(b), 64) if err == nil { dur := time.Second * time.Duration(sF) - d = Duration(dur) + *d = Duration(dur) return nil } return nil } -func (s Size) UnmarshalTOML(b []byte) error { +func (s *Size) UnmarshalTOML(b []byte) error { var err error b = bytes.Trim(b, `'`) val, err := strconv.ParseInt(string(b), 10, 64) if err == nil { - s = Size(val) + *s = Size(val) return nil } uq, err := strconv.Unquote(string(b)) @@ -73,16 +73,16 @@ func (s Size) UnmarshalTOML(b []byte) error { if err != nil { return err } - s = Size(val) + *s = Size(val) return nil } -func (n Number) UnmarshalTOML(b []byte) error { +func (n *Number) UnmarshalTOML(b []byte) error { value, err := strconv.ParseFloat(string(b), 64) if err != nil { return err } - n = Number(value) + *n = Number(value) return nil } diff --git a/plugins/inputs/execd/execd.go b/plugins/inputs/execd/execd.go index cfac99bbe5880..228c38db50f76 100644 --- a/plugins/inputs/execd/execd.go +++ b/plugins/inputs/execd/execd.go @@ -41,10 +41,10 @@ const sampleConfig = ` ` type Execd struct { - Command []string - Signal string - RestartDelay config.Duration - Log telegraf.Logger + Command []string `toml:"command"` + Signal string `toml:"signal"` + RestartDelay config.Duration `toml:"restart_delay"` + Log telegraf.Logger `toml:"-"` process *process.Process acc telegraf.Accumulator diff --git a/plugins/inputs/execd/execd_test.go b/plugins/inputs/execd/execd_test.go index 2a26cfe56bcd6..a7be617da3a48 100644 --- a/plugins/inputs/execd/execd_test.go +++ b/plugins/inputs/execd/execd_test.go @@ -24,6 +24,24 @@ import ( "github.com/influxdata/telegraf" ) +func TestSettingConfigWorks(t *testing.T) { + cfg := ` + [[inputs.execd]] + command = ["a", "b", "c"] + restart_delay = "1m" + signal = "SIGHUP" + ` + conf := config.NewConfig() + require.NoError(t, conf.LoadConfigData([]byte(cfg))) + + require.Len(t, conf.Inputs, 1) + inp, ok := conf.Inputs[0].Input.(*Execd) + require.True(t, ok) + require.EqualValues(t, []string{"a", "b", "c"}, inp.Command) + require.EqualValues(t, 1*time.Minute, inp.RestartDelay) + require.EqualValues(t, "SIGHUP", inp.Signal) +} + func TestExternalInputWorks(t *testing.T) { influxParser, err := parsers.NewInfluxParser() require.NoError(t, err)