Skip to content

Commit

Permalink
*: add Telegram support in v1beta1
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
  • Loading branch information
simonpasquier committed May 25, 2022
1 parent 008561c commit 8287fa7
Show file tree
Hide file tree
Showing 6 changed files with 1,995 additions and 708 deletions.

Large diffs are not rendered by default.

403 changes: 403 additions & 0 deletions jsonnet/prometheus-operator/alertmanagerconfigs-v1beta1-crd.libsonnet

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions pkg/apis/monitoring/v1beta1/alertmanager_config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ type Receiver struct {
PushoverConfigs []PushoverConfig `json:"pushoverConfigs,omitempty"`
// List of SNS configurations
SNSConfigs []SNSConfig `json:"snsConfigs,omitempty"`
// List of Telegram configurations.
TelegramConfigs []TelegramConfig `json:"telegramConfigs,omitempty"`
}

// PagerDutyConfig configures notifications via PagerDuty.
Expand Down Expand Up @@ -769,6 +771,37 @@ type SNSConfig struct {
HTTPConfig *HTTPConfig `json:"httpConfig,omitempty"`
}

// TelegramConfig configures notifications via Telegram.
// See https://prometheus.io/docs/alerting/latest/configuration/#telegram_config
type TelegramConfig struct {
// Whether to notify about resolved alerts.
// +optional
SendResolved *bool `json:"sendResolved,omitempty"`
// The Telegram API URL i.e. https://api.telegram.org.
// If not specified, default API URL will be used.
// +optional
APIURL string `json:"apiURL,omitempty"`
// Telegram bot token
// The secret needs to be in the same namespace as the AlertmanagerConfig
// object and accessible by the Prometheus Operator.
BotToken *SecretKeySelector `json:"botToken,omitempty"`
// The Telegram chat ID.
ChatID int64 `json:"chatID,omitempty"`
// Message template
// +optional
Message string `json:"message,omitempty"`
// Disable telegram notifications
// +optional
DisableNotifications *bool `json:"disableNotifications,omitempty"`
// Parse mode for telegram message
//+kubebuilder:validation:Enum=MarkdownV2;Markdown;HTML
// +optional
ParseMode string `json:"parseMode,omitempty"`
// HTTP client configuration.
// +optional
HTTPConfig *HTTPConfig `json:"httpConfig,omitempty"`
}

// InhibitRule defines an inhibition rule that allows to mute alerts when other
// alerts are already firing.
// See https://prometheus.io/docs/alerting/latest/configuration/#inhibit_rule
Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/monitoring/v1beta1/conversion_from.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,19 @@ func convertSNSConfigFrom(in v1alpha1.SNSConfig) SNSConfig {
}
}

func convertTelegramConfigFrom(in v1alpha1.TelegramConfig) TelegramConfig {
return TelegramConfig{
SendResolved: in.SendResolved,
APIURL: in.APIURL,
BotToken: convertSecretKeySelectorFrom(in.BotToken),
ChatID: in.ChatID,
Message: in.Message,
DisableNotifications: in.DisableNotifications,
ParseMode: in.ParseMode,
HTTPConfig: convertHTTPConfigFrom(in.HTTPConfig),
}
}

// ConvertFrom converts from the Hub version (v1alpha1) to this version (v1beta1).
func (dst *AlertmanagerConfig) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*v1alpha1.AlertmanagerConfig)
Expand Down Expand Up @@ -489,6 +502,13 @@ func (dst *AlertmanagerConfig) ConvertFrom(srcRaw conversion.Hub) error {
)
}

for _, in := range in.TelegramConfigs {
out.TelegramConfigs = append(
out.TelegramConfigs,
convertTelegramConfigFrom(in),
)
}

dst.Spec.Receivers = append(dst.Spec.Receivers, out)
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/monitoring/v1beta1/conversion_to.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,19 @@ func convertSNSConfigTo(in SNSConfig) v1alpha1.SNSConfig {
}
}

func convertTelegramConfigTo(in TelegramConfig) v1alpha1.TelegramConfig {
return v1alpha1.TelegramConfig{
SendResolved: in.SendResolved,
APIURL: in.APIURL,
BotToken: convertSecretKeySelectorTo(in.BotToken),
ChatID: in.ChatID,
Message: in.Message,
DisableNotifications: in.DisableNotifications,
ParseMode: in.ParseMode,
HTTPConfig: convertHTTPConfigTo(in.HTTPConfig),
}
}

// ConvertTo converts from this version (v1beta1) to the Hub version (v1alpha1).
func (src *AlertmanagerConfig) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*v1alpha1.AlertmanagerConfig)
Expand Down Expand Up @@ -484,6 +497,13 @@ func (src *AlertmanagerConfig) ConvertTo(dstRaw conversion.Hub) error {
)
}

for _, in := range in.TelegramConfigs {
out.TelegramConfigs = append(
out.TelegramConfigs,
convertTelegramConfigTo(in),
)
}

dst.Spec.Receivers = append(dst.Spec.Receivers, out)
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/apis/monitoring/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8287fa7

Please sign in to comment.