Commands all running

This commit is contained in:
Ian Fijolek
2019-10-02 09:37:29 -07:00
parent dd0b8e3f38
commit 7b746ed62a
6 changed files with 262 additions and 43 deletions
+23 -1
View File
@@ -1,6 +1,7 @@
package main
import (
"log"
"time"
)
@@ -10,7 +11,28 @@ func main() {
for {
for _, monitor := range config.Monitors {
if monitor.ShouldCheck() {
monitor.Check()
_, alertNotice := monitor.Check()
if alertNotice != nil {
//log.Printf("Recieved an alert notice: %v", alertNotice)
var alerts []string
if alertNotice.IsUp {
alerts = monitor.AlertUp
log.Printf("Alert up: %v", monitor.AlertUp)
} else {
alerts = monitor.AlertDown
log.Printf("Alert down: %v", monitor.AlertDown)
}
if alerts == nil {
log.Printf("WARNING: Found alert, but no alert mechanism: %v", alertNotice)
}
for _, alertName := range alerts {
if alert, ok := config.Alerts[alertName]; ok {
alert.Send(*alertNotice)
} else {
log.Printf("WARNING: Could not find alert for %s", alertName)
}
}
}
}
}