Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: exec support remote config #909

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions inputs/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"os"
osExec "os/exec"
"path/filepath"
"runtime"
Expand All @@ -29,6 +30,8 @@ const MaxStderrBytes int = 512
type Instance struct {
config.InstanceConfig

Scripts map[string]string `toml:"scripts"`

Commands []string `toml:"commands"`
Timeout config.Duration `toml:"timeout"`
DataFormat string `toml:"data_format"`
Expand Down Expand Up @@ -63,6 +66,20 @@ func (e *Exec) GetInstances() []inputs.Instance {
}

func (ins *Instance) Init() error {
if len(ins.Scripts) > 0 {
for script, content := range ins.Scripts {
dir := filepath.Dir(script)
file := filepath.Base(script)
err := os.MkdirAll(dir, 0755)
if err != nil {
return err
}
err = os.WriteFile(filepath.Join(dir, file), []byte(content), 0755)
if err != nil {
return fmt.Errorf("write script %s error: %s", script, err)
}
}
}
if len(ins.Commands) == 0 {
return types.ErrInstancesEmpty
}
Expand Down
Loading