2020-09-25 01:54:15 +02:00
|
|
|
package provider
|
|
|
|
|
2020-09-26 20:23:43 +02:00
|
|
|
import (
|
2021-10-08 03:28:04 +02:00
|
|
|
"github.com/TwiN/gatus/v3/alerting/alert"
|
|
|
|
"github.com/TwiN/gatus/v3/alerting/provider/custom"
|
|
|
|
"github.com/TwiN/gatus/v3/alerting/provider/discord"
|
|
|
|
"github.com/TwiN/gatus/v3/alerting/provider/mattermost"
|
|
|
|
"github.com/TwiN/gatus/v3/alerting/provider/messagebird"
|
|
|
|
"github.com/TwiN/gatus/v3/alerting/provider/pagerduty"
|
|
|
|
"github.com/TwiN/gatus/v3/alerting/provider/slack"
|
|
|
|
"github.com/TwiN/gatus/v3/alerting/provider/teams"
|
|
|
|
"github.com/TwiN/gatus/v3/alerting/provider/telegram"
|
|
|
|
"github.com/TwiN/gatus/v3/alerting/provider/twilio"
|
|
|
|
"github.com/TwiN/gatus/v3/core"
|
2020-09-26 20:23:43 +02:00
|
|
|
)
|
|
|
|
|
2020-09-26 21:15:50 +02:00
|
|
|
// AlertProvider is the interface that each providers should implement
|
2020-09-25 01:54:15 +02:00
|
|
|
type AlertProvider interface {
|
2020-09-26 21:15:50 +02:00
|
|
|
// IsValid returns whether the provider's configuration is valid
|
2020-09-25 01:54:15 +02:00
|
|
|
IsValid() bool
|
2020-09-26 21:15:50 +02:00
|
|
|
|
|
|
|
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
2021-05-19 04:29:15 +02:00
|
|
|
ToCustomAlertProvider(service *core.Service, alert *alert.Alert, result *core.Result, resolved bool) *custom.AlertProvider
|
2021-05-16 03:31:32 +02:00
|
|
|
|
|
|
|
// GetDefaultAlert returns the provider's default alert configuration
|
2021-05-19 04:29:15 +02:00
|
|
|
GetDefaultAlert() *alert.Alert
|
2021-05-16 03:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParseWithDefaultAlert parses a service alert by using the provider's default alert as a baseline
|
2021-05-19 04:29:15 +02:00
|
|
|
func ParseWithDefaultAlert(providerDefaultAlert, serviceAlert *alert.Alert) {
|
2021-05-16 03:31:32 +02:00
|
|
|
if providerDefaultAlert == nil || serviceAlert == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if serviceAlert.Enabled == nil {
|
|
|
|
serviceAlert.Enabled = providerDefaultAlert.Enabled
|
|
|
|
}
|
|
|
|
if serviceAlert.SendOnResolved == nil {
|
|
|
|
serviceAlert.SendOnResolved = providerDefaultAlert.SendOnResolved
|
|
|
|
}
|
|
|
|
if serviceAlert.Description == nil {
|
|
|
|
serviceAlert.Description = providerDefaultAlert.Description
|
|
|
|
}
|
|
|
|
if serviceAlert.FailureThreshold == 0 {
|
|
|
|
serviceAlert.FailureThreshold = providerDefaultAlert.FailureThreshold
|
|
|
|
}
|
|
|
|
if serviceAlert.SuccessThreshold == 0 {
|
|
|
|
serviceAlert.SuccessThreshold = providerDefaultAlert.SuccessThreshold
|
|
|
|
}
|
2020-09-25 01:54:15 +02:00
|
|
|
}
|
2020-11-03 04:43:55 +01:00
|
|
|
|
|
|
|
var (
|
|
|
|
// Validate interface implementation on compile
|
|
|
|
_ AlertProvider = (*custom.AlertProvider)(nil)
|
2021-03-05 03:26:17 +01:00
|
|
|
_ AlertProvider = (*discord.AlertProvider)(nil)
|
2020-11-14 15:55:37 +01:00
|
|
|
_ AlertProvider = (*mattermost.AlertProvider)(nil)
|
2020-11-23 22:20:06 +01:00
|
|
|
_ AlertProvider = (*messagebird.AlertProvider)(nil)
|
2020-11-03 04:43:55 +01:00
|
|
|
_ AlertProvider = (*pagerduty.AlertProvider)(nil)
|
2021-03-05 03:26:17 +01:00
|
|
|
_ AlertProvider = (*slack.AlertProvider)(nil)
|
2021-07-30 01:54:40 +02:00
|
|
|
_ AlertProvider = (*teams.AlertProvider)(nil)
|
2021-03-31 01:38:34 +02:00
|
|
|
_ AlertProvider = (*telegram.AlertProvider)(nil)
|
2021-03-05 03:26:17 +01:00
|
|
|
_ AlertProvider = (*twilio.AlertProvider)(nil)
|
2020-11-03 04:43:55 +01:00
|
|
|
)
|