From e69340bd14734fcb64c0fdbb4f203e93195ea024 Mon Sep 17 00:00:00 2001 From: Christoph Maser Date: Thu, 2 Nov 2023 16:30:15 +0100 Subject: [PATCH] feat: add rocketchat notifier Signed-off-by: Christoph Maser Co-authored-by: George Robinson --- config/config.go | 142 +++++---- config/config_test.go | 111 +++++++- config/notifiers.go | 79 +++++ config/receiver/receiver.go | 4 + ...nf.rocketchat-both-token-and-tokenfile.yml | 20 ++ ...ocketchat-both-tokenid-and-tokenidfile.yml | 20 ++ .../conf.rocketchat-default-token-file.yml | 22 ++ .../conf.rocketchat-default-token.yml | 22 ++ config/testdata/conf.rocketchat-no-token.yml | 19 ++ docs/configuration.md | 69 ++++- notify/notify.go | 1 + notify/rocketchat/rocketchat.go | 269 ++++++++++++++++++ notify/rocketchat/rocketchat_test.go | 66 +++++ template/default.tmpl | 7 + 14 files changed, 789 insertions(+), 62 deletions(-) create mode 100644 config/testdata/conf.rocketchat-both-token-and-tokenfile.yml create mode 100644 config/testdata/conf.rocketchat-both-tokenid-and-tokenidfile.yml create mode 100644 config/testdata/conf.rocketchat-default-token-file.yml create mode 100644 config/testdata/conf.rocketchat-default-token.yml create mode 100644 config/testdata/conf.rocketchat-no-token.yml create mode 100644 notify/rocketchat/rocketchat.go create mode 100644 notify/rocketchat/rocketchat_test.go diff --git a/config/config.go b/config/config.go index 5b8c7074e3..890592ca90 100644 --- a/config/config.go +++ b/config/config.go @@ -269,6 +269,9 @@ func resolveFilepaths(baseDir string, cfg *Config) { for _, cfg := range receiver.JiraConfigs { cfg.HTTPConfig.SetDirectory(baseDir) } + for _, cfg := range receiver.RocketchatConfigs { + cfg.HTTPConfig.SetDirectory(baseDir) + } } } @@ -364,6 +367,14 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { return errors.New("at most one of smtp_auth_password & smtp_auth_password_file must be configured") } + if c.Global.RocketchatToken != nil && len(c.Global.RocketchatTokenFile) > 0 { + return errors.New("at most one of rocketchat_token & rocketchat_token_file must be configured") + } + + if c.Global.RocketchatTokenID != nil && len(c.Global.RocketchatTokenIDFile) > 0 { + return errors.New("at most one of rocketchat_token_id & rocketchat_token_id_file must be configured") + } + names := map[string]struct{}{} for _, rcv := range c.Receivers { @@ -573,6 +584,28 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { jira.APIURL = c.Global.JiraAPIURL } } + for _, rocketchat := range rcv.RocketchatConfigs { + if rocketchat.HTTPConfig == nil { + rocketchat.HTTPConfig = c.Global.HTTPConfig + } + if rocketchat.APIURL == nil { + rocketchat.APIURL = c.Global.RocketchatAPIURL + } + if rocketchat.TokenID == nil && len(rocketchat.TokenIDFile) == 0 { + if c.Global.RocketchatTokenID == nil && len(c.Global.RocketchatTokenIDFile) == 0 { + return errors.New("no global Rocketchat TokenID set either inline or in a file") + } + rocketchat.TokenID = c.Global.RocketchatTokenID + rocketchat.TokenIDFile = c.Global.RocketchatTokenIDFile + } + if rocketchat.Token == nil && len(rocketchat.TokenFile) == 0 { + if c.Global.RocketchatToken == nil && len(c.Global.RocketchatTokenFile) == 0 { + return errors.New("no global Rocketchat Token set either inline or in a file") + } + rocketchat.Token = c.Global.RocketchatToken + rocketchat.TokenFile = c.Global.RocketchatTokenFile + } + } names[rcv.Name] = struct{}{} } @@ -665,17 +698,18 @@ func DefaultGlobalConfig() GlobalConfig { defaultSMTPTLSConfig := commoncfg.TLSConfig{} return GlobalConfig{ - ResolveTimeout: model.Duration(5 * time.Minute), - HTTPConfig: &defaultHTTPConfig, - SMTPHello: "localhost", - SMTPRequireTLS: true, - SMTPTLSConfig: &defaultSMTPTLSConfig, - PagerdutyURL: mustParseURL("https://events.pagerduty.com/v2/enqueue"), - OpsGenieAPIURL: mustParseURL("https://api.opsgenie.com/"), - WeChatAPIURL: mustParseURL("https://qyapi.weixin.qq.com/cgi-bin/"), - VictorOpsAPIURL: mustParseURL("https://alert.victorops.com/integrations/generic/20131114/alert/"), - TelegramAPIUrl: mustParseURL("https://api.telegram.org"), - WebexAPIURL: mustParseURL("https://webexapis.com/v1/messages"), + ResolveTimeout: model.Duration(5 * time.Minute), + HTTPConfig: &defaultHTTPConfig, + SMTPHello: "localhost", + SMTPRequireTLS: true, + SMTPTLSConfig: &defaultSMTPTLSConfig, + PagerdutyURL: mustParseURL("https://events.pagerduty.com/v2/enqueue"), + OpsGenieAPIURL: mustParseURL("https://api.opsgenie.com/"), + WeChatAPIURL: mustParseURL("https://qyapi.weixin.qq.com/cgi-bin/"), + VictorOpsAPIURL: mustParseURL("https://alert.victorops.com/integrations/generic/20131114/alert/"), + TelegramAPIUrl: mustParseURL("https://api.telegram.org"), + WebexAPIURL: mustParseURL("https://webexapis.com/v1/messages"), + RocketchatAPIURL: mustParseURL("https://open.rocket.chat/"), } } @@ -777,31 +811,36 @@ type GlobalConfig struct { HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"` - JiraAPIURL *URL `yaml:"jira_api_url,omitempty" json:"jira_api_url,omitempty"` - SMTPFrom string `yaml:"smtp_from,omitempty" json:"smtp_from,omitempty"` - SMTPHello string `yaml:"smtp_hello,omitempty" json:"smtp_hello,omitempty"` - SMTPSmarthost HostPort `yaml:"smtp_smarthost,omitempty" json:"smtp_smarthost,omitempty"` - SMTPAuthUsername string `yaml:"smtp_auth_username,omitempty" json:"smtp_auth_username,omitempty"` - SMTPAuthPassword Secret `yaml:"smtp_auth_password,omitempty" json:"smtp_auth_password,omitempty"` - SMTPAuthPasswordFile string `yaml:"smtp_auth_password_file,omitempty" json:"smtp_auth_password_file,omitempty"` - SMTPAuthSecret Secret `yaml:"smtp_auth_secret,omitempty" json:"smtp_auth_secret,omitempty"` - SMTPAuthIdentity string `yaml:"smtp_auth_identity,omitempty" json:"smtp_auth_identity,omitempty"` - SMTPRequireTLS bool `yaml:"smtp_require_tls" json:"smtp_require_tls,omitempty"` - SMTPTLSConfig *commoncfg.TLSConfig `yaml:"smtp_tls_config,omitempty" json:"smtp_tls_config,omitempty"` - SlackAPIURL *SecretURL `yaml:"slack_api_url,omitempty" json:"slack_api_url,omitempty"` - SlackAPIURLFile string `yaml:"slack_api_url_file,omitempty" json:"slack_api_url_file,omitempty"` - PagerdutyURL *URL `yaml:"pagerduty_url,omitempty" json:"pagerduty_url,omitempty"` - OpsGenieAPIURL *URL `yaml:"opsgenie_api_url,omitempty" json:"opsgenie_api_url,omitempty"` - OpsGenieAPIKey Secret `yaml:"opsgenie_api_key,omitempty" json:"opsgenie_api_key,omitempty"` - OpsGenieAPIKeyFile string `yaml:"opsgenie_api_key_file,omitempty" json:"opsgenie_api_key_file,omitempty"` - WeChatAPIURL *URL `yaml:"wechat_api_url,omitempty" json:"wechat_api_url,omitempty"` - WeChatAPISecret Secret `yaml:"wechat_api_secret,omitempty" json:"wechat_api_secret,omitempty"` - WeChatAPICorpID string `yaml:"wechat_api_corp_id,omitempty" json:"wechat_api_corp_id,omitempty"` - VictorOpsAPIURL *URL `yaml:"victorops_api_url,omitempty" json:"victorops_api_url,omitempty"` - VictorOpsAPIKey Secret `yaml:"victorops_api_key,omitempty" json:"victorops_api_key,omitempty"` - VictorOpsAPIKeyFile string `yaml:"victorops_api_key_file,omitempty" json:"victorops_api_key_file,omitempty"` - TelegramAPIUrl *URL `yaml:"telegram_api_url,omitempty" json:"telegram_api_url,omitempty"` - WebexAPIURL *URL `yaml:"webex_api_url,omitempty" json:"webex_api_url,omitempty"` + JiraAPIURL *URL `yaml:"jira_api_url,omitempty" json:"jira_api_url,omitempty"` + SMTPFrom string `yaml:"smtp_from,omitempty" json:"smtp_from,omitempty"` + SMTPHello string `yaml:"smtp_hello,omitempty" json:"smtp_hello,omitempty"` + SMTPSmarthost HostPort `yaml:"smtp_smarthost,omitempty" json:"smtp_smarthost,omitempty"` + SMTPAuthUsername string `yaml:"smtp_auth_username,omitempty" json:"smtp_auth_username,omitempty"` + SMTPAuthPassword Secret `yaml:"smtp_auth_password,omitempty" json:"smtp_auth_password,omitempty"` + SMTPAuthPasswordFile string `yaml:"smtp_auth_password_file,omitempty" json:"smtp_auth_password_file,omitempty"` + SMTPAuthSecret Secret `yaml:"smtp_auth_secret,omitempty" json:"smtp_auth_secret,omitempty"` + SMTPAuthIdentity string `yaml:"smtp_auth_identity,omitempty" json:"smtp_auth_identity,omitempty"` + SMTPRequireTLS bool `yaml:"smtp_require_tls" json:"smtp_require_tls,omitempty"` + SMTPTLSConfig *commoncfg.TLSConfig `yaml:"smtp_tls_config,omitempty" json:"smtp_tls_config,omitempty"` + SlackAPIURL *SecretURL `yaml:"slack_api_url,omitempty" json:"slack_api_url,omitempty"` + SlackAPIURLFile string `yaml:"slack_api_url_file,omitempty" json:"slack_api_url_file,omitempty"` + PagerdutyURL *URL `yaml:"pagerduty_url,omitempty" json:"pagerduty_url,omitempty"` + OpsGenieAPIURL *URL `yaml:"opsgenie_api_url,omitempty" json:"opsgenie_api_url,omitempty"` + OpsGenieAPIKey Secret `yaml:"opsgenie_api_key,omitempty" json:"opsgenie_api_key,omitempty"` + OpsGenieAPIKeyFile string `yaml:"opsgenie_api_key_file,omitempty" json:"opsgenie_api_key_file,omitempty"` + WeChatAPIURL *URL `yaml:"wechat_api_url,omitempty" json:"wechat_api_url,omitempty"` + WeChatAPISecret Secret `yaml:"wechat_api_secret,omitempty" json:"wechat_api_secret,omitempty"` + WeChatAPICorpID string `yaml:"wechat_api_corp_id,omitempty" json:"wechat_api_corp_id,omitempty"` + VictorOpsAPIURL *URL `yaml:"victorops_api_url,omitempty" json:"victorops_api_url,omitempty"` + VictorOpsAPIKey Secret `yaml:"victorops_api_key,omitempty" json:"victorops_api_key,omitempty"` + VictorOpsAPIKeyFile string `yaml:"victorops_api_key_file,omitempty" json:"victorops_api_key_file,omitempty"` + TelegramAPIUrl *URL `yaml:"telegram_api_url,omitempty" json:"telegram_api_url,omitempty"` + WebexAPIURL *URL `yaml:"webex_api_url,omitempty" json:"webex_api_url,omitempty"` + RocketchatAPIURL *URL `yaml:"rocketchat_api_url,omitempty" json:"rocketchat_api_url,omitempty"` + RocketchatToken *Secret `yaml:"rocketchat_token,omitempty" json:"rocketchat_token,omitempty"` + RocketchatTokenFile string `yaml:"rocketchat_token_file,omitempty" json:"rocketchat_token_file,omitempty"` + RocketchatTokenID *Secret `yaml:"rocketchat_token_id,omitempty" json:"rocketchat_token_id,omitempty"` + RocketchatTokenIDFile string `yaml:"rocketchat_token_id_file,omitempty" json:"rocketchat_token_id_file,omitempty"` } // UnmarshalYAML implements the yaml.Unmarshaler interface for GlobalConfig. @@ -933,21 +972,22 @@ type Receiver struct { // A unique identifier for this receiver. Name string `yaml:"name" json:"name"` - DiscordConfigs []*DiscordConfig `yaml:"discord_configs,omitempty" json:"discord_configs,omitempty"` - EmailConfigs []*EmailConfig `yaml:"email_configs,omitempty" json:"email_configs,omitempty"` - PagerdutyConfigs []*PagerdutyConfig `yaml:"pagerduty_configs,omitempty" json:"pagerduty_configs,omitempty"` - SlackConfigs []*SlackConfig `yaml:"slack_configs,omitempty" json:"slack_configs,omitempty"` - WebhookConfigs []*WebhookConfig `yaml:"webhook_configs,omitempty" json:"webhook_configs,omitempty"` - OpsGenieConfigs []*OpsGenieConfig `yaml:"opsgenie_configs,omitempty" json:"opsgenie_configs,omitempty"` - WechatConfigs []*WechatConfig `yaml:"wechat_configs,omitempty" json:"wechat_configs,omitempty"` - PushoverConfigs []*PushoverConfig `yaml:"pushover_configs,omitempty" json:"pushover_configs,omitempty"` - VictorOpsConfigs []*VictorOpsConfig `yaml:"victorops_configs,omitempty" json:"victorops_configs,omitempty"` - SNSConfigs []*SNSConfig `yaml:"sns_configs,omitempty" json:"sns_configs,omitempty"` - TelegramConfigs []*TelegramConfig `yaml:"telegram_configs,omitempty" json:"telegram_configs,omitempty"` - WebexConfigs []*WebexConfig `yaml:"webex_configs,omitempty" json:"webex_configs,omitempty"` - MSTeamsConfigs []*MSTeamsConfig `yaml:"msteams_configs,omitempty" json:"msteams_configs,omitempty"` - MSTeamsV2Configs []*MSTeamsV2Config `yaml:"msteamsv2_configs,omitempty" json:"msteamsv2_configs,omitempty"` - JiraConfigs []*JiraConfig `yaml:"jira_configs,omitempty" json:"jira_configs,omitempty"` + DiscordConfigs []*DiscordConfig `yaml:"discord_configs,omitempty" json:"discord_configs,omitempty"` + EmailConfigs []*EmailConfig `yaml:"email_configs,omitempty" json:"email_configs,omitempty"` + PagerdutyConfigs []*PagerdutyConfig `yaml:"pagerduty_configs,omitempty" json:"pagerduty_configs,omitempty"` + SlackConfigs []*SlackConfig `yaml:"slack_configs,omitempty" json:"slack_configs,omitempty"` + WebhookConfigs []*WebhookConfig `yaml:"webhook_configs,omitempty" json:"webhook_configs,omitempty"` + OpsGenieConfigs []*OpsGenieConfig `yaml:"opsgenie_configs,omitempty" json:"opsgenie_configs,omitempty"` + WechatConfigs []*WechatConfig `yaml:"wechat_configs,omitempty" json:"wechat_configs,omitempty"` + PushoverConfigs []*PushoverConfig `yaml:"pushover_configs,omitempty" json:"pushover_configs,omitempty"` + VictorOpsConfigs []*VictorOpsConfig `yaml:"victorops_configs,omitempty" json:"victorops_configs,omitempty"` + SNSConfigs []*SNSConfig `yaml:"sns_configs,omitempty" json:"sns_configs,omitempty"` + TelegramConfigs []*TelegramConfig `yaml:"telegram_configs,omitempty" json:"telegram_configs,omitempty"` + WebexConfigs []*WebexConfig `yaml:"webex_configs,omitempty" json:"webex_configs,omitempty"` + MSTeamsConfigs []*MSTeamsConfig `yaml:"msteams_configs,omitempty" json:"msteams_configs,omitempty"` + MSTeamsV2Configs []*MSTeamsV2Config `yaml:"msteamsv2_configs,omitempty" json:"msteamsv2_configs,omitempty"` + JiraConfigs []*JiraConfig `yaml:"jira_configs,omitempty" json:"jira_configs,omitempty"` + RocketchatConfigs []*RocketchatConfig `yaml:"rocketchat_configs,omitempty" json:"rocketchat_configs,omitempty"` } // UnmarshalYAML implements the yaml.Unmarshaler interface for Receiver. diff --git a/config/config_test.go b/config/config_test.go index fa21bb498a..15edfeed2d 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -872,14 +872,15 @@ func TestEmptyFieldsAndRegex(t *testing.T) { SMTPTLSConfig: &commoncfg.TLSConfig{ InsecureSkipVerify: false, }, - SlackAPIURL: (*SecretURL)(mustParseURL("http://slack.example.com/")), - SMTPRequireTLS: true, - PagerdutyURL: mustParseURL("https://events.pagerduty.com/v2/enqueue"), - OpsGenieAPIURL: mustParseURL("https://api.opsgenie.com/"), - WeChatAPIURL: mustParseURL("https://qyapi.weixin.qq.com/cgi-bin/"), - VictorOpsAPIURL: mustParseURL("https://alert.victorops.com/integrations/generic/20131114/alert/"), - TelegramAPIUrl: mustParseURL("https://api.telegram.org"), - WebexAPIURL: mustParseURL("https://webexapis.com/v1/messages"), + SlackAPIURL: (*SecretURL)(mustParseURL("http://slack.example.com/")), + SMTPRequireTLS: true, + PagerdutyURL: mustParseURL("https://events.pagerduty.com/v2/enqueue"), + OpsGenieAPIURL: mustParseURL("https://api.opsgenie.com/"), + WeChatAPIURL: mustParseURL("https://qyapi.weixin.qq.com/cgi-bin/"), + VictorOpsAPIURL: mustParseURL("https://alert.victorops.com/integrations/generic/20131114/alert/"), + TelegramAPIUrl: mustParseURL("https://api.telegram.org"), + WebexAPIURL: mustParseURL("https://webexapis.com/v1/messages"), + RocketchatAPIURL: mustParseURL("https://open.rocket.chat/"), }, Templates: []string{ @@ -1203,6 +1204,100 @@ func TestInvalidSNSConfig(t *testing.T) { } } +func TestRocketchatDefaultToken(t *testing.T) { + conf, err := LoadFile("testdata/conf.rocketchat-default-token.yml") + if err != nil { + t.Fatalf("Error parsing %s: %s", "testdata/conf.rocketchat-default-token.yml", err) + } + + defaultToken := conf.Global.RocketchatToken + overrideToken := Secret("token456") + if defaultToken != conf.Receivers[0].RocketchatConfigs[0].Token { + t.Fatalf("Invalid rocketchat key: %s\nExpected: %s", string(*conf.Receivers[0].RocketchatConfigs[0].Token), string(*defaultToken)) + } + if overrideToken != *conf.Receivers[1].RocketchatConfigs[0].Token { + t.Errorf("Invalid rocketchat key: %s\nExpected: %s", string(*conf.Receivers[0].RocketchatConfigs[0].Token), string(overrideToken)) + } +} + +func TestRocketchatDefaultTokenID(t *testing.T) { + conf, err := LoadFile("testdata/conf.rocketchat-default-token.yml") + if err != nil { + t.Fatalf("Error parsing %s: %s", "testdata/conf.rocketchat-default-token.yml", err) + } + + defaultTokenID := conf.Global.RocketchatTokenID + overrideTokenID := Secret("id456") + if defaultTokenID != conf.Receivers[0].RocketchatConfigs[0].TokenID { + t.Fatalf("Invalid rocketchat key: %s\nExpected: %s", string(*conf.Receivers[0].RocketchatConfigs[0].TokenID), string(*defaultTokenID)) + } + if overrideTokenID != *conf.Receivers[1].RocketchatConfigs[0].TokenID { + t.Errorf("Invalid rocketchat key: %s\nExpected: %s", string(*conf.Receivers[0].RocketchatConfigs[0].TokenID), string(overrideTokenID)) + } +} + +func TestRocketchatDefaultTokenFile(t *testing.T) { + conf, err := LoadFile("testdata/conf.rocketchat-default-token-file.yml") + if err != nil { + t.Fatalf("Error parsing %s: %s", "testdata/conf.rocketchat-default-token-file.yml", err) + } + + defaultTokenFile := conf.Global.RocketchatTokenFile + overrideTokenFile := "/override_file" + if defaultTokenFile != conf.Receivers[0].RocketchatConfigs[0].TokenFile { + t.Fatalf("Invalid Rocketchat key_file: %s\nExpected: %s", conf.Receivers[0].RocketchatConfigs[0].TokenFile, defaultTokenFile) + } + if overrideTokenFile != conf.Receivers[1].RocketchatConfigs[0].TokenFile { + t.Errorf("Invalid Rocketchat key_file: %s\nExpected: %s", conf.Receivers[0].RocketchatConfigs[0].TokenFile, overrideTokenFile) + } +} + +func TestRocketchatDefaultIDTokenFile(t *testing.T) { + conf, err := LoadFile("testdata/conf.rocketchat-default-token-file.yml") + if err != nil { + t.Fatalf("Error parsing %s: %s", "testdata/conf.rocketchat-default-token-file.yml", err) + } + + defaultTokenIDFile := conf.Global.RocketchatTokenIDFile + overrideTokenIDFile := "/override_file" + if defaultTokenIDFile != conf.Receivers[0].RocketchatConfigs[0].TokenIDFile { + t.Fatalf("Invalid Rocketchat key_file: %s\nExpected: %s", conf.Receivers[0].RocketchatConfigs[0].TokenIDFile, defaultTokenIDFile) + } + if overrideTokenIDFile != conf.Receivers[1].RocketchatConfigs[0].TokenIDFile { + t.Errorf("Invalid Rocketchat key_file: %s\nExpected: %s", conf.Receivers[0].RocketchatConfigs[0].TokenIDFile, overrideTokenIDFile) + } +} + +func TestRocketchatBothTokenAndTokenFile(t *testing.T) { + _, err := LoadFile("testdata/conf.rocketchat-both-token-and-tokenfile.yml") + if err == nil { + t.Fatalf("Expected an error parsing %s: %s", "testdata/conf.rocketchat-both-token-and-tokenfile.yml", err) + } + if err.Error() != "at most one of rocketchat_token & rocketchat_token_file must be configured" { + t.Errorf("Expected: %s\nGot: %s", "at most one of rocketchat_token & rocketchat_token_file must be configured", err.Error()) + } +} + +func TestRocketchatBothTokenIDAndTokenIDFile(t *testing.T) { + _, err := LoadFile("testdata/conf.rocketchat-both-tokenid-and-tokenidfile.yml") + if err == nil { + t.Fatalf("Expected an error parsing %s: %s", "testdata/conf.rocketchat-both-tokenid-and-tokenidfile.yml", err) + } + if err.Error() != "at most one of rocketchat_token_id & rocketchat_token_id_file must be configured" { + t.Errorf("Expected: %s\nGot: %s", "at most one of rocketchat_token_id & rocketchat_token_id_file must be configured", err.Error()) + } +} + +func TestRocketchatNoToken(t *testing.T) { + _, err := LoadFile("testdata/conf.rocketchat-no-token.yml") + if err == nil { + t.Fatalf("Expected an error parsing %s: %s", "testdata/conf.rocketchat-no-token.yml", err) + } + if err.Error() != "no global Rocketchat Token set either inline or in a file" { + t.Errorf("Expected: %s\nGot: %s", "no global Rocketchat Token set either inline or in a file", err.Error()) + } +} + func TestUnmarshalHostPort(t *testing.T) { for _, tc := range []struct { in string diff --git a/config/notifiers.go b/config/notifiers.go index 519e5efb81..4e23fb924b 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -99,6 +99,18 @@ var ( CallbackID: `{{ template "slack.default.callbackid" . }}`, Footer: `{{ template "slack.default.footer" . }}`, } + // DefaultRocketchatConfig defines default values for Rocketchat configurations. + DefaultRocketchatConfig = RocketchatConfig{ + NotifierConfig: NotifierConfig{ + VSendResolved: false, + }, + Color: `{{ if eq .Status "firing" }}red{{ else }}green{{ end }}`, + Emoji: `{{ template "rocketchat.default.emoji" . }}`, + IconURL: `{{ template "rocketchat.default.iconurl" . }}`, + Text: `{{ template "rocketchat.default.text" . }}`, + Title: `{{ template "rocketchat.default.title" . }}`, + TitleLink: `{{ template "rocketchat.default.titlelink" . }}`, + } // DefaultOpsGenieConfig defines default values for OpsGenie configurations. DefaultOpsGenieConfig = OpsGenieConfig{ @@ -907,6 +919,73 @@ func (c *JiraConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { if c.IssueType == "" { return errors.New("missing issue_type in jira_config") } + return nil +} +type RocketchatAttachmentField struct { + Short *bool `json:"short"` + Title string `json:"title,omitempty"` + Value string `json:"value,omitempty"` +} + +const ( + ProcessingTypeSendMessage = "sendMessage" + ProcessingTypeRespondWithMessage = "respondWithMessage" +) + +type RocketchatAttachmentAction struct { + Type string `json:"type,omitempty"` + Text string `json:"text,omitempty"` + URL string `json:"url,omitempty"` + ImageURL string `json:"image_url,omitempty"` + IsWebView bool `json:"is_webview"` + WebviewHeightRatio string `json:"webview_height_ratio,omitempty"` + Msg string `json:"msg,omitempty"` + MsgInChatWindow bool `json:"msg_in_chat_window"` + MsgProcessingType string `json:"msg_processing_type,omitempty"` +} + +// RocketchatConfig configures notifications via Rocketchat. +type RocketchatConfig struct { + NotifierConfig `yaml:",inline" json:",inline"` + + HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"` + + APIURL *URL `yaml:"api_url,omitempty" json:"api_url,omitempty"` + TokenID *Secret `yaml:"token_id,omitempty" json:"token_id,omitempty"` + TokenIDFile string `yaml:"token_id_file,omitempty" json:"token_id_file,omitempty"` + Token *Secret `yaml:"token,omitempty" json:"token,omitempty"` + TokenFile string `yaml:"token_file,omitempty" json:"token_file,omitempty"` + + // RocketChat channel override, (like #other-channel or @username). + Channel string `yaml:"channel,omitempty" json:"channel,omitempty"` + + Color string `yaml:"color,omitempty" json:"color,omitempty"` + Title string `yaml:"title,omitempty" json:"title,omitempty"` + TitleLink string `yaml:"title_link,omitempty" json:"title_link,omitempty"` + Text string `yaml:"text,omitempty" json:"text,omitempty"` + Fields []*RocketchatAttachmentField `yaml:"fields,omitempty" json:"fields,omitempty"` + ShortFields bool `yaml:"short_fields" json:"short_fields,omitempty"` + Emoji string `yaml:"emoji,omitempty" json:"emoji,omitempty"` + IconURL string `yaml:"icon_url,omitempty" json:"icon_url,omitempty"` + ImageURL string `yaml:"image_url,omitempty" json:"image_url,omitempty"` + ThumbURL string `yaml:"thumb_url,omitempty" json:"thumb_url,omitempty"` + LinkNames bool `yaml:"link_names" json:"link_names,omitempty"` + Actions []*RocketchatAttachmentAction `yaml:"actions,omitempty" json:"actions,omitempty"` +} + +// UnmarshalYAML implements the yaml.Unmarshaler interface. +func (c *RocketchatConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { + *c = DefaultRocketchatConfig + type plain RocketchatConfig + if err := unmarshal((*plain)(c)); err != nil { + return err + } + if c.Token != nil && len(c.TokenFile) > 0 { + return errors.New("at most one of token & token_file must be configured") + } + if c.TokenID != nil && len(c.TokenIDFile) > 0 { + return errors.New("at most one of token_id & token_id_file must be configured") + } return nil } diff --git a/config/receiver/receiver.go b/config/receiver/receiver.go index 7edc177500..f66c4a7048 100644 --- a/config/receiver/receiver.go +++ b/config/receiver/receiver.go @@ -28,6 +28,7 @@ import ( "github.com/prometheus/alertmanager/notify/opsgenie" "github.com/prometheus/alertmanager/notify/pagerduty" "github.com/prometheus/alertmanager/notify/pushover" + "github.com/prometheus/alertmanager/notify/rocketchat" "github.com/prometheus/alertmanager/notify/slack" "github.com/prometheus/alertmanager/notify/sns" "github.com/prometheus/alertmanager/notify/telegram" @@ -100,6 +101,9 @@ func BuildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logg for i, c := range nc.JiraConfigs { add("jira", i, c, func(l log.Logger) (notify.Notifier, error) { return jira.New(c, tmpl, l, httpOpts...) }) } + for i, c := range nc.RocketchatConfigs { + add("rocketchat", i, c, func(l log.Logger) (notify.Notifier, error) { return rocketchat.New(c, tmpl, l, httpOpts...) }) + } if errs.Len() > 0 { return nil, &errs diff --git a/config/testdata/conf.rocketchat-both-token-and-tokenfile.yml b/config/testdata/conf.rocketchat-both-token-and-tokenfile.yml new file mode 100644 index 0000000000..b51cebde47 --- /dev/null +++ b/config/testdata/conf.rocketchat-both-token-and-tokenfile.yml @@ -0,0 +1,20 @@ +global: + rocketchat_token_file: /global_file + rocketchat_token: token123 +route: + group_by: ['alertname', 'cluster', 'service'] + group_wait: 30s + group_interval: 5m + repeat_interval: 3h + receiver: team-Y-rocketchat + routes: + - match: + service: foo + receiver: team-X-rocketchat +receivers: + - name: 'team-X-rocketchat' + rocketchat_configs: + - channel: '#team-X' + - name: 'team-Y-rocketchat' + rocketchat_configs: + - channel: '#team-Y' diff --git a/config/testdata/conf.rocketchat-both-tokenid-and-tokenidfile.yml b/config/testdata/conf.rocketchat-both-tokenid-and-tokenidfile.yml new file mode 100644 index 0000000000..702e0522c7 --- /dev/null +++ b/config/testdata/conf.rocketchat-both-tokenid-and-tokenidfile.yml @@ -0,0 +1,20 @@ +global: + rocketchat_token_id_file: /global_file + rocketchat_token_id: id123 +route: + group_by: ['alertname', 'cluster', 'service'] + group_wait: 30s + group_interval: 5m + repeat_interval: 3h + receiver: team-Y-rocketchat + routes: + - match: + service: foo + receiver: team-X-rocketchat +receivers: + - name: 'team-X-rocketchat' + rocketchat_configs: + - channel: '#team-X' + - name: 'team-Y-rocketchat' + rocketchat_configs: + - channel: '#team-Y' diff --git a/config/testdata/conf.rocketchat-default-token-file.yml b/config/testdata/conf.rocketchat-default-token-file.yml new file mode 100644 index 0000000000..c298422938 --- /dev/null +++ b/config/testdata/conf.rocketchat-default-token-file.yml @@ -0,0 +1,22 @@ +global: + rocketchat_token_file: /global_file + rocketchat_token_id_file: /etc/alertmanager/rocketchat_token_id +route: + group_by: ['alertname', 'cluster', 'service'] + group_wait: 30s + group_interval: 5m + repeat_interval: 3h + receiver: team-Y-rocketchat + routes: + - match: + service: foo + receiver: team-X-rocketchat +receivers: + - name: 'team-X-rocketchat' + rocketchat_configs: + - channel: '#team-X' + - name: 'team-Y-rocketchat' + rocketchat_configs: + - channel: '#team-Y' + token_file: /override_file + token_id_file: /override_file diff --git a/config/testdata/conf.rocketchat-default-token.yml b/config/testdata/conf.rocketchat-default-token.yml new file mode 100644 index 0000000000..01387472c8 --- /dev/null +++ b/config/testdata/conf.rocketchat-default-token.yml @@ -0,0 +1,22 @@ +global: + rocketchat_token: token123 + rocketchat_token_id: id123 +route: + group_by: ['alertname', 'cluster', 'service'] + group_wait: 30s + group_interval: 5m + repeat_interval: 3h + receiver: team-Y-rocketchat + routes: + - match: + service: foo + receiver: team-X-rocketchat +receivers: + - name: 'team-X-rocketchat' + rocketchat_configs: + - channel: '#team-X' + - name: 'team-Y-rocketchat' + rocketchat_configs: + - channel: '#team-Y' + token: token456 + token_id: id456 diff --git a/config/testdata/conf.rocketchat-no-token.yml b/config/testdata/conf.rocketchat-no-token.yml new file mode 100644 index 0000000000..ca44388828 --- /dev/null +++ b/config/testdata/conf.rocketchat-no-token.yml @@ -0,0 +1,19 @@ +global: + rocketchat_token_id: id123 +route: + group_by: ['alertname', 'cluster', 'service'] + group_wait: 30s + group_interval: 5m + repeat_interval: 3h + receiver: team-Y-rocketchat + routes: + - match: + service: foo + receiver: team-X-rocketchat +receivers: + - name: 'team-X-rocketchat' + rocketchat_configs: + - channel: '#team-X' + - name: 'team-Y-rocketchat' + rocketchat_configs: + - channel: '#team-Y' diff --git a/docs/configuration.md b/docs/configuration.md index 7db87af50f..b2e73d7d4b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -97,7 +97,7 @@ global: # The default TLS configuration for SMTP receivers [ smtp_tls_config: ] - # Default settings for the JIRA integration. + # Default settings for the JIRA integration. [ jira_api_url: ] # The API URL to use for Slack notifications. @@ -110,6 +110,11 @@ global: [ opsgenie_api_key: ] [ opsgenie_api_key_file: ] [ opsgenie_api_url: | default = "https://api.opsgenie.com/" ] + [ rocketchat_api_url: | default = "https://open.rocket.chat/api/v1/chat.postMessage" ] + [ rocketchat_token: ] + [ rocketchat_token_file: ] + [ rocketchat_token_id: ] + [ rocketchat_token_id_file: ] [ wechat_api_url: | default = "https://qyapi.weixin.qq.com/cgi-bin/" ] [ wechat_api_secret: ] [ wechat_api_corp_id: ] @@ -710,6 +715,8 @@ pagerduty_configs: [ - , ... ] pushover_configs: [ - , ... ] +rocket_configs: + [ - , ... ] slack_configs: [ - , ... ] sns_configs: @@ -981,7 +988,7 @@ Microsoft Teams v2 notifications using the new message format with adaptive card JIRA notifications are sent via [JIRA Rest API v2](https://developer.atlassian.com/cloud/jira/platform/rest/v2/intro/) or [JIRA REST API v3](https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#version). -Note: This integration is only tested against a Jira Cloud instance. +Note: This integration is only tested against a Jira Cloud instance. Jira Data Center (on premise instance) can work, but it's not guaranteed. Both APIs have the same feature set. The difference is that V2 supports [Wiki Markup](https://jira.atlassian.com/secure/WikiRendererHelpAction.jspa?section=all) @@ -1006,7 +1013,7 @@ project: [ description: | default = '{{ template "jira.default.description" . }}' ] # Labels to be added to the issue. -labels: +labels: [ - ... ] # Priority of the issue. @@ -1283,6 +1290,62 @@ token_file: [ http_config: | default = global.http_config ] ``` +### `` + +Rocketchat notifications are sent via the [Rocketchat REST API](https://developer.rocket.chat/reference/api/rest-api/endpoints/messaging/chat-endpoints/postmessage). + +```yaml +# Whether to notify about resolved alerts. +[ send_resolved: | default = true ] +[ api_url: | default = global.rocketchat_api_url ] +[ channel: | default = global.rocketchat_api_url ] + +# The sender token and token_id +# See https://docs.rocket.chat/use-rocket.chat/user-guides/user-panel/my-account#personal-access-tokens +# token and token_file are mutually exclusive. +# token_id and token_id_file are mutually exclusive. +token: +token_file: +token_id: +token_id_file: + + +[ color: ... ] +[ image_url ] +[ thumb_url ] +[ link_names ] +[ short_fields: | default = false ] +actions: + [ ... ] +``` + +#### `` + +The fields are documented in the [Rocketchat API documentation](https://developer.rocket.chat/reference/api/rest-api/endpoints/messaging/chat-endpoints/postmessage#attachment-field-objects). + +```yaml +[ title: ] +[ value: ] +[ short: | default = rocketchat_config.short_fields ] +``` + +#### `` +The fields are documented in the [Rocketchat API api models](https://github.com/RocketChat/Rocket.Chat.Go.SDK/blob/master/models/message.go). + +```yaml +[ type: | ignored, only "button" is supported ] +[ text: ] +[ url: ] +[ msg: ] + ### `` Slack notifications can be sent via [Incoming webhooks](https://api.slack.com/messaging/webhooks) or [Bot tokens](https://api.slack.com/authentication/token-types). diff --git a/notify/notify.go b/notify/notify.go index 25d04cb237..6510653442 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -367,6 +367,7 @@ func (m *Metrics) InitializeFor(receiver map[string][]Integration) { "msteams", "msteamsv2", "jira", + "rocketchat", } { m.numNotifications.WithLabelValues(integration) m.numNotificationRequestsTotal.WithLabelValues(integration) diff --git a/notify/rocketchat/rocketchat.go b/notify/rocketchat/rocketchat.go new file mode 100644 index 0000000000..2dc06b4397 --- /dev/null +++ b/notify/rocketchat/rocketchat.go @@ -0,0 +1,269 @@ +// Copyright 2022 Prometheus Team +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package rocketchat + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "os" + "strings" + + "github.com/go-kit/log" + "github.com/go-kit/log/level" + commoncfg "github.com/prometheus/common/config" + + "github.com/prometheus/alertmanager/config" + "github.com/prometheus/alertmanager/notify" + "github.com/prometheus/alertmanager/template" + "github.com/prometheus/alertmanager/types" +) + +const maxTitleLenRunes = 1024 + +type Notifier struct { + conf *config.RocketchatConfig + tmpl *template.Template + logger log.Logger + client *http.Client + retrier *notify.Retrier + token string + tokenID string + + postJSONFunc func(ctx context.Context, client *http.Client, url string, body io.Reader) (*http.Response, error) +} + +// PostMessage Payload for postmessage rest API +// +// https://rocket.chat/docs/developer-guides/rest-api/chat/postmessage/ +type Attachment struct { + Title string `json:"title,omitempty"` + TitleLink string `json:"title_link,omitempty"` + Text string `json:"text,omitempty"` + ImageURL string `json:"image_url,omitempty"` + ThumbURL string `json:"thumb_url,omitempty"` + Color string `json:"color,omitempty"` + Fields []config.RocketchatAttachmentField `json:"fields,omitempty"` + Actions []config.RocketchatAttachmentAction `json:"actions,omitempty"` +} + +// PostMessage Payload for postmessage rest API +// +// https://rocket.chat/docs/developer-guides/rest-api/chat/postmessage/ +type PostMessage struct { + Channel string `json:"channel,omitempty"` + Text string `json:"text,omitempty"` + ParseUrls bool `json:"parseUrls,omitempty"` + Alias string `json:"alias,omitempty"` + Emoji string `json:"emoji,omitempty"` + Avatar string `json:"avatar,omitempty"` + Attachments []Attachment `json:"attachments,omitempty"` + Actions []config.RocketchatAttachmentAction `json:"actions,omitempty"` +} + +type rocketchatRoundTripper struct { + wrapped http.RoundTripper + token string + tokenID string +} + +func (t *rocketchatRoundTripper) RoundTrip(req *http.Request) (res *http.Response, e error) { + req.Header.Set("X-Auth-Token", t.token) + req.Header.Set("X-User-Id", t.tokenID) + return t.wrapped.RoundTrip(req) +} + +// New returns a new Rocketchat notification handler. +func New(c *config.RocketchatConfig, t *template.Template, l log.Logger, httpOpts ...commoncfg.HTTPClientOption) (*Notifier, error) { + client, err := commoncfg.NewClientFromConfig(*c.HTTPConfig, "rocketchat", httpOpts...) + if err != nil { + return nil, err + } + token, err := getToken(c) + if err != nil { + return nil, err + } + tokenID, err := getTokenID(c) + if err != nil { + return nil, err + } + + client.Transport = &rocketchatRoundTripper{wrapped: client.Transport, token: token, tokenID: tokenID} + return &Notifier{ + conf: c, + tmpl: t, + logger: l, + client: client, + retrier: ¬ify.Retrier{}, + postJSONFunc: notify.PostJSON, + token: token, + tokenID: tokenID, + }, nil +} + +func getTokenID(c *config.RocketchatConfig) (string, error) { + if len(c.TokenIDFile) > 0 { + content, err := os.ReadFile(c.TokenIDFile) + if err != nil { + return "", fmt.Errorf("could not read %s: %w", c.TokenIDFile, err) + } + return strings.TrimSpace(string(content)), nil + } + return string(*c.TokenID), nil +} + +func getToken(c *config.RocketchatConfig) (string, error) { + if len(c.TokenFile) > 0 { + content, err := os.ReadFile(c.TokenFile) + if err != nil { + return "", fmt.Errorf("could not read %s: %w", c.TokenFile, err) + } + return strings.TrimSpace(string(content)), nil + } + return string(*c.Token), nil +} + +// Notify implements the Notifier interface. +func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) { + var err error + + data := notify.GetTemplateData(ctx, n.tmpl, as, n.logger) + tmplText := notify.TmplText(n.tmpl, data, &err) + if err != nil { + return false, err + } + title := tmplText(n.conf.Title) + if err != nil { + return false, err + } + + title, truncated := notify.TruncateInRunes(title, maxTitleLenRunes) + if truncated { + key, err := notify.ExtractGroupKey(ctx) + if err != nil { + return false, err + } + level.Warn(n.logger).Log("msg", "Truncated title", "key", key, "max_runes", maxTitleLenRunes) + } + att := &Attachment{ + Title: title, + TitleLink: tmplText(n.conf.TitleLink), + Text: tmplText(n.conf.Text), + ImageURL: tmplText(n.conf.ImageURL), + ThumbURL: tmplText(n.conf.ThumbURL), + Color: tmplText(n.conf.Color), + } + numFields := len(n.conf.Fields) + if numFields > 0 { + fields := make([]config.RocketchatAttachmentField, numFields) + for index, field := range n.conf.Fields { + // Check if short was defined for the field otherwise fallback to the global setting + var short bool + if field.Short != nil { + short = *field.Short + } else { + short = n.conf.ShortFields + } + + // Rebuild the field by executing any templates and setting the new value for short + fields[index] = config.RocketchatAttachmentField{ + Title: tmplText(field.Title), + Value: tmplText(field.Value), + Short: &short, + } + } + att.Fields = fields + } + numActions := len(n.conf.Actions) + if numActions > 0 { + actions := make([]config.RocketchatAttachmentAction, numActions) + for index, action := range n.conf.Actions { + actions[index] = config.RocketchatAttachmentAction{ + Type: "button", // Only button type is supported + Text: tmplText(action.Text), + URL: tmplText(action.URL), + Msg: tmplText(action.Msg), + } + } + att.Actions = actions + } + + body := &PostMessage{ + Channel: n.conf.Channel, + Emoji: tmplText(n.conf.Emoji), + Avatar: tmplText(n.conf.IconURL), + Attachments: []Attachment{*att}, + } + if err != nil { + return false, err + } + + var buf bytes.Buffer + if err := json.NewEncoder(&buf).Encode(body); err != nil { + return false, err + } + resp, err := n.postJSONFunc(ctx, n.client, n.conf.APIURL.String(), &buf) + if err != nil { + return true, notify.RedactURL(err) + } + defer notify.Drain(resp) + + // Use a retrier to generate an error message for non-200 responses and + // classify them as retriable or not. + retry, err := n.retrier.Check(resp.StatusCode, resp.Body) + if err != nil { + err = fmt.Errorf("channel %q: %w", body.Channel, err) + return retry, notify.NewErrorWithReason(notify.GetFailureReasonFromStatusCode(resp.StatusCode), err) + } + + // Rocketchat web API might return errors with a 200 response code. + retry, err = checkResponseError(resp) + if err != nil { + err = fmt.Errorf("channel %q: %w", body.Channel, err) + return retry, notify.NewErrorWithReason(notify.ClientErrorReason, err) + } + + return retry, nil +} + +// checkResponseError parses out the error message from Rocketchat API response. +func checkResponseError(resp *http.Response) (bool, error) { + body, err := io.ReadAll(resp.Body) + if err != nil { + return true, fmt.Errorf("could not read response body: %w", err) + } + + return checkJSONResponseError(body) +} + +// checkJSONResponseError classifies JSON responses from Rocketchat. +func checkJSONResponseError(body []byte) (bool, error) { + // response is for parsing out errors from the JSON response. + type response struct { + Success bool `json:"success"` + Error string `json:"error"` + } + + var data response + if err := json.Unmarshal(body, &data); err != nil { + return true, fmt.Errorf("could not unmarshal JSON response %q: %w", string(body), err) + } + if !data.Success { + return false, fmt.Errorf("error response from Rocketchat: %s", data.Error) + } + return false, nil +} diff --git a/notify/rocketchat/rocketchat_test.go b/notify/rocketchat/rocketchat_test.go new file mode 100644 index 0000000000..35033d3db7 --- /dev/null +++ b/notify/rocketchat/rocketchat_test.go @@ -0,0 +1,66 @@ +// Copyright 2019 Prometheus Team +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package rocketchat + +import ( + "fmt" + "net/url" + "os" + "testing" + + "github.com/go-kit/log" + commoncfg "github.com/prometheus/common/config" + "github.com/stretchr/testify/require" + + "github.com/prometheus/alertmanager/config" + "github.com/prometheus/alertmanager/notify/test" +) + +func TestRocketchatRetry(t *testing.T) { + secret := config.Secret("xxxxx") + notifier, err := New( + &config.RocketchatConfig{ + HTTPConfig: &commoncfg.HTTPClientConfig{}, + Token: &secret, + TokenID: &secret, + }, + test.CreateTmpl(t), + log.NewNopLogger(), + ) + require.NoError(t, err) + + for statusCode, expected := range test.RetryTests(test.DefaultRetryCodes()) { + actual, _ := notifier.retrier.Check(statusCode, nil) + require.Equal(t, expected, actual, fmt.Sprintf("error on status %d", statusCode)) + } +} + +func TestGettingRocketchatTokenFromFile(t *testing.T) { + f, err := os.CreateTemp("", "rocketchat_test") + require.NoError(t, err, "creating temp file failed") + _, err = f.WriteString("secret") + require.NoError(t, err, "writing to temp file failed") + + _, err = New( + &config.RocketchatConfig{ + TokenFile: f.Name(), + TokenIDFile: f.Name(), + HTTPConfig: &commoncfg.HTTPClientConfig{}, + APIURL: &config.URL{URL: &url.URL{Scheme: "http", Host: "example.com", Path: "/api/v1/"}}, + }, + test.CreateTmpl(t), + log.NewNopLogger(), + ) + require.NoError(t, err) +} diff --git a/template/default.tmpl b/template/default.tmpl index 6475e0a260..a08caa86a1 100644 --- a/template/default.tmpl +++ b/template/default.tmpl @@ -209,3 +209,10 @@ Alerts Resolved: {{- end -}} {{- $priority -}} {{- end -}} + +{{ define "rocketchat.default.title" }}{{ template "__subject" . }}{{ end }} +{{ define "rocketchat.default.alias" }}{{ template "__alertmanager" . }}{{ end }} +{{ define "rocketchat.default.titlelink" }}{{ template "__alertmanagerURL" . }}{{ end }} +{{ define "rocketchat.default.emoji" }}{{ end }} +{{ define "rocketchat.default.iconurl" }}{{ end }} +{{ define "rocketchat.default.text" }}{{ end }}