From 65342fe0ddb31f2302cda4109c0cc36792e4af50 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Tue, 18 Feb 2020 00:47:43 +0000 Subject: [PATCH] Add a default log alert --- alert.go | 13 +++++++++++++ config.go | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/alert.go b/alert.go index 85b85ce..3ea08e3 100644 --- a/alert.go +++ b/alert.go @@ -112,3 +112,16 @@ func (alert Alert) Send(notice AlertNotice) (outputStr string, err error) { return outputStr, err } + +// NewLogAlert creates an alert that does basic logging using echo +func NewLogAlert() *Alert { + return &Alert{ + Name: "log", + Command: CommandOrShell{ + Command: []string{ + "echo", + "{{.MonitorName}} check has failed {{.FailureCount}} times", + }, + }, + } +} diff --git a/config.go b/config.go index fd237a4..f441925 100644 --- a/config.go +++ b/config.go @@ -117,6 +117,11 @@ func LoadConfig(filePath string) (config Config, err error) { log.Printf("DEBUG: Config values:\n%v\n", config) } + if _, ok := config.Alerts["log"]; !ok { + log.Printf("Adding log alert") + config.Alerts["log"] = NewLogAlert() + } + if !config.IsValid() { err = errors.New("Invalid configuration") return