diff options
| author | Gibheer <gibheer+git@zero-knowledge.org> | 2018-12-10 09:34:00 +0100 | 
|---|---|---|
| committer | Gibheer <gibheer+git@zero-knowledge.org> | 2018-12-10 09:34:00 +0100 | 
| commit | 40e744cd6a372a1c44f5a827f253f163b046e9c3 (patch) | |
| tree | 5be33377d7ca801ab150f219c3e1fbda3f339b05 /cmd | |
| parent | 3400167c98c78a2cf104cd4be3907450e01c56ff (diff) | |
moncheck - add PATH environment
This adds the path environment configuration to control which programs
to call.
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/moncheck/main.go | 15 | 
1 files 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) | 
