2020-09-19 22:22:12 +02:00
|
|
|
package alerting
|
|
|
|
|
2020-09-19 22:29:08 +02:00
|
|
|
import (
|
2021-10-04 03:53:59 +02:00
|
|
|
"github.com/TwinProduction/gatus/v3/alerting/alert"
|
|
|
|
"github.com/TwinProduction/gatus/v3/alerting/provider"
|
|
|
|
"github.com/TwinProduction/gatus/v3/alerting/provider/custom"
|
|
|
|
"github.com/TwinProduction/gatus/v3/alerting/provider/discord"
|
|
|
|
"github.com/TwinProduction/gatus/v3/alerting/provider/mattermost"
|
|
|
|
"github.com/TwinProduction/gatus/v3/alerting/provider/messagebird"
|
|
|
|
"github.com/TwinProduction/gatus/v3/alerting/provider/pagerduty"
|
|
|
|
"github.com/TwinProduction/gatus/v3/alerting/provider/slack"
|
|
|
|
"github.com/TwinProduction/gatus/v3/alerting/provider/teams"
|
|
|
|
"github.com/TwinProduction/gatus/v3/alerting/provider/telegram"
|
|
|
|
"github.com/TwinProduction/gatus/v3/alerting/provider/twilio"
|
2020-09-19 22:29:08 +02:00
|
|
|
)
|
|
|
|
|
2020-10-23 22:12:53 +02:00
|
|
|
// Config is the configuration for alerting providers
|
2020-09-19 22:22:12 +02:00
|
|
|
type Config struct {
|
2021-03-05 03:26:17 +01:00
|
|
|
// Custom is the configuration for the custom alerting provider
|
|
|
|
Custom *custom.AlertProvider `yaml:"custom"`
|
|
|
|
|
|
|
|
// Discord is the configuration for the discord alerting provider
|
|
|
|
Discord *discord.AlertProvider `yaml:"discord"`
|
2020-10-23 22:12:53 +02:00
|
|
|
|
2020-11-14 15:55:37 +01:00
|
|
|
// Mattermost is the configuration for the mattermost alerting provider
|
|
|
|
Mattermost *mattermost.AlertProvider `yaml:"mattermost"`
|
|
|
|
|
2020-11-23 22:20:06 +01:00
|
|
|
// Messagebird is the configuration for the messagebird alerting provider
|
|
|
|
Messagebird *messagebird.AlertProvider `yaml:"messagebird"`
|
|
|
|
|
2021-03-05 03:26:17 +01:00
|
|
|
// PagerDuty is the configuration for the pagerduty alerting provider
|
2020-09-19 22:29:08 +02:00
|
|
|
PagerDuty *pagerduty.AlertProvider `yaml:"pagerduty"`
|
2020-10-23 22:12:53 +02:00
|
|
|
|
2021-03-05 03:26:17 +01:00
|
|
|
// Slack is the configuration for the slack alerting provider
|
|
|
|
Slack *slack.AlertProvider `yaml:"slack"`
|
|
|
|
|
2021-07-30 01:54:40 +02:00
|
|
|
// Teams is the configuration for the teams alerting provider
|
|
|
|
Teams *teams.AlertProvider `yaml:"teams"`
|
|
|
|
|
2021-03-31 01:38:34 +02:00
|
|
|
// Telegram is the configuration for the telegram alerting provider
|
|
|
|
Telegram *telegram.AlertProvider `yaml:"telegram"`
|
|
|
|
|
2020-10-23 22:12:53 +02:00
|
|
|
// Twilio is the configuration for the twilio alerting provider
|
|
|
|
Twilio *twilio.AlertProvider `yaml:"twilio"`
|
2020-09-19 22:22:12 +02:00
|
|
|
}
|
2021-05-19 04:29:15 +02: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
|
|
|
|
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
|
|
|
|
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-30 01:54:40 +02: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 04:29:15 +02: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
|
|
|
|
}
|