Start working on notifications when service is back to healthy (#9)
This commit is contained in:
@ -13,6 +13,9 @@ type Alert struct {
|
||||
|
||||
// Description of the alert. Will be included in the alert sent.
|
||||
Description string `yaml:"description"`
|
||||
|
||||
// SendOnResolved defines whether to send a second notification when the issue has been resolved
|
||||
SendOnResolved bool `yaml:"send-on-resolved"`
|
||||
}
|
||||
|
||||
type AlertType string
|
||||
|
@ -21,6 +21,10 @@ type TwilioAlertProvider struct {
|
||||
To string `yaml:"to"`
|
||||
}
|
||||
|
||||
func (provider *TwilioAlertProvider) IsValid() bool {
|
||||
return len(provider.Token) > 0 && len(provider.SID) > 0 && len(provider.From) > 0 && len(provider.To) > 0
|
||||
}
|
||||
|
||||
type CustomAlertProvider struct {
|
||||
Url string `yaml:"url"`
|
||||
Method string `yaml:"method,omitempty"`
|
||||
@ -28,6 +32,10 @@ type CustomAlertProvider struct {
|
||||
Headers map[string]string `yaml:"headers,omitempty"`
|
||||
}
|
||||
|
||||
func (provider *CustomAlertProvider) IsValid() bool {
|
||||
return len(provider.Url) > 0
|
||||
}
|
||||
|
||||
func (provider *CustomAlertProvider) buildRequest(serviceName, alertDescription string) *http.Request {
|
||||
body := provider.Body
|
||||
url := provider.Url
|
||||
|
@ -46,7 +46,7 @@ type Service struct {
|
||||
// Alerts is the alerting configuration for the service in case of failure
|
||||
Alerts []*Alert `yaml:"alerts"`
|
||||
|
||||
numberOfFailuresInARow int
|
||||
NumberOfFailuresInARow int
|
||||
}
|
||||
|
||||
func (service *Service) Validate() {
|
||||
@ -94,22 +94,16 @@ func (service *Service) EvaluateConditions() *Result {
|
||||
}
|
||||
}
|
||||
result.Timestamp = time.Now()
|
||||
if result.Success {
|
||||
service.numberOfFailuresInARow = 0
|
||||
// TODO: Send notification that alert has been resolved?
|
||||
} else {
|
||||
service.numberOfFailuresInARow++
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (service *Service) GetAlertsTriggered() []Alert {
|
||||
var alerts []Alert
|
||||
if service.numberOfFailuresInARow == 0 {
|
||||
if service.NumberOfFailuresInARow == 0 {
|
||||
return alerts
|
||||
}
|
||||
for _, alert := range service.Alerts {
|
||||
if alert.Enabled && alert.Threshold == service.numberOfFailuresInARow {
|
||||
if alert.Enabled && alert.Threshold == service.NumberOfFailuresInARow {
|
||||
alerts = append(alerts, *alert)
|
||||
continue
|
||||
}
|
||||
|
Reference in New Issue
Block a user