2020-09-25 01:54:15 +02:00
|
|
|
package provider
|
|
|
|
|
2020-09-26 20:23:43 +02:00
|
|
|
import (
|
2022-12-06 07:41:09 +01:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/alert"
|
2023-10-26 05:52:43 +02:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/awsses"
|
2022-12-06 07:41:09 +01:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/custom"
|
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/discord"
|
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/email"
|
2024-08-21 23:51:45 +02:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/gitea"
|
2022-12-16 05:32:04 +01:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/github"
|
2023-05-31 03:57:15 +02:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/gitlab"
|
2022-12-06 07:41:09 +01:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/googlechat"
|
2024-03-28 23:36:22 +01:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/jetbrainsspace"
|
2022-12-06 07:41:09 +01:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/matrix"
|
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/mattermost"
|
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/messagebird"
|
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/ntfy"
|
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/opsgenie"
|
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/pagerduty"
|
2023-01-29 23:32:16 +01:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/pushover"
|
2022-12-06 07:41:09 +01:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/slack"
|
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/teams"
|
2024-10-15 23:25:02 +02:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/teamsworkflows"
|
2022-12-06 07:41:09 +01:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/telegram"
|
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/twilio"
|
2024-09-04 05:21:08 +02:00
|
|
|
"github.com/TwiN/gatus/v5/alerting/provider/zulip"
|
2024-05-10 04:56:16 +02:00
|
|
|
"github.com/TwiN/gatus/v5/config/endpoint"
|
2020-09-26 20:23:43 +02:00
|
|
|
)
|
|
|
|
|
2024-04-11 02:46:17 +02:00
|
|
|
// AlertProvider is the interface that each provider should implement
|
2020-09-25 01:54:15 +02:00
|
|
|
type AlertProvider interface {
|
2024-12-17 02:32:13 +01:00
|
|
|
// Validate the provider's configuration
|
|
|
|
Validate() error
|
|
|
|
|
|
|
|
// Send an alert using the provider
|
|
|
|
Send(ep *endpoint.Endpoint, alert *alert.Alert, result *endpoint.Result, resolved bool) error
|
2020-09-26 21:15:50 +02:00
|
|
|
|
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-12-03 03:05:17 +01:00
|
|
|
|
2024-12-17 02:32:13 +01:00
|
|
|
// ValidateOverrides validates the alert's provider override and, if present, the group override
|
|
|
|
ValidateOverrides(group string, alert *alert.Alert) error
|
2021-05-16 03:31:32 +02:00
|
|
|
}
|
|
|
|
|
2024-12-17 02:32:13 +01:00
|
|
|
type Config[T any] interface {
|
|
|
|
Validate() error
|
|
|
|
Merge(override *T)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MergeProviderDefaultAlertIntoEndpointAlert parses an Endpoint alert by using the provider's default alert as a baseline
|
|
|
|
func MergeProviderDefaultAlertIntoEndpointAlert(providerDefaultAlert, endpointAlert *alert.Alert) {
|
2021-10-23 22:47:12 +02:00
|
|
|
if providerDefaultAlert == nil || endpointAlert == nil {
|
2021-05-16 03:31:32 +02:00
|
|
|
return
|
|
|
|
}
|
2021-10-23 22:47:12 +02:00
|
|
|
if endpointAlert.Enabled == nil {
|
|
|
|
endpointAlert.Enabled = providerDefaultAlert.Enabled
|
2021-05-16 03:31:32 +02:00
|
|
|
}
|
2021-10-23 22:47:12 +02:00
|
|
|
if endpointAlert.SendOnResolved == nil {
|
|
|
|
endpointAlert.SendOnResolved = providerDefaultAlert.SendOnResolved
|
2021-05-16 03:31:32 +02:00
|
|
|
}
|
2021-10-23 22:47:12 +02:00
|
|
|
if endpointAlert.Description == nil {
|
|
|
|
endpointAlert.Description = providerDefaultAlert.Description
|
2021-05-16 03:31:32 +02:00
|
|
|
}
|
2021-10-23 22:47:12 +02:00
|
|
|
if endpointAlert.FailureThreshold == 0 {
|
|
|
|
endpointAlert.FailureThreshold = providerDefaultAlert.FailureThreshold
|
2021-05-16 03:31:32 +02:00
|
|
|
}
|
2021-10-23 22:47:12 +02:00
|
|
|
if endpointAlert.SuccessThreshold == 0 {
|
|
|
|
endpointAlert.SuccessThreshold = providerDefaultAlert.SuccessThreshold
|
2021-05-16 03:31:32 +02:00
|
|
|
}
|
2020-09-25 01:54:15 +02:00
|
|
|
}
|
2020-11-03 04:43:55 +01:00
|
|
|
|
|
|
|
var (
|
2024-12-17 02:32:13 +01:00
|
|
|
// Validate provider interface implementation on compile
|
2023-10-26 05:52:43 +02:00
|
|
|
_ AlertProvider = (*awsses.AlertProvider)(nil)
|
2020-11-03 04:43:55 +01:00
|
|
|
_ AlertProvider = (*custom.AlertProvider)(nil)
|
2021-03-05 03:26:17 +01:00
|
|
|
_ AlertProvider = (*discord.AlertProvider)(nil)
|
2021-12-03 03:05:17 +01:00
|
|
|
_ AlertProvider = (*email.AlertProvider)(nil)
|
2024-12-17 02:32:13 +01:00
|
|
|
_ AlertProvider = (*gitea.AlertProvider)(nil)
|
2022-12-16 05:32:04 +01:00
|
|
|
_ AlertProvider = (*github.AlertProvider)(nil)
|
2023-05-31 03:57:15 +02:00
|
|
|
_ AlertProvider = (*gitlab.AlertProvider)(nil)
|
2022-01-15 03:00:00 +01:00
|
|
|
_ AlertProvider = (*googlechat.AlertProvider)(nil)
|
2024-03-28 23:36:22 +01:00
|
|
|
_ AlertProvider = (*jetbrainsspace.AlertProvider)(nil)
|
2022-07-19 19:05:27 +02:00
|
|
|
_ AlertProvider = (*matrix.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)
|
2022-10-05 05:26:34 +02:00
|
|
|
_ AlertProvider = (*ntfy.AlertProvider)(nil)
|
2022-06-08 01:43:23 +02:00
|
|
|
_ AlertProvider = (*opsgenie.AlertProvider)(nil)
|
2020-11-03 04:43:55 +01:00
|
|
|
_ AlertProvider = (*pagerduty.AlertProvider)(nil)
|
2023-01-29 23:32:16 +01:00
|
|
|
_ AlertProvider = (*pushover.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)
|
2024-10-15 23:25:02 +02:00
|
|
|
_ AlertProvider = (*teamsworkflows.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)
|
2024-09-04 05:21:08 +02:00
|
|
|
_ AlertProvider = (*zulip.AlertProvider)(nil)
|
2024-12-17 02:32:13 +01:00
|
|
|
|
|
|
|
// Validate config interface implementation on compile
|
|
|
|
_ Config[awsses.Config] = (*awsses.Config)(nil)
|
|
|
|
_ Config[custom.Config] = (*custom.Config)(nil)
|
|
|
|
_ Config[discord.Config] = (*discord.Config)(nil)
|
|
|
|
_ Config[email.Config] = (*email.Config)(nil)
|
|
|
|
_ Config[gitea.Config] = (*gitea.Config)(nil)
|
|
|
|
_ Config[github.Config] = (*github.Config)(nil)
|
|
|
|
_ Config[gitlab.Config] = (*gitlab.Config)(nil)
|
|
|
|
_ Config[googlechat.Config] = (*googlechat.Config)(nil)
|
|
|
|
_ Config[jetbrainsspace.Config] = (*jetbrainsspace.Config)(nil)
|
|
|
|
_ Config[matrix.Config] = (*matrix.Config)(nil)
|
|
|
|
_ Config[mattermost.Config] = (*mattermost.Config)(nil)
|
|
|
|
_ Config[messagebird.Config] = (*messagebird.Config)(nil)
|
|
|
|
_ Config[ntfy.Config] = (*ntfy.Config)(nil)
|
|
|
|
_ Config[opsgenie.Config] = (*opsgenie.Config)(nil)
|
|
|
|
_ Config[pagerduty.Config] = (*pagerduty.Config)(nil)
|
|
|
|
_ Config[pushover.Config] = (*pushover.Config)(nil)
|
|
|
|
_ Config[slack.Config] = (*slack.Config)(nil)
|
|
|
|
_ Config[teams.Config] = (*teams.Config)(nil)
|
|
|
|
_ Config[teamsworkflows.Config] = (*teamsworkflows.Config)(nil)
|
|
|
|
_ Config[telegram.Config] = (*telegram.Config)(nil)
|
|
|
|
_ Config[twilio.Config] = (*twilio.Config)(nil)
|
|
|
|
_ Config[zulip.Config] = (*zulip.Config)(nil)
|
2020-11-03 04:43:55 +01:00
|
|
|
)
|