Add implementation for `UpdateNotified` Check

pull/258/head
Emanuel Bennici 2019-10-04 14:48:56 +02:00
parent d062839b52
commit 2a3c682013
No known key found for this signature in database
GPG Key ID: 17FA2D56BAD01661
1 changed files with 20 additions and 2 deletions

View File

@ -19,6 +19,7 @@ import (
"fmt"
"github.com/hunterlong/statping/types"
"github.com/hunterlong/statping/utils"
"github.com/hunterlong/statping/core"
)
// OnSave will trigger a notifier when it has been saved - Notifier interface
@ -38,6 +39,19 @@ func OnFailure(s *types.Service, f *types.Failure) {
if !s.AllowNotifications.Bool {
return
}
// check if User wants to receive every Status Change
if core.CoreApp.UpdateNotify.Bool {
// send only if User hasn't been already notified about the Downtime
if !s.UserNotified {
s.UserNotified = true
goto sendMessages
} else {
return
}
}
sendMessages:
for _, comm := range AllCommunications {
if isType(comm, new(BasicEvents)) && isEnabled(comm) && inLimits(comm) {
notifier := comm.(Notifier).Select()
@ -45,7 +59,6 @@ func OnFailure(s *types.Service, f *types.Failure) {
comm.(BasicEvents).OnFailure(s, f)
}
}
}
// OnSuccess will be triggered when a service is successful - BasicEvents interface
@ -53,6 +66,12 @@ func OnSuccess(s *types.Service) {
if !s.AllowNotifications.Bool {
return
}
// check if User wants to receive every Status Change
if core.CoreApp.UpdateNotify.Bool && s.UserNotified {
s.UserNotified = false
}
for _, comm := range AllCommunications {
if isType(comm, new(BasicEvents)) && isEnabled(comm) && inLimits(comm) {
notifier := comm.(Notifier).Select()
@ -60,7 +79,6 @@ func OnSuccess(s *types.Service) {
comm.(BasicEvents).OnSuccess(s)
}
}
}
// OnNewService is triggered when a new service is created - ServiceEvents interface