From e3de4a2ef6ae0c916d510e88fda01e2b88cf82cc Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 4 Jul 2019 19:19:14 -0600 Subject: [PATCH] bugfix badword and change detection --- watchdog.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/watchdog.go b/watchdog.go index f0c0ca3..05193f6 100644 --- a/watchdog.go +++ b/watchdog.go @@ -70,6 +70,8 @@ func (d *Dog) Watch() { } } +// Now that I've added the ability to notify when a server is back up +// this definitely needs some refactoring. It's bad now. func (d *Dog) watch() { d.Logger <- fmt.Sprintf("Check: '%s'", d.Name) @@ -88,6 +90,7 @@ func (d *Dog) watch() { if nil != err2 { d.Logger <- fmt.Sprintf("Down: '%s': %s", d.Name, err2) } else { + d.notify("hiccuped") d.Logger <- fmt.Sprintf("Hiccup: '%s': %s", d.Name, err) return } @@ -109,11 +112,13 @@ func (d *Dog) watch() { // TODO what if the server is flip-flopping rapidly? // how to rate limit? // "{{ .Server }} is on cooldown for 30 minutes" - if changed { + if changed || d.changed { changed = false - d.notify("went down") if StatusUp == d.status { + d.notify("came back up") break + } else { + d.notify("went down") } // * We've had success since the last notification @@ -176,7 +181,7 @@ func (d *Dog) check() error { } if "" != d.Badwords { - if !bytes.Contains(b, []byte(d.Badwords)) { + if bytes.Contains(b, []byte(d.Badwords)) { err = fmt.Errorf("Down: '%s' Found for '%s'", d.Badwords, d.Name) d.Logger <- fmt.Sprintf("%s", err) d.error = err