Skip to content

Commit

Permalink
refactor: remove rocketchat SDK
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Maser <christoph.maser+github@gmail.com>
  • Loading branch information
TheMeier committed Nov 27, 2023
1 parent 52679cf commit e44a344
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 188 deletions.
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -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
}
Expand Down
67 changes: 48 additions & 19 deletions config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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" . }}`,
Expand Down Expand Up @@ -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"`
Expand All @@ -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.
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion config/receiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit e44a344

Please sign in to comment.