From 27605997c14d8484f0a23a8586b6446f589d51a2 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Tue, 11 Jan 2022 07:50:58 -0500 Subject: [PATCH] emailer configurable interval --- config.json | 3 ++- config/config.go | 1 + main.go | 17 ++++++++--------- todo.yaml | 3 +++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/config.json b/config.json index 01159fd..d593d38 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,8 @@ { "Interval": { "OK": "6h0m0s", - "Error": "6h" + "Error": "6h", + "Email": "15m" }, "States": [ "GA" diff --git a/config/config.go b/config/config.go index 947cbc8..fbdfeb2 100644 --- a/config/config.go +++ b/config/config.go @@ -11,6 +11,7 @@ import ( type Config struct { Interval struct { + Email Duration OK Duration Error Duration } diff --git a/main.go b/main.go index 3817cfc..b00ace2 100644 --- a/main.go +++ b/main.go @@ -21,16 +21,15 @@ var stateFinder = regexp.MustCompile(`[A-Za-z]+`) func main() { lock := &sync.Mutex{} go func() { - c := time.NewTicker(time.Minute) - for range c.C { - if !config.Get().EmailerEnabled { - continue + for { + if config.Get().EmailerEnabled { + lock.Lock() + if err := email(); err != nil { + log.Print(err) + } + lock.Unlock() } - lock.Lock() - if err := email(); err != nil { - log.Print(err) - } - lock.Unlock() + time.Sleep(config.Get().Interval.Email.Get()) } }() if err := _main(); err != nil { diff --git a/todo.yaml b/todo.yaml index 0b8b20c..d81f141 100644 --- a/todo.yaml +++ b/todo.yaml @@ -4,7 +4,10 @@ todo: - banlist criteria like vendors, brokers, metadata - quiet hours - setup pa on element +- accept states via element for one system done: +- configurable email interval +- jitter on intervals, including dedicated err span - email doesnt get all matches - send jobs - read jobs