Added ability to run commands in a shell

Diverges a small amount from the Python version for this.
This commit is contained in:
Ian Fijolek
2019-10-01 08:26:07 -07:00
parent 342b12432e
commit dd0b8e3f38
4 changed files with 37 additions and 4 deletions
+10 -2
View File
@@ -1,7 +1,9 @@
package main
import (
"bytes"
"fmt"
"log"
"os/exec"
"text/template"
"time"
@@ -12,7 +14,7 @@ type Alert struct {
Command []string
CommandShell string `yaml:"command_shell"`
commandTemplate []template.Template
commandShellTemplate template.Template
commandShellTemplate *template.Template
}
func (alert Alert) IsValid() bool {
@@ -43,8 +45,14 @@ func (alert Alert) Send(notice AlertNotice) {
} else if alert.commandShellTemplate != nil {
var commandBuffer bytes.Buffer
err := alert.commandShellTemplate.Execute(&commandBuffer, notice)
// TODO handle error
if err != nil {
panic(err)
}
cmd = exec.Command(commandBuffer.String())
output, err := cmd.CombinedOutput()
log.Printf("Check %s\n---\n%s\n---", alert.Name, string(output))
} else {
panic("No template?")
}