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
Raw Permalink Normal View History

2019-06-10 17:09:10 +00:00
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)
}
}
2019-06-11 07:44:35 +00:00
func runLogAction(sourceName, text string) {
2019-06-10 17:09:10 +00:00
log.Printf("[%s] %s", sourceName, text)
2019-06-11 07:44:35 +00:00
dir, err := os.Getwd()
if err != nil {
log.Printf("Failed to get working directory: %v", err)
return
2019-06-10 17:09:10 +00:00
}
2019-06-11 07:44:35 +00:00
action := filepath.Join(dir, "log-action")
2019-06-10 17:09:10 +00:00
run(action, sourceName, text)
}
2019-06-11 07:44:35 +00:00
func runAlertAction(sourceName, text string) {
2019-06-10 17:09:10 +00:00
log.Printf("[%s] ALERT %s", sourceName, text)
2019-06-11 07:44:35 +00:00
dir, err := os.Getwd()
if err != nil {
log.Printf("Failed to get working directory: %v", err)
return
2019-06-10 17:09:10 +00:00
}
2019-06-11 07:44:35 +00:00
action := filepath.Join(dir, "alert-action")
2019-06-10 17:09:10 +00:00
run(action, sourceName, text)
}