diff --git a/asset/assets_vfsdata.go b/asset/assets_vfsdata.go index f74112ad01..6634f64fef 100644 --- a/asset/assets_vfsdata.go +++ b/asset/assets_vfsdata.go @@ -163,9 +163,9 @@ var Assets = func() http.FileSystem { "/templates/default.tmpl": &vfsgen۰CompressedFileInfo{ name: "default.tmpl", modTime: time.Date(1970, 1, 1, 0, 0, 1, 0, time.UTC), - uncompressedSize: 5951, + uncompressedSize: 6349, - compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xec\x58\x4f\x6f\xbb\x46\x10\xbd\xf3\x29\x56\xce\x25\x3e\x98\xf4\x1c\x29\xaa\xa2\xaa\xed\x25\xaa\x2a\x47\xee\xa5\xaa\xd0\x1a\xc6\x64\xe3\xfd\x43\x76\x07\x27\x16\xe6\xbb\x57\x0b\xc4\x06\x2f\x38\x8b\xe3\xdf\xe9\xe7\x5b\xd8\xcc\xbc\x99\x7d\x6f\x98\x19\x5c\x14\x24\x81\x15\x93\x40\x26\x51\x44\x39\x68\x14\x54\xd2\x14\xf4\x84\x94\xe5\x63\xeb\xb9\x28\x08\xc8\x84\x94\x65\x30\xe8\xb2\x98\x3f\x59\xaf\xa2\x20\xe1\xef\x1f\x08\x5a\x52\xbe\x98\x3f\x91\xb2\xbc\xbb\xb9\xab\xec\xcc\xaf\x1a\x62\x60\x1b\xd0\x0f\xd6\x68\xde\x3c\x90\x1d\xc9\x35\x7f\xcb\x41\x6f\x6b\xf7\x26\x50\x37\x92\xc9\x97\xaf\x10\xa3\x8d\xf0\xaf\xf5\x7e\x46\x8a\xb9\x21\x3b\x82\x6a\x91\x65\xa0\x6b\x57\xb6\x22\xf0\xb6\xff\xe7\x64\xc5\x34\x93\xa9\xf5\xb9\xb7\x3e\xd5\x85\x4c\xf8\x47\x75\x4a\x76\x84\x83\x6c\x47\xfc\x8f\x58\xa3\x3f\xb5\xca\xb3\x27\xba\x04\x6e\xc2\x67\xa5\x11\x92\xbf\x29\xd3\x26\xfc\x87\xf2\x1c\x6c\xc0\x57\xc5\x24\x99\x10\x8b\x4a\xea\x90\x29\x92\x5b\x8b\x15\xfe\xa6\x84\x50\xb2\x76\x9e\x36\x67\x2d\xbc\x29\x29\xcb\xdb\xa2\x20\xef\x0c\x5f\xba\xc6\xe1\x1c\x84\xda\x40\x37\xfa\x5f\x54\x80\x69\x18\xed\x8b\xbe\x4f\x7c\xba\xff\x6b\x40\xa6\x04\x4c\xac\x59\x86\x4c\xc9\xc9\x09\x8e\x11\x3e\xb0\x96\x34\xe2\xcc\x60\x63\xaa\xa9\x4c\x81\x84\xa4\x2c\xeb\xbc\xee\x83\xc3\xa1\xcb\x93\x65\x65\x56\x11\x69\xd3\xb7\x4f\x0f\x64\x7f\x81\x26\xb1\x3a\xf8\xa3\x94\x0a\xa9\xcd\xa9\x03\xd9\x3a\x3e\x0f\xf7\x59\xe5\x3a\x86\xfb\x5a\x4c\x90\xa0\x29\x2a\x5d\x57\x62\xd0\x43\xd4\x49\x0a\x22\x41\xf5\x3a\x51\xef\xd2\xe1\x22\xf0\x25\xc3\x33\xeb\x60\x3c\x1d\xbe\xc8\x5e\x84\x04\xfd\x8c\x18\x4e\xe3\x75\x98\xc0\x8a\xe6\x1c\x43\x64\xc8\xa1\xa1\x02\x41\x64\x9c\x62\xf7\xe5\x0c\x87\x6a\xb0\x8b\x93\x1b\xdb\x1e\x44\x1f\x54\xb7\x09\x79\xe2\xad\x28\xe7\x4b\x1a\xaf\x1d\xbc\xde\xf4\x2d\x28\xd9\x91\xaf\x0c\x39\x93\x6b\xef\x0c\xe2\x26\x03\x96\x4c\xfc\x1c\x32\x0d\xb6\xd6\x3c\xad\x5b\x09\x9d\x64\xac\xea\xc1\x9e\x29\xb3\x58\x49\x10\xea\x95\x4d\xfc\xed\x73\xcd\x7d\x33\xf6\xbf\xdc\x4a\x29\xac\x27\x4e\xab\x06\xdb\xe6\x99\xbd\x5a\x92\xe3\x76\xef\xe2\x36\xb4\x71\xe5\xe8\x22\xc6\x9c\x81\xc4\xf3\x0b\x72\x08\xf1\x30\x15\xcf\xd3\xcc\xc5\x65\xd2\x20\x95\x31\x98\x1e\x5c\xa7\x83\x87\xc3\xac\xaa\xcc\xa4\x20\x19\xec\x81\x05\x18\x43\xd3\xf3\xde\x6f\x07\xcc\x55\xa8\x19\x78\x03\x0d\xad\x77\xc2\x05\x47\xf3\xb5\x33\xc0\xa7\xe4\x17\x32\xb3\x8d\xb3\x3a\x24\xf5\x61\xd5\x3a\x4f\x33\xd2\xdd\x02\xaa\x20\xb3\xd6\x8d\x7a\xe2\xcd\xc1\x28\xbe\x81\xe4\x28\xe2\xe7\xb1\x7f\xcc\x4f\x0f\x27\xea\xcc\x87\x52\x53\xf5\xf1\xf1\xd5\xd4\x51\xfd\x1d\xe2\x17\x8a\x63\x35\x0f\xae\xfa\x9d\xd0\xaf\xbd\x28\x2f\x34\x77\xf0\x7a\xf5\x19\x50\xfd\x48\x1f\x54\x91\x1d\x96\x83\x9d\xd4\x35\xcf\xa8\xc6\xed\x08\x7b\xa4\xa9\xaf\x35\x4d\x41\x62\x74\x3c\xe2\xba\xf5\xb5\x61\x31\x2a\xad\x32\x73\x28\x5b\xa4\x08\x51\xb7\xd0\xae\xb5\x34\xae\x17\xb8\xac\x82\x44\x86\xdb\x28\x61\x26\xe3\x74\x1b\x0d\x6c\x53\x5f\x37\x6e\x17\x59\x28\xc9\x50\x59\x42\x22\x54\x8a\x8f\x1c\x89\x9d\xd9\x95\x9b\x17\xb5\x01\x7d\x81\xfd\xd1\x81\xfa\xf1\xf5\x74\x99\x72\xf2\xaf\xa6\xcb\x15\x93\xbb\xd2\x9f\x62\xf2\xb0\xd3\x8d\x99\x29\xed\x6d\x4e\xb6\x5e\xf6\xc3\x67\xfa\xf8\x6f\x84\x16\xce\x55\xde\x31\xf2\xb6\x59\x44\xe0\x90\x6a\x2a\xfa\xa8\xfc\x69\x49\x49\x98\x89\x95\x4e\x2e\xd0\x88\x8e\x91\xae\xec\xda\x35\x61\x09\x1f\xd7\x57\xf7\xdb\x3c\x0a\x83\x40\x45\xbb\x99\x0a\x41\xf5\xf6\xac\x3a\x3d\xc6\x3a\xbf\xe2\x1d\xa4\xe6\xcb\xde\x47\xa6\x1b\x32\x4a\xa8\xd6\xcf\x6d\xdf\x56\x6c\x1f\xda\x57\xb3\x9e\xe0\x5f\x89\xf7\x7f\x00\x00\x00\xff\xff\xf6\x0e\x88\xb1\x3f\x17\x00\x00"), + compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xec\x58\x4d\x6f\xe3\x36\x10\xbd\xeb\x57\x10\xde\xcb\xe6\x10\x6d\xcf\x01\x16\xc5\xa2\x68\x7b\x09\x8a\xc2\x41\x7a\x29\x0a\x81\x96\xc6\x0a\x63\x7e\x68\xc9\x91\x13\x43\xd6\x7f\x2f\x28\x69\x6d\xca\x94\x6c\x4a\x71\x4f\xf5\xcd\xa2\x67\xde\x0c\xdf\x1b\xcd\x50\xac\x2a\x92\xc1\x9a\x49\x20\x8b\x24\xa1\x1c\x34\x0a\x2a\x69\x0e\x7a\x41\xea\xfa\x9b\xf3\x5c\x55\x04\x64\x46\xea\x3a\x1a\x75\x79\x5e\x3e\x5a\xaf\xaa\x22\xf1\xaf\xef\x08\x5a\x52\xfe\xbc\x7c\x24\x75\xfd\xe5\xd3\x97\xc6\xce\xfc\xac\x21\x05\xb6\x05\xfd\xd5\x1a\x2d\xbb\x07\xb2\x27\xa5\xe6\xdf\x4b\xd0\xbb\xd6\xbd\x0b\xd4\x8f\x64\xca\xd5\x2b\xa4\x68\x23\xfc\x6d\xbd\x9f\x90\x62\x69\xc8\x9e\xa0\x7a\x2e\x0a\xd0\xad\x2b\x5b\x13\xf8\x7e\xf8\x73\xb1\x66\x9a\xc9\xdc\xfa\x3c\x58\x9f\x66\x43\x26\xfe\xad\x59\x25\x7b\xc2\x41\xba\x11\xff\x21\xd6\xe8\x77\xad\xca\xe2\x91\xae\x80\x9b\xf8\x49\x69\x84\xec\x4f\xca\xb4\x89\xff\xa2\xbc\x04\x1b\xf0\x55\x31\x49\x16\xc4\xa2\x92\x36\x64\x8e\xe4\xb3\xc5\x8a\x7f\x51\x42\x28\xd9\x3a\xdf\x75\x6b\x0e\xde\x1d\xa9\xeb\xcf\x55\x45\xde\x18\xbe\xf4\x8d\xe3\x25\x08\xb5\x85\x7e\xf4\x3f\xa8\x00\xd3\x31\x3a\x14\xfd\x90\xf8\xdd\xe1\xd7\x88\x4c\x19\x98\x54\xb3\x02\x99\x92\x8b\x33\x1c\x23\xbc\x63\x2b\x69\xc2\x99\xc1\xce\x54\x53\x99\x03\x89\x49\x5d\xb7\x79\x3d\x44\xc7\x45\x9f\x27\xcb\xca\x7d\x43\xa4\x4d\xdf\x3e\x7d\x25\x87\x0d\x74\x89\xb5\xc1\xbf\x49\xa9\x90\xda\x9c\x7a\x90\xce\xf2\x3c\xdc\x27\x55\xea\x14\x1e\x5a\x31\x41\x82\xa6\xa8\x74\x5b\x89\xd1\x00\x51\x67\x29\x48\x04\xd5\x9b\x4c\xbd\x49\x8f\x8b\x28\x94\x8c\xc0\xac\xa3\xe9\x74\x84\x22\x07\x11\x12\x0d\x33\x62\x38\x4d\x37\x71\x06\x6b\x5a\x72\x8c\x91\x21\x87\x8e\x0a\x04\x51\x70\x8a\xfd\x97\x33\x1e\xab\xc1\x3e\x4e\x69\x6c\x7b\x10\x43\x50\xfd\x26\x14\x88\xb7\xa6\x9c\xaf\x68\xba\xf1\xf0\x06\xd3\xb7\xa0\x64\x4f\x2e\x19\x72\x26\x37\xc1\x19\xa4\x5d\x06\x2c\x5b\x84\x39\x14\x1a\x6c\xad\x05\x5a\x3b\x09\x9d\x65\xac\xe9\xc1\x81\x29\xb3\x54\x49\x10\xea\x95\x2d\xc2\xed\x4b\xcd\x43\x33\x0e\xdf\xdc\x5a\x29\x6c\x27\x8e\x53\x83\xae\x79\x61\xb7\x96\x95\xb8\x3b\xb8\xf8\x0d\x6d\x5a\x39\xfa\x88\x29\x67\x20\x71\x7e\x41\x8e\x21\x1e\xa7\xe2\x3c\xcd\x7c\x5c\x26\x0d\x52\x99\x82\x19\xc0\xf5\x3a\x78\x3c\xce\xaa\x2a\x4c\x0e\x92\xc1\x01\x58\x80\x31\x34\x9f\xf7\x7e\x7b\x60\xbe\x42\xdd\xc0\x1b\x69\x68\x83\x13\x2e\x3a\x99\xaf\xbd\x01\x7e\x47\x7e\x22\xf7\xb6\x71\x36\x8b\xa4\x5d\x6c\x5a\xe7\x79\x46\xfa\xa7\x80\x26\xc8\xbd\xb3\xa3\x81\x78\x4b\x30\x8a\x6f\x21\x3b\x89\xf8\x63\x39\x3c\xe6\x0f\x0f\x2f\xea\x7d\x08\xa5\xa6\xe9\xe3\xd3\xab\xa9\xa7\xfa\x1b\xa4\x2f\x14\xa7\x6a\x1e\xdd\xf4\x3b\xa3\x9f\x7b\x50\x7e\xd6\xdc\xc3\x1b\xd4\x67\x44\xf5\x13\x7d\x50\x25\x76\x58\x8e\x76\x52\xdf\xbc\xa0\x1a\x77\x13\xec\x91\xe6\xa1\xd6\x34\x07\x89\xc9\xe9\x88\xeb\xd7\xd7\x96\xa5\xa8\xb4\x2a\xcc\xb1\x6c\x91\x22\x24\xfd\x42\xbb\xd5\xd2\xb4\x5e\xe0\xb3\x0a\x12\x19\xee\x92\x8c\x99\x82\xd3\x5d\x32\x72\x9a\xba\xdc\xb8\x7d\x64\xa1\x24\x43\x65\x09\x49\x50\x29\x3e\x71\x24\xf6\x66\x57\x69\x5e\xd4\x16\xf4\x15\xce\x8f\x1e\xd4\x7f\x5f\x4f\xd7\x29\xa7\xf0\x6a\xba\x5e\x31\xf9\x47\xfa\x73\x4c\x1e\xcf\x74\x53\x66\x8a\x7b\x9a\x93\xce\xcb\x7e\xfc\x4c\x9f\xfe\x8d\xe0\xe0\xdc\xe4\x9d\x22\xaf\xcb\x22\x02\x87\x5c\x53\x31\x44\xe5\xff\x96\x94\x8c\x99\x54\xe9\xec\x0a\x8d\xe8\x14\xe9\xc6\xae\x3d\x26\xac\xe0\xfd\xf6\xea\x7e\x98\x47\x61\x10\xa8\x70\x9b\xa9\x10\x54\xef\x66\xd5\xe9\x29\xd6\xfc\x8a\xf7\x90\xba\x2f\xfb\x10\x99\x3e\x91\x49\x42\x39\xd7\x6d\x1f\x56\xec\x10\x3a\x54\xb3\x81\xe0\x17\xc5\x73\x79\xd2\x2a\xdd\x00\xf6\x8f\xd7\xb3\x49\x1f\x00\xa3\x9c\x51\x33\xff\x82\x62\x2c\xbd\x0f\xdf\x2a\x0d\x00\x9f\xbf\x56\x1a\x70\xb8\x74\xb7\x34\x94\xbc\x77\xc1\xf4\x6f\x00\x00\x00\xff\xff\xd4\x6a\xf2\x42\xcd\x18\x00\x00"), }, "/templates/email.tmpl": &vfsgen۰CompressedFileInfo{ name: "email.tmpl", diff --git a/config/config.go b/config/config.go index 8816e20f8d..89e0265ed5 100644 --- a/config/config.go +++ b/config/config.go @@ -258,6 +258,9 @@ func resolveFilepaths(baseDir string, cfg *Config) { for _, cfg := range receiver.MSTeamsConfigs { cfg.HTTPConfig.SetDirectory(baseDir) } + for _, cfg := range receiver.RocketchatConfigs { + cfg.HTTPConfig.SetDirectory(baseDir) + } } } @@ -549,6 +552,9 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { } } for _, rocketchat := range rcv.RocketchatConfigs { + if rocketchat.HTTPConfig == nil { + rocketchat.HTTPConfig = c.Global.HTTPConfig + } if rocketchat.APIURL == nil { rocketchat.APIURL = c.Global.RocketchatAPIURL } diff --git a/config/notifiers.go b/config/notifiers.go index 776d5ccf82..97f09d3dce 100644 --- a/config/notifiers.go +++ b/config/notifiers.go @@ -24,8 +24,6 @@ import ( "github.com/pkg/errors" commoncfg "github.com/prometheus/common/config" "github.com/prometheus/common/sigv4" - - rcmodels "github.com/RocketChat/Rocket.Chat.Go.SDK/models" ) var ( @@ -105,7 +103,6 @@ var ( NotifierConfig: NotifierConfig{ VSendResolved: false, }, - // Alias: `{{ template "rocketchat.default.alias" . }}`, Color: `{{ if eq .Status "firing" }}red{{ else }}green{{ end }}`, Emoji: `{{ template "rocketchat.default.emoji" . }}`, IconURL: `{{ template "rocketchat.default.iconurl" . }}`, @@ -815,10 +812,43 @@ func (c *MSTeamsConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { return unmarshal((*plain)(c)) } +type RocketchaAttachmentField struct { + Short *bool `json:"short"` + Title string `json:"title,omitempty"` + Value string `json:"value,omitempty"` +} + +type RocketchatAttachmentActionType string + +const ( + RocketchatAttachmentActionTypeButton RocketchatAttachmentActionType = "button" +) + +type RocketchatMessageProcessingType string + +const ( + ProcessingTypeSendMessage RocketchatMessageProcessingType = "sendMessage" + ProcessingTypeRespondWithMessage RocketchatMessageProcessingType = "respondWithMessage" +) + +type RocketchatAttachmentAction struct { + Type RocketchatAttachmentActionType `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 RocketchatMessageProcessingType `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"` @@ -827,20 +857,19 @@ type RocketchatConfig struct { // RocketChat channel override, (like #other-channel or @username). Channel string `yaml:"channel,omitempty" json:"channel,omitempty"` - Alias string `yaml:"alias,omitempty" json:"alias,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 []*rcmodels.AttachmentField `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 []*rcmodels.AttachmentAction `yaml:"actions,omitempty" json:"actions,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 []*RocketchaAttachmentField `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. @@ -851,10 +880,10 @@ func (c *RocketchatConfig) UnmarshalYAML(unmarshal func(interface{}) error) erro return err } if c.Token != nil && len(c.TokenFile) > 0 { - return fmt.Errorf("at most one of api_url & api_url_file must be configured") + return fmt.Errorf("at most one of token & token_file must be configured") } if c.TokenID != nil && len(c.TokenIDFile) > 0 { - return fmt.Errorf("at most one of api_url & api_url_file must be configured") + return fmt.Errorf("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 9d06ca142a..2fa6766d0c 100644 --- a/config/receiver/receiver.go +++ b/config/receiver/receiver.go @@ -94,7 +94,7 @@ func BuildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logg add("msteams", i, c, func(l log.Logger) (notify.Notifier, error) { return msteams.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) }) + add("rocketchat", i, c, func(l log.Logger) (notify.Notifier, error) { return rocketchat.New(c, tmpl, l, httpOpts...) }) } if errs.Len() > 0 { diff --git a/go.mod b/go.mod index 28c0c90dd8..461651d192 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/prometheus/alertmanager go 1.21 require ( - github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20221121042443-a3fd332d56d9 github.com/alecthomas/kingpin/v2 v2.3.2 github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 github.com/aws/aws-sdk-go v1.47.0 diff --git a/go.sum b/go.sum index 901a4374e5..c8bffd1977 100644 --- a/go.sum +++ b/go.sum @@ -57,13 +57,9 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= -github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo= -github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20221121042443-a3fd332d56d9 h1:vuu1KBsr6l7XU3CHsWESP/4B1SNd+VZkrgeFZsUXrsY= -github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20221121042443-a3fd332d56d9/go.mod h1:rjP7sIipbZcagro/6TCk6X0ZeFT2eyudH5+fve/cbBA= github.com/alecthomas/kingpin/v2 v2.3.2 h1:H0aULhgmSzN8xQ3nX1uxtdlTHYoPLu5AhHxWrKI6ocU= github.com/alecthomas/kingpin/v2 v2.3.2/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -123,7 +119,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= @@ -142,8 +137,6 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -322,8 +315,6 @@ github.com/googleapis/gax-go/v2 v2.2.0/go.mod h1:as02EH8zWkzwUoLbBaFeQ+arQaj/Oth github.com/googleapis/gax-go/v2 v2.3.0/go.mod h1:b8LNqSzNabLiUpXKkY7HAR5jr6bIT99EXz9pXxye9YM= github.com/googleapis/gax-go/v2 v2.4.0/go.mod h1:XOTVJ59hdnfJLIP/dh8n5CGryZR2LxK9wbMD5+iXC6c= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= -github.com/gopackage/ddp v0.0.0-20170117053602-652027933df4 h1:4EZlYQIiyecYJlUbVkFXCXHz1QPhVXcHnQKAzBTPfQo= -github.com/gopackage/ddp v0.0.0-20170117053602-652027933df4/go.mod h1:lEO7XoHJ/xNRBCxrn4h/CEB67h0kW1B0t4ooP2yrjUA= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/consul/api v1.12.0/go.mod h1:6pVBMo0ebnYdt2S3H87XhekM/HHrUoTD2XXb/VrZVy0= @@ -367,7 +358,6 @@ github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0= github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= github.com/hashicorp/serf v0.9.7/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= @@ -462,17 +452,10 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= -github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= -github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= -github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= @@ -546,8 +529,6 @@ github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/sony/sonyflake v1.0.0 h1:MpU6Ro7tfXwgn2l5eluf9xQvQJDROTBImNCfRXn/YeM= -github.com/sony/sonyflake v1.0.0/go.mod h1:Jv3cfhf/UFtolOTTRd3q4Nl6ENqM+KfyZ5PseKfZGF4= github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/spf13/afero v1.8.2/go.mod h1:CtAatgMJh6bJEIs48Ay/FOnkljP3WeGUG0MC1RfAqwo= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= @@ -671,7 +652,6 @@ golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -695,12 +675,10 @@ golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= @@ -763,7 +741,6 @@ golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -778,14 +755,11 @@ golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -802,7 +776,6 @@ golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1113,11 +1086,9 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/telebot.v3 v3.2.1 h1:3I4LohaAyJBiivGmkfB+CiVu7QFOWkuZ4+KHgO/G3rs= gopkg.in/telebot.v3 v3.2.1/go.mod h1:GJKwwWqp9nSkIVN51eRKU78aB5f5OnQuWdwiIZfPbko= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/notify/rocketchat/rocketchat.go b/notify/rocketchat/rocketchat.go index c13cbb5a54..b0fc881200 100644 --- a/notify/rocketchat/rocketchat.go +++ b/notify/rocketchat/rocketchat.go @@ -14,19 +14,20 @@ package rocketchat import ( + "bytes" "context" + "encoding/json" "fmt" + "io" + "net/http" "os" "strings" "github.com/pkg/errors" - - "github.com/RocketChat/Rocket.Chat.Go.SDK/models" + commoncfg "github.com/prometheus/common/config" "github.com/prometheus/alertmanager/template" - "github.com/RocketChat/Rocket.Chat.Go.SDK/rest" - "github.com/go-kit/log" "github.com/go-kit/log/level" @@ -41,41 +42,66 @@ type Notifier struct { conf *config.RocketchatConfig tmpl *template.Template logger log.Logger - client *rest.Client + 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) } -// New returns a new Rocketchat notification handler. -func New(c *config.RocketchatConfig, t *template.Template, l log.Logger) (*Notifier, error) { - client, err := createRocketchatClient(c) - if err != nil { - return nil, err - } +// 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.RocketchaAttachmentField `json:"fields,omitempty"` + Actions []config.RocketchatAttachmentAction `json:"actions,omitempty"` +} - return &Notifier{ - conf: c, - tmpl: t, - logger: l, - client: client, - retrier: ¬ify.Retrier{}, - }, nil +// 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"` } -func createRocketchatClient(c *config.RocketchatConfig) (*rest.Client, error) { - client := rest.NewClient(c.APIURL.URL, false) - token, err := getToken(c) +// 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 } - tokenid, err := getTokenID(c) + token, err := getToken(c) if err != nil { return nil, err } - err = client.Login(&models.UserCredentials{ID: tokenid, Token: token}) + tokenID, err := getTokenID(c) if err != nil { return nil, err } - return client, nil + 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) { @@ -122,7 +148,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) } level.Warn(n.logger).Log("msg", "Truncated title", "key", key, "max_runes", maxTitleLenRunes) } - att := &models.Attachment{ + att := &Attachment{ Title: title, TitleLink: tmplText(n.conf.TitleLink), Text: tmplText(n.conf.Text), @@ -132,26 +158,33 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) } numFields := len(n.conf.Fields) if numFields > 0 { - fields := make([]models.AttachmentField, numFields) + fields := make([]config.RocketchaAttachmentField, 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] = models.AttachmentField{ + fields[index] = config.RocketchaAttachmentField{ Title: tmplText(field.Title), Value: tmplText(field.Value), - Short: field.Short, + Short: &short, } } att.Fields = fields } - numActions := len(n.conf.Actions) if numActions > 0 { - actions := make([]models.AttachmentAction, numActions) + actions := make([]config.RocketchatAttachmentAction, numActions) for index, action := range n.conf.Actions { - rocketchatAction := models.AttachmentAction{ + rocketchatAction := config.RocketchatAttachmentAction{ Type: "button", // Only button type is supported Text: tmplText(action.Text), - Url: tmplText(action.Url), + URL: tmplText(action.URL), Msg: tmplText(action.Msg), } @@ -160,33 +193,75 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) att.Actions = actions } - req := &models.PostMessage{ + body := &PostMessage{ Channel: n.conf.Channel, - Text: tmplText(n.conf.Text), - Alias: tmplText(n.conf.Alias), Emoji: tmplText(n.conf.Emoji), Avatar: tmplText(n.conf.IconURL), - Attachments: []models.Attachment{*att}, + Attachments: []Attachment{*att}, + } + if err != nil { + return false, err } - response, err := n.client.PostMessage(req) + var buf bytes.Buffer + if err := json.NewEncoder(&buf).Encode(body); err != nil { + return false, err + } + req, err := http.NewRequest("POST", fmt.Sprintf("%s/%s", n.conf.APIURL.String(), "api/v1/chat.postMessage"), &buf) + req.Header.Set("X-Auth-Token", n.token) + req.Header.Set("X-User-Id", n.tokenID) + req.Header.Set("Content-Type", "application/json") if err != nil { - level.Error(n.logger).Log("msg", "Failed to send rocketchat message", "err", err, "response", response.Message.Msg) - return false, fmt.Errorf("failed to send rocketchat message: %w", err) + return false, err } - retry, err := checkResponseError(response) + + resp, err := n.client.Do(req) if err != nil { - err = errors.Wrap(err, fmt.Sprintf("channel %q", req.Channel)) + return true, err + } + + // 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 = errors.Wrap(err, fmt.Sprintf("channel %q", body.Channel)) + 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 = errors.Wrap(err, fmt.Sprintf("channel %q", body.Channel)) return retry, notify.NewErrorWithReason(notify.ClientErrorReason, err) } - return false, nil + return retry, nil } // checkResponseError parses out the error message from Rocketchat API response. -func checkResponseError(resp *rest.MessageResponse) (bool, error) { - if !resp.Status.Success { - return false, fmt.Errorf("error response from Slack: %s", resp.Message.Msg) +func checkResponseError(resp *http.Response) (bool, error) { + body, err := io.ReadAll(resp.Body) + if err != nil { + return true, errors.Wrap(err, "could not read response body") + } + + 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, errors.Wrapf(err, "could not unmarshal JSON response %q", string(body)) + } + 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 index fe4a00f3c9..35033d3db7 100644 --- a/notify/rocketchat/rocketchat_test.go +++ b/notify/rocketchat/rocketchat_test.go @@ -14,38 +14,26 @@ package rocketchat import ( - "context" "fmt" - "net/http" - "net/http/httptest" "net/url" + "os" "testing" - "time" "github.com/go-kit/log" + commoncfg "github.com/prometheus/common/config" "github.com/stretchr/testify/require" - "github.com/prometheus/common/model" - "github.com/prometheus/alertmanager/config" - "github.com/prometheus/alertmanager/notify" "github.com/prometheus/alertmanager/notify/test" - "github.com/prometheus/alertmanager/types" ) -func TestRocketChatRetry(t *testing.T) { - secret := config.Secret("secret") - +func TestRocketchatRetry(t *testing.T) { + secret := config.Secret("xxxxx") notifier, err := New( &config.RocketchatConfig{ - TokenID: &secret, - Token: &secret, - APIURL: &config.URL{ - URL: &url.URL{ - Scheme: "https", - Host: "FAKE_API", - }, - }, + HTTPConfig: &commoncfg.HTTPClientConfig{}, + Token: &secret, + TokenID: &secret, }, test.CreateTmpl(t), log.NewNopLogger(), @@ -58,80 +46,21 @@ func TestRocketChatRetry(t *testing.T) { } } -func TestTelegramNotify(t *testing.T) { - token := config.Secret("secretToken") - tokenID := config.Secret("secretTokenID") +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") - for _, tc := range []struct { - name string - cfg config.RocketchatConfig - expText string - }{ - { - name: "Standard notify", - cfg: config.RocketchatConfig{ - Title: "Test Message", - APIURL: &config.URL{}, - Token: &token, - TokenID: &tokenID, - Channel: "#channel", - }, - expText: "x < y", + _, 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/"}}, }, - } { - t.Run(tc.name, func(t *testing.T) { - srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - require.Equal(t, "/api/v1/chat.postMessage", r.URL.Path) - var err error - require.NoError(t, err) - w.Header().Add("Content-Type", "application/json") - w.Write([]byte(`{ - "ts": 1481748965123, - "channel": "general", - "message": { - "alias": "", - "msg": "This is a test!", - "parseUrls": true, - "groupable": false, - "ts": "2016-12-14T20:56:05.117Z", - "u": { - "_id": "y65tAmHs93aDChMWu", - "username": "graywolf336" - }, - "rid": "GENERAL", - "_updatedAt": "2016-12-14T20:56:05.119Z", - "_id": "jC9chsFddTvsbFQG7" - }, - "success": true - }`)) - })) - defer srv.Close() - u, _ := url.Parse(srv.URL) - - tc.cfg.APIURL = &config.URL{URL: u} - - notifier, err := New(&tc.cfg, test.CreateTmpl(t), log.NewNopLogger()) - require.NoError(t, err) - - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - ctx = notify.WithGroupKey(ctx, "1") - - retry, err := notifier.Notify(ctx, []*types.Alert{ - { - Alert: model.Alert{ - Labels: model.LabelSet{ - "lbl1": "val1", - "lbl3": "val3", - }, - StartsAt: time.Now(), - EndsAt: time.Now().Add(time.Hour), - }, - }, - }...) - - require.False(t, retry) - require.NoError(t, err) - }) - } + test.CreateTmpl(t), + log.NewNopLogger(), + ) + require.NoError(t, err) }