clarify docs and add warning if execd is misconfigured (#7866)

This commit is contained in:
Steven Soroka 2020-07-20 17:41:04 -04:00
parent 641b1d60cd
commit de313fcde6
6 changed files with 30 additions and 3 deletions

View File

@ -17,7 +17,8 @@ STDERR from the process will be relayed to Telegraf as errors in the logs.
```toml
[[inputs.execd]]
## Program to run as daemon
## One program to run as daemon.
## NOTE: process and each argument should each be their own string
command = ["telegraf-smartctl", "-d", "/dev/sda"]
## Define how the process is signaled on each collection interval.

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"strings"
"time"
"github.com/influxdata/telegraf"
@ -75,6 +76,13 @@ func (e *Execd) Start(acc telegraf.Accumulator) error {
e.process.ReadStderrFn = e.cmdReadErr
if err = e.process.Start(); err != nil {
// if there was only one argument, and it contained spaces, warn the user
// that they may have configured it wrong.
if len(e.Command) == 1 && strings.Contains(e.Command[0], " ") {
e.Log.Warn("The inputs.execd Command contained spaces but no arguments. " +
"This setting expects the program and arguments as an array of strings, " +
"not as a space-delimited string. See the plugin readme for an example.")
}
return fmt.Errorf("failed to start process %s: %w", e.Command, err)
}

View File

@ -8,7 +8,8 @@ Telegraf minimum version: Telegraf 1.15.0
```toml
[[outputs.execd]]
## Program to run as daemon
## One program to run as daemon.
## NOTE: process and each argument should each be their own string
command = ["my-telegraf-output", "--some-flag", "value"]
## Delay before the process is restarted after an unexpected termination

View File

@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"io"
"strings"
"time"
"github.com/influxdata/telegraf"
@ -69,6 +70,13 @@ func (e *Execd) Init() error {
func (e *Execd) Connect() error {
if err := e.process.Start(); err != nil {
// if there was only one argument, and it contained spaces, warn the user
// that they may have configured it wrong.
if len(e.Command) == 1 && strings.Contains(e.Command[0], " ") {
e.Log.Warn("The outputs.execd Command contained spaces but no arguments. " +
"This setting expects the program and arguments as an array of strings, " +
"not as a space-delimited string. See the plugin readme for an example.")
}
return fmt.Errorf("failed to start process %s: %w", e.Command, err)
}

View File

@ -24,7 +24,8 @@ Telegraf minimum version: Telegraf 1.15.0
```toml
[[processor.execd]]
## Program to run as daemon
## One program to run as daemon.
## NOTE: process and each argument should each be their own string
## eg: command = ["/path/to/your_program", "arg1", "arg2"]
command = ["cat"]

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"strings"
"time"
"github.com/influxdata/telegraf"
@ -79,6 +80,13 @@ func (e *Execd) Start(acc telegraf.Accumulator) error {
e.process.ReadStderrFn = e.cmdReadErr
if err = e.process.Start(); err != nil {
// if there was only one argument, and it contained spaces, warn the user
// that they may have configured it wrong.
if len(e.Command) == 1 && strings.Contains(e.Command[0], " ") {
e.Log.Warn("The processors.execd Command contained spaces but no arguments. " +
"This setting expects the program and arguments as an array of strings, " +
"not as a space-delimited string. See the plugin readme for an example.")
}
return fmt.Errorf("failed to start process %s: %w", e.Command, err)
}