2020-09-19 20:22:12 +00:00
|
|
|
package alerting
|
|
|
|
|
2020-09-19 20:29:08 +00:00
|
|
|
import (
|
2022-06-21 01:25:14 +00:00
|
|
|
"github.com/TwiN/gatus/v4/alerting/alert"
|
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider"
|
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/custom"
|
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/discord"
|
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/email"
|
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/googlechat"
|
2022-07-16 04:43:48 +00:00
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/matrix"
|
2022-06-21 01:25:14 +00:00
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/mattermost"
|
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/messagebird"
|
2022-10-05 03:26:34 +00:00
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/ntfy"
|
2022-06-21 01:25:14 +00:00
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/opsgenie"
|
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/pagerduty"
|
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/slack"
|
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/teams"
|
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/telegram"
|
|
|
|
"github.com/TwiN/gatus/v4/alerting/provider/twilio"
|
2020-09-19 20:29:08 +00:00
|
|
|
)
|
|
|
|
|
2020-10-23 20:12:53 +00:00
|
|
|
// Config is the configuration for alerting providers
|
2020-09-19 20:22:12 +00:00
|
|
|
type Config struct {
|
2021-03-05 02:26:17 +00:00
|
|
|
// Custom is the configuration for the custom alerting provider
|
2021-12-03 02:05:17 +00:00
|
|
|
Custom *custom.AlertProvider `yaml:"custom,omitempty"`
|
2021-03-05 02:26:17 +00:00
|
|
|
|
2022-01-15 02:00:00 +00:00
|
|
|
// googlechat is the configuration for the Google chat alerting provider
|
|
|
|
GoogleChat *googlechat.AlertProvider `yaml:"googlechat,omitempty"`
|
|
|
|
|
2021-03-05 02:26:17 +00:00
|
|
|
// Discord is the configuration for the discord alerting provider
|
2021-12-03 02:05:17 +00:00
|
|
|
Discord *discord.AlertProvider `yaml:"discord,omitempty"`
|
|
|
|
|
|
|
|
// Email is the configuration for the email alerting provider
|
|
|
|
Email *email.AlertProvider `yaml:"email,omitempty"`
|
2020-10-23 20:12:53 +00:00
|
|
|
|
2022-07-19 17:48:12 +00:00
|
|
|
// Matrix is the configuration for the matrix alerting provider
|
|
|
|
Matrix *matrix.AlertProvider `yaml:"matrix,omitempty"`
|
|
|
|
|
2020-11-14 14:55:37 +00:00
|
|
|
// Mattermost is the configuration for the mattermost alerting provider
|
2021-12-03 02:05:17 +00:00
|
|
|
Mattermost *mattermost.AlertProvider `yaml:"mattermost,omitempty"`
|
2020-11-14 14:55:37 +00:00
|
|
|
|
2020-11-23 21:20:06 +00:00
|
|
|
// Messagebird is the configuration for the messagebird alerting provider
|
2021-12-03 02:05:17 +00:00
|
|
|
Messagebird *messagebird.AlertProvider `yaml:"messagebird,omitempty"`
|
2020-11-23 21:20:06 +00:00
|
|
|
|
2022-10-05 03:26:34 +00:00
|
|
|
// Ntfy is the configuration for the ntfy alerting provider
|
|
|
|
Ntfy *ntfy.AlertProvider `yaml:"ntfy,omitempty"`
|
|
|
|
|
2022-10-05 03:22:41 +00:00
|
|
|
// Opsgenie is the configuration for the opsgenie alerting provider
|
|
|
|
Opsgenie *opsgenie.AlertProvider `yaml:"opsgenie,omitempty"`
|
|
|
|
|
2021-03-05 02:26:17 +00:00
|
|
|
// PagerDuty is the configuration for the pagerduty alerting provider
|
2021-12-03 02:05:17 +00:00
|
|
|
PagerDuty *pagerduty.AlertProvider `yaml:"pagerduty,omitempty"`
|
2020-10-23 20:12:53 +00:00
|
|
|
|
2021-03-05 02:26:17 +00:00
|
|
|
// Slack is the configuration for the slack alerting provider
|
2021-12-03 02:05:17 +00:00
|
|
|
Slack *slack.AlertProvider `yaml:"slack,omitempty"`
|
2021-03-05 02:26:17 +00:00
|
|
|
|
2021-07-29 23:54:40 +00:00
|
|
|
// Teams is the configuration for the teams alerting provider
|
2021-12-03 02:05:17 +00:00
|
|
|
Teams *teams.AlertProvider `yaml:"teams,omitempty"`
|
2021-07-29 23:54:40 +00:00
|
|
|
|
2021-03-30 23:38:34 +00:00
|
|
|
// Telegram is the configuration for the telegram alerting provider
|
2021-12-03 02:05:17 +00:00
|
|
|
Telegram *telegram.AlertProvider `yaml:"telegram,omitempty"`
|
2021-03-30 23:38:34 +00:00
|
|
|
|
2020-10-23 20:12:53 +00:00
|
|
|
// Twilio is the configuration for the twilio alerting provider
|
2021-12-03 02:05:17 +00:00
|
|
|
Twilio *twilio.AlertProvider `yaml:"twilio,omitempty"`
|
2020-09-19 20:22:12 +00:00
|
|
|
}
|
2021-05-19 02:29:15 +00:00
|
|
|
|
|
|
|
// GetAlertingProviderByAlertType returns an provider.AlertProvider by its corresponding alert.Type
|
|
|
|
func (config Config) GetAlertingProviderByAlertType(alertType alert.Type) provider.AlertProvider {
|
|
|
|
switch alertType {
|
|
|
|
case alert.TypeCustom:
|
|
|
|
if config.Custom == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Custom
|
|
|
|
case alert.TypeDiscord:
|
|
|
|
if config.Discord == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Discord
|
2021-12-03 02:05:17 +00:00
|
|
|
case alert.TypeEmail:
|
|
|
|
if config.Email == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Email
|
2022-06-12 18:18:18 +00:00
|
|
|
case alert.TypeGoogleChat:
|
|
|
|
if config.GoogleChat == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.GoogleChat
|
2022-07-19 17:05:27 +00:00
|
|
|
case alert.TypeMatrix:
|
|
|
|
if config.Matrix == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Matrix
|
2021-05-19 02:29:15 +00:00
|
|
|
case alert.TypeMattermost:
|
|
|
|
if config.Mattermost == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Mattermost
|
|
|
|
case alert.TypeMessagebird:
|
|
|
|
if config.Messagebird == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Messagebird
|
2022-10-05 03:26:34 +00:00
|
|
|
case alert.TypeNtfy:
|
|
|
|
if config.Ntfy == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Ntfy
|
2021-12-10 01:32:38 +00:00
|
|
|
case alert.TypeOpsgenie:
|
|
|
|
if config.Opsgenie == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Opsgenie
|
2021-05-19 02:29:15 +00:00
|
|
|
case alert.TypePagerDuty:
|
|
|
|
if config.PagerDuty == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.PagerDuty
|
|
|
|
case alert.TypeSlack:
|
|
|
|
if config.Slack == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Slack
|
2021-07-29 23:54:40 +00:00
|
|
|
case alert.TypeTeams:
|
|
|
|
if config.Teams == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Teams
|
2021-05-19 02:29:15 +00:00
|
|
|
case alert.TypeTelegram:
|
|
|
|
if config.Telegram == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Telegram
|
|
|
|
case alert.TypeTwilio:
|
|
|
|
if config.Twilio == nil {
|
|
|
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return config.Twilio
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|