mirror of https://github.com/statping/statping
Add implementation for `UpdateNotified` Check
parent
d062839b52
commit
2a3c682013
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue