Skip to content

Commit

Permalink
feat: exec support remote config (#909)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongfei605 authored Apr 29, 2024
1 parent e135214 commit 447238f
Showing 1 changed file with 17 additions and 0 deletions.
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

0 comments on commit 447238f

Please sign in to comment.