This repository has been archived on 2019-06-27. You can view files and clone it, but cannot push or open issues/pull-requests.
am/actions.go

42 lines
823 B
Go

package am
import (
"log"
"os"
"os/exec"
"path/filepath"
)
func run(cmd, name, text string) {
c := exec.Command(cmd, name, text)
c.Stderr = os.Stderr
if err := c.Run(); err != nil {
log.Printf("Failed to run command in shell `%s`: %v", cmd, err)
}
}
func runLogAction(sourceName, text string) {
log.Printf("[%s] %s", sourceName, text)
dir, err := os.Getwd()
if err != nil {
log.Printf("Failed to get working directory: %v", err)
return
}
action := filepath.Join(dir, "log-action")
run(action, sourceName, text)
}
func runAlertAction(sourceName, text string) {
log.Printf("[%s] ALERT %s", sourceName, text)
dir, err := os.Getwd()
if err != nil {
log.Printf("Failed to get working directory: %v", err)
return
}
action := filepath.Join(dir, "alert-action")
run(action, sourceName, text)
}