From 447238fc37a50a0971d78230a725df9d1fc00a29 Mon Sep 17 00:00:00 2001 From: kongfei605 Date: Mon, 29 Apr 2024 19:11:05 +0800 Subject: [PATCH] feat: exec support remote config (#909) --- inputs/exec/exec.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/inputs/exec/exec.go b/inputs/exec/exec.go index d9e2430a..c8b2925d 100644 --- a/inputs/exec/exec.go +++ b/inputs/exec/exec.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "log" + "os" osExec "os/exec" "path/filepath" "runtime" @@ -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"` @@ -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 }