command action
This commit is contained in:
parent
4721baa00b
commit
b3b1ad87b9
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
tmp/
|
||||
fstrigger
|
||||
|
25
main.go
25
main.go
@ -8,6 +8,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
@ -45,6 +46,10 @@ type ActionConfig struct {
|
||||
Body *string
|
||||
From *string
|
||||
|
||||
// command
|
||||
Command *string
|
||||
Args []string
|
||||
|
||||
Stop bool
|
||||
OnSuccess []ActionConfig `yaml:"onSuccess"`
|
||||
OnError []ActionConfig `yaml:"onError"`
|
||||
@ -256,6 +261,8 @@ func runAction(action *ActionConfig, eventInfo notify.EventInfo, ctx actionCtx)
|
||||
err = actionLog(action, eventInfo, ctx)
|
||||
case "mail":
|
||||
err = actionMail(action, eventInfo, ctx)
|
||||
case "command":
|
||||
err = actionCommand(action, eventInfo, ctx)
|
||||
default:
|
||||
err = fmt.Errorf("action type %s unknown", action.Type)
|
||||
}
|
||||
@ -506,6 +513,24 @@ func actionMail(action *ActionConfig, eventInfo notify.EventInfo, ctx actionCtx)
|
||||
return mail.Send()
|
||||
}
|
||||
|
||||
func actionCommand(action *ActionConfig, eventInfo notify.EventInfo, ctx actionCtx) error {
|
||||
if action.Command == nil {
|
||||
return fmt.Errorf("missing command")
|
||||
}
|
||||
args := make([]string, len(action.Args))
|
||||
for idx, a := range action.Args {
|
||||
var err error
|
||||
args[idx], err = tpl2String(a, action, eventInfo, ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
out, err := exec.Command(*action.Command, action.Args...).Output()
|
||||
log.Println("COMMAND OUTPUT: ", string(out))
|
||||
return err
|
||||
}
|
||||
|
||||
func tpl2String(tpl string, action *ActionConfig, eventInfo notify.EventInfo, ctx actionCtx) (string, error) {
|
||||
_tpl, err := pongo2.FromString(tpl)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user