From 1bc0252b841e67fb788b5fed2b37d49327ed3c35 Mon Sep 17 00:00:00 2001 From: Norwin Roosen Date: Fri, 29 Jun 2018 00:50:36 +0200 Subject: [PATCH] use default checks when no .events are configured #1 --- cmd/shared.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cmd/shared.go b/cmd/shared.go index bf2c40e..1e86d62 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -4,6 +4,7 @@ import ( "fmt" "regexp" + log "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -33,12 +34,40 @@ func BoxIdValidator(cmd *cobra.Command, args []string) error { } func checkAndNotify(boxIds []string) error { + defaultNotifyConf := &core.NotifyConfig{} err := viper.UnmarshalKey("defaultHealthchecks", defaultNotifyConf) if err != nil { return err } + // set default events, when no events are given. an empty events key indicates no checks are desired + if len(defaultNotifyConf.Events) == 0 { + allKeys := viper.AllKeys() + eventsDefined := false + for _, k := range allKeys { + if k == "defaulthealthchecks.events" { + eventsDefined = true + break + } + } + if !eventsDefined { + log.Debug("using default checks") + defaultNotifyConf.Events = []core.NotifyEvent{ + core.NotifyEvent{ + Type: "measurement_age", + Target: "all", + Threshold: "15m", + }, + core.NotifyEvent{ + Type: "measurement_faulty", + Target: "all", + Threshold: "", + }, + } + } + } + results, err := core.CheckBoxes(boxIds, defaultNotifyConf) if err != nil { return err