From 40e744cd6a372a1c44f5a827f253f163b046e9c3 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Mon, 10 Dec 2018 09:34:00 +0100 Subject: moncheck - add PATH environment This adds the path environment configuration to control which programs to call. --- cmd/moncheck/main.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/moncheck/main.go b/cmd/moncheck/main.go index cc05594..60051e2 100644 --- a/cmd/moncheck/main.go +++ b/cmd/moncheck/main.go @@ -10,6 +10,7 @@ import ( "fmt" "io/ioutil" "log" + "os" "os/exec" "strconv" "strings" @@ -26,9 +27,10 @@ var ( type ( Config struct { - DB string `json:"db"` - Timeout string `json:"timeout"` - Wait string `json:"wait"` + DB string `json:"db"` + Timeout string `json:"timeout"` + Wait string `json:"wait"` + Path []string `json:"path"` } States []int @@ -46,6 +48,10 @@ func main() { log.Fatalf("could not parse config: %s", err) } + if err := os.Setenv("PATH", strings.Join(config.Path, ":")); err != nil { + log.Fatalf("could not set PATH: %s", err) + } + waitDuration, err := time.ParseDuration(config.Wait) if err != nil { log.Fatalf("could not parse wait duration: %s", err) @@ -119,6 +125,9 @@ func check(thread int, db *sql.DB, waitDuration, timeout time.Duration) { // TODO all this casting should be done better states.Add(99) fmt.Fprintf(output, "check took longer than %s", timeout) + } else if err != nil && cmd.ProcessState == nil { + log.Printf("[%d] error running check: %s", id, err) + states.Add(1) } else if err != nil { cancel() status, ok := cmd.ProcessState.Sys().(syscall.WaitStatus) -- cgit v1.2.3-70-g09d2