diff options
| author | Paul Buetow <paul@buetow.org> | 2023-04-17 20:41:22 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-04-17 20:41:22 +0300 |
| commit | e40e22f69470b987bfb2c39b4a18df67f497739d (patch) | |
| tree | 73d03e14614b5b29ff07dec4ccb4cdad61234493 /main.go | |
| parent | f7456fded178b85637c82255e9c3178817f5fa68 (diff) | |
can keep state
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -4,15 +4,11 @@ import ( "context" "flag" "fmt" - "log" "time" ) func main() { - log.Println("Welcome to Gogios!") - configFile := flag.String("cfg", "/etc/gogios.json", "The config file") - flag.Parse() config, err := newConfig(*configFile) @@ -20,14 +16,26 @@ func main() { panic(err) } - for _, check := range config.Checks { + state, err := newState(config) + if err != nil { + notifyError(config, err) + } + + for name, check := range config.Checks { ctx, cancel := context.WithTimeout(context.Background(), time.Duration(config.CheckTimeoutS)*time.Second) defer cancel() - if output, status := check.execute(ctx); status != ok { + output, status := check.execute(ctx) + stateChanged := state.update(name, status) + + if status != ok || stateChanged { subject := fmt.Sprintf("GOGIOS %s: %s", codeToString(status), check.Name) notify(config, subject, output) } } + + if err := state.persist(); err != nil { + notifyError(config, err) + } } |
