summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-04-17 20:41:22 +0300
committerPaul Buetow <paul@buetow.org>2023-04-17 20:41:22 +0300
commite40e22f69470b987bfb2c39b4a18df67f497739d (patch)
tree73d03e14614b5b29ff07dec4ccb4cdad61234493 /main.go
parentf7456fded178b85637c82255e9c3178817f5fa68 (diff)
can keep state
Diffstat (limited to 'main.go')
-rw-r--r--main.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/main.go b/main.go
index cf63a5f..d7df829 100644
--- a/main.go
+++ b/main.go
@@ -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)
+ }
}