we're doing it kinda wrong, we should mention stale results when a check switches to OK/FAIL to do this, we need to track the age of a failed check
39 lines
900 B
Go
39 lines
900 B
Go
package cmd
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func init() {
|
|
watchCmd.PersistentFlags().DurationP("interval", "i", 5*time.Minute, "interval to run checks in")
|
|
viper.BindPFlags(watchCmd.PersistentFlags())
|
|
rootCmd.AddCommand(watchCmd)
|
|
}
|
|
|
|
var watchCmd = &cobra.Command{
|
|
Use: "watch [...<check-ids>]",
|
|
Short: "Continously run all or specific healthchecks",
|
|
Long: "specify target IDs to watch them for events",
|
|
Args: ValidateCheckID,
|
|
PreRun: func(cmd *cobra.Command, args []string) {
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
ticker := time.NewTicker(viper.GetDuration("interval")).C
|
|
cmd.SilenceUsage = true
|
|
err := checkAndNotify(args)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for {
|
|
<-ticker
|
|
err = checkAndNotify(args)
|
|
if err != nil {
|
|
// we already did retries, so exiting seems appropriate
|
|
return err
|
|
}
|
|
}
|
|
},
|
|
}
|