exec plugin: allow using glob pattern in command list
Allow using glob pattern in the command list in configuration. This enables for example placing all commands in a single directory and using /path/to/dir/*.sh as one of the commands to run all shell scripts in that directory. Glob patterns are applied on every run of the commands, so matching commands can be added without restarting telegraf.
This commit is contained in:
parent
5d3c582ecf
commit
df7318a08a
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
@ -139,10 +140,19 @@ func (e *Exec) Gather(acc telegraf.Accumulator) error {
|
||||||
e.Command = ""
|
e.Command = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
e.errChan = make(chan error, len(e.Commands))
|
commands := make([]string, len(e.Commands))
|
||||||
|
for _, pattern := range e.Commands {
|
||||||
|
matches, err := filepath.Glob(pattern)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
commands = append(commands, matches...)
|
||||||
|
}
|
||||||
|
|
||||||
e.wg.Add(len(e.Commands))
|
e.errChan = make(chan error, len(commands))
|
||||||
for _, command := range e.Commands {
|
|
||||||
|
e.wg.Add(len(commands))
|
||||||
|
for _, command := range commands {
|
||||||
go e.ProcessCommand(command, acc)
|
go e.ProcessCommand(command, acc)
|
||||||
}
|
}
|
||||||
e.wg.Wait()
|
e.wg.Wait()
|
||||||
|
|
Loading…
Reference in New Issue