Close #91: Implement default provider alert

This commit is contained in:
TwinProduction
2021-05-15 21:31:32 -04:00
parent c7d554efa5
commit a85c5d5486
18 changed files with 765 additions and 42 deletions

View File

@ -11,6 +11,9 @@ import (
// AlertProvider is the configuration necessary for sending an alert using PagerDuty
type AlertProvider struct {
IntegrationKey string `yaml:"integration-key"`
// DefaultAlert is the default alert configuration to use for services with an alert of the appropriate type
DefaultAlert *core.Alert `yaml:"default-alert"`
}
// IsValid returns whether the provider's configuration is valid
@ -24,11 +27,11 @@ func (provider *AlertProvider) IsValid() bool {
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *core.Alert, _ *core.Result, resolved bool) *custom.AlertProvider {
var message, eventAction, resolveKey string
if resolved {
message = fmt.Sprintf("RESOLVED: %s - %s", service.Name, alert.Description)
message = fmt.Sprintf("RESOLVED: %s - %s", service.Name, alert.GetDescription())
eventAction = "resolve"
resolveKey = alert.ResolveKey
} else {
message = fmt.Sprintf("TRIGGERED: %s - %s", service.Name, alert.Description)
message = fmt.Sprintf("TRIGGERED: %s - %s", service.Name, alert.GetDescription())
eventAction = "trigger"
resolveKey = ""
}
@ -50,3 +53,8 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
},
}
}
// GetDefaultAlert returns the provider's default alert configuration
func (provider AlertProvider) GetDefaultAlert() *core.Alert {
return provider.DefaultAlert
}