Fix logger initialization in exec input (#6492)
This commit is contained in:
parent
d7988915e9
commit
74c7dd3ce7
|
@ -158,6 +158,11 @@ func TestConfig_LoadDirectory(t *testing.T) {
|
||||||
MeasurementSuffix: "_myothercollector",
|
MeasurementSuffix: "_myothercollector",
|
||||||
}
|
}
|
||||||
eConfig.Tags = make(map[string]string)
|
eConfig.Tags = make(map[string]string)
|
||||||
|
|
||||||
|
exec := c.Inputs[1].Input.(*exec.Exec)
|
||||||
|
require.NotNil(t, exec.Log)
|
||||||
|
exec.Log = nil
|
||||||
|
|
||||||
assert.Equal(t, ex, c.Inputs[1].Input,
|
assert.Equal(t, ex, c.Inputs[1].Input,
|
||||||
"Merged Testdata did not produce a correct exec struct.")
|
"Merged Testdata did not produce a correct exec struct.")
|
||||||
assert.Equal(t, eConfig, c.Inputs[1].Config,
|
assert.Equal(t, eConfig, c.Inputs[1].Config,
|
||||||
|
|
|
@ -10,13 +10,12 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/kballard/go-shellquote"
|
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
"github.com/influxdata/telegraf/internal"
|
"github.com/influxdata/telegraf/internal"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
"github.com/influxdata/telegraf/plugins/parsers"
|
"github.com/influxdata/telegraf/plugins/parsers"
|
||||||
"github.com/influxdata/telegraf/plugins/parsers/nagios"
|
"github.com/influxdata/telegraf/plugins/parsers/nagios"
|
||||||
|
"github.com/kballard/go-shellquote"
|
||||||
)
|
)
|
||||||
|
|
||||||
const sampleConfig = `
|
const sampleConfig = `
|
||||||
|
@ -50,7 +49,7 @@ type Exec struct {
|
||||||
parser parsers.Parser
|
parser parsers.Parser
|
||||||
|
|
||||||
runner Runner
|
runner Runner
|
||||||
log telegraf.Logger
|
Log telegraf.Logger `toml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExec() *Exec {
|
func NewExec() *Exec {
|
||||||
|
@ -161,7 +160,7 @@ func (e *Exec) ProcessCommand(command string, acc telegraf.Accumulator, wg *sync
|
||||||
if isNagios {
|
if isNagios {
|
||||||
metrics, err = nagios.TryAddState(runErr, metrics)
|
metrics, err = nagios.TryAddState(runErr, metrics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.log.Errorf("Failed to add nagios state: %s", err)
|
e.Log.Errorf("Failed to add nagios state: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ func TestExec(t *testing.T) {
|
||||||
MetricName: "exec",
|
MetricName: "exec",
|
||||||
})
|
})
|
||||||
e := &Exec{
|
e := &Exec{
|
||||||
log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
runner: newRunnerMock([]byte(validJson), nil, nil),
|
runner: newRunnerMock([]byte(validJson), nil, nil),
|
||||||
Commands: []string{"testcommand arg1"},
|
Commands: []string{"testcommand arg1"},
|
||||||
parser: parser,
|
parser: parser,
|
||||||
|
@ -126,7 +126,7 @@ func TestExecMalformed(t *testing.T) {
|
||||||
MetricName: "exec",
|
MetricName: "exec",
|
||||||
})
|
})
|
||||||
e := &Exec{
|
e := &Exec{
|
||||||
log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
runner: newRunnerMock([]byte(malformedJson), nil, nil),
|
runner: newRunnerMock([]byte(malformedJson), nil, nil),
|
||||||
Commands: []string{"badcommand arg1"},
|
Commands: []string{"badcommand arg1"},
|
||||||
parser: parser,
|
parser: parser,
|
||||||
|
@ -143,7 +143,7 @@ func TestCommandError(t *testing.T) {
|
||||||
MetricName: "exec",
|
MetricName: "exec",
|
||||||
})
|
})
|
||||||
e := &Exec{
|
e := &Exec{
|
||||||
log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
runner: newRunnerMock(nil, nil, fmt.Errorf("exit status code 1")),
|
runner: newRunnerMock(nil, nil, fmt.Errorf("exit status code 1")),
|
||||||
Commands: []string{"badcommand"},
|
Commands: []string{"badcommand"},
|
||||||
parser: parser,
|
parser: parser,
|
||||||
|
|
Loading…
Reference in New Issue