bugfix badword and change detection

This commit is contained in:
AJ ONeal 2019-07-04 19:19:14 -06:00
parent 80ad9d9dc3
commit e3de4a2ef6
1 changed files with 8 additions and 3 deletions

View File

@ -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() { func (d *Dog) watch() {
d.Logger <- fmt.Sprintf("Check: '%s'", d.Name) d.Logger <- fmt.Sprintf("Check: '%s'", d.Name)
@ -88,6 +90,7 @@ func (d *Dog) watch() {
if nil != err2 { if nil != err2 {
d.Logger <- fmt.Sprintf("Down: '%s': %s", d.Name, err2) d.Logger <- fmt.Sprintf("Down: '%s': %s", d.Name, err2)
} else { } else {
d.notify("hiccuped")
d.Logger <- fmt.Sprintf("Hiccup: '%s': %s", d.Name, err) d.Logger <- fmt.Sprintf("Hiccup: '%s': %s", d.Name, err)
return return
} }
@ -109,11 +112,13 @@ func (d *Dog) watch() {
// TODO what if the server is flip-flopping rapidly? // TODO what if the server is flip-flopping rapidly?
// how to rate limit? // how to rate limit?
// "{{ .Server }} is on cooldown for 30 minutes" // "{{ .Server }} is on cooldown for 30 minutes"
if changed { if changed || d.changed {
changed = false changed = false
d.notify("went down")
if StatusUp == d.status { if StatusUp == d.status {
d.notify("came back up")
break break
} else {
d.notify("went down")
} }
// * We've had success since the last notification // * We've had success since the last notification
@ -176,7 +181,7 @@ func (d *Dog) check() error {
} }
if "" != d.Badwords { 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) err = fmt.Errorf("Down: '%s' Found for '%s'", d.Badwords, d.Name)
d.Logger <- fmt.Sprintf("%s", err) d.Logger <- fmt.Sprintf("%s", err)
d.error = err d.error = err