Skip to content

Commit

Permalink
feat(3920): add msteamsv2 receiver (prometheus#4024)
Browse files Browse the repository at this point in the history
* feat(3920): add msteamsv2 receiver

Signed-off-by: Simon Schneider <github@simon-schneider.eu>

* Don't use `fmt.Errorf` when there's no formatting required on `config/config.go`

Signed-off-by: gotjosh <josue.abreu@gmail.com>

* Don't use `fmt.Errorf` when there's no formatting required on `config/notifiers.go`

Signed-off-by: gotjosh <josue.abreu@gmail.com>

* Remove additional documentation steps

Signed-off-by: gotjosh <josue.abreu@gmail.com>

* add more info to the documentation

Signed-off-by: gotjosh <josue.abreu@gmail.com>

* Change documentation links to convey the message better

Signed-off-by: gotjosh <josue.abreu@gmail.com>

---------

Signed-off-by: Simon Schneider <github@simon-schneider.eu>
Signed-off-by: gotjosh <josue.abreu@gmail.com>
Co-authored-by: gotjosh <josue.abreu@gmail.com>
  • Loading branch information
2 people authored and mogoll92 committed Oct 23, 2024
1 parent 63fd487 commit e4fb0fb
Show file tree
Hide file tree
Showing 9 changed files with 577 additions and 66 deletions.
4 changes: 2 additions & 2 deletions asset/assets_vfsdata.go

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

74 changes: 43 additions & 31 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ func resolveFilepaths(baseDir string, cfg *Config) {
for _, cfg := range receiver.MSTeamsConfigs {
cfg.HTTPConfig.SetDirectory(baseDir)
}
for _, cfg := range receiver.MSTeamsV2Configs {
cfg.HTTPConfig.SetDirectory(baseDir)
}
for _, cfg := range receiver.JiraConfigs {
cfg.HTTPConfig.SetDirectory(baseDir)
}
Expand All @@ -282,7 +285,7 @@ func (mt *MuteTimeInterval) UnmarshalYAML(unmarshal func(interface{}) error) err
return err
}
if mt.Name == "" {
return fmt.Errorf("missing name in mute time interval")
return errors.New("missing name in mute time interval")
}
return nil
}
Expand All @@ -300,7 +303,7 @@ func (ti *TimeInterval) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err
}
if ti.Name == "" {
return fmt.Errorf("missing name in time interval")
return errors.New("missing name in time interval")
}
return nil
}
Expand Down Expand Up @@ -346,19 +349,19 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}

if c.Global.SlackAPIURL != nil && len(c.Global.SlackAPIURLFile) > 0 {
return fmt.Errorf("at most one of slack_api_url & slack_api_url_file must be configured")
return errors.New("at most one of slack_api_url & slack_api_url_file must be configured")
}

if c.Global.OpsGenieAPIKey != "" && len(c.Global.OpsGenieAPIKeyFile) > 0 {
return fmt.Errorf("at most one of opsgenie_api_key & opsgenie_api_key_file must be configured")
return errors.New("at most one of opsgenie_api_key & opsgenie_api_key_file must be configured")
}

if c.Global.VictorOpsAPIKey != "" && len(c.Global.VictorOpsAPIKeyFile) > 0 {
return fmt.Errorf("at most one of victorops_api_key & victorops_api_key_file must be configured")
return errors.New("at most one of victorops_api_key & victorops_api_key_file must be configured")
}

if len(c.Global.SMTPAuthPassword) > 0 && len(c.Global.SMTPAuthPasswordFile) > 0 {
return fmt.Errorf("at most one of smtp_auth_password & smtp_auth_password_file must be configured")
return errors.New("at most one of smtp_auth_password & smtp_auth_password_file must be configured")
}

names := map[string]struct{}{}
Expand All @@ -378,13 +381,13 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
if ec.Smarthost.String() == "" {
if c.Global.SMTPSmarthost.String() == "" {
return fmt.Errorf("no global SMTP smarthost set")
return errors.New("no global SMTP smarthost set")
}
ec.Smarthost = c.Global.SMTPSmarthost
}
if ec.From == "" {
if c.Global.SMTPFrom == "" {
return fmt.Errorf("no global SMTP from set")
return errors.New("no global SMTP from set")
}
ec.From = c.Global.SMTPFrom
}
Expand Down Expand Up @@ -415,7 +418,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
if sc.APIURL == nil && len(sc.APIURLFile) == 0 {
if c.Global.SlackAPIURL == nil && len(c.Global.SlackAPIURLFile) == 0 {
return fmt.Errorf("no global Slack API URL set either inline or in a file")
return errors.New("no global Slack API URL set either inline or in a file")
}
sc.APIURL = c.Global.SlackAPIURL
sc.APIURLFile = c.Global.SlackAPIURLFile
Expand All @@ -432,7 +435,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
if pdc.URL == nil {
if c.Global.PagerdutyURL == nil {
return fmt.Errorf("no global PagerDuty URL set")
return errors.New("no global PagerDuty URL set")
}
pdc.URL = c.Global.PagerdutyURL
}
Expand All @@ -443,7 +446,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
if ogc.APIURL == nil {
if c.Global.OpsGenieAPIURL == nil {
return fmt.Errorf("no global OpsGenie URL set")
return errors.New("no global OpsGenie URL set")
}
ogc.APIURL = c.Global.OpsGenieAPIURL
}
Expand All @@ -452,7 +455,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
if ogc.APIKey == "" && len(ogc.APIKeyFile) == 0 {
if c.Global.OpsGenieAPIKey == "" && len(c.Global.OpsGenieAPIKeyFile) == 0 {
return fmt.Errorf("no global OpsGenie API Key set either inline or in a file")
return errors.New("no global OpsGenie API Key set either inline or in a file")
}
ogc.APIKey = c.Global.OpsGenieAPIKey
ogc.APIKeyFile = c.Global.OpsGenieAPIKeyFile
Expand All @@ -465,21 +468,21 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {

if wcc.APIURL == nil {
if c.Global.WeChatAPIURL == nil {
return fmt.Errorf("no global Wechat URL set")
return errors.New("no global Wechat URL set")
}
wcc.APIURL = c.Global.WeChatAPIURL
}

if wcc.APISecret == "" {
if c.Global.WeChatAPISecret == "" {
return fmt.Errorf("no global Wechat ApiSecret set")
return errors.New("no global Wechat ApiSecret set")
}
wcc.APISecret = c.Global.WeChatAPISecret
}

if wcc.CorpID == "" {
if c.Global.WeChatAPICorpID == "" {
return fmt.Errorf("no global Wechat CorpID set")
return errors.New("no global Wechat CorpID set")
}
wcc.CorpID = c.Global.WeChatAPICorpID
}
Expand All @@ -494,7 +497,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
if voc.APIURL == nil {
if c.Global.VictorOpsAPIURL == nil {
return fmt.Errorf("no global VictorOps URL set")
return errors.New("no global VictorOps URL set")
}
voc.APIURL = c.Global.VictorOpsAPIURL
}
Expand All @@ -503,7 +506,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
if voc.APIKey == "" && len(voc.APIKeyFile) == 0 {
if c.Global.VictorOpsAPIKey == "" && len(c.Global.VictorOpsAPIKeyFile) == 0 {
return fmt.Errorf("no global VictorOps API Key set")
return errors.New("no global VictorOps API Key set")
}
voc.APIKey = c.Global.VictorOpsAPIKey
voc.APIKeyFile = c.Global.VictorOpsAPIKeyFile
Expand All @@ -528,7 +531,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
discord.HTTPConfig = c.Global.HTTPConfig
}
if discord.WebhookURL == nil && len(discord.WebhookURLFile) == 0 {
return fmt.Errorf("no discord webhook URL or URLFile provided")
return errors.New("no discord webhook URL or URLFile provided")
}
}
for _, webex := range rcv.WebexConfigs {
Expand All @@ -537,7 +540,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
if webex.APIURL == nil {
if c.Global.WebexAPIURL == nil {
return fmt.Errorf("no global Webex URL set")
return errors.New("no global Webex URL set")
}

webex.APIURL = c.Global.WebexAPIURL
Expand All @@ -548,7 +551,15 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
msteams.HTTPConfig = c.Global.HTTPConfig
}
if msteams.WebhookURL == nil && len(msteams.WebhookURLFile) == 0 {
return fmt.Errorf("no msteams webhook URL or URLFile provided")
return errors.New("no msteams webhook URL or URLFile provided")
}
}
for _, msteamsv2 := range rcv.MSTeamsV2Configs {
if msteamsv2.HTTPConfig == nil {
msteamsv2.HTTPConfig = c.Global.HTTPConfig
}
if msteamsv2.WebhookURL == nil && len(msteamsv2.WebhookURLFile) == 0 {
return errors.New("no msteamsv2 webhook URL or URLFile provided")
}
}
for _, jira := range rcv.JiraConfigs {
Expand All @@ -557,7 +568,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
}
if jira.APIURL == nil {
if c.Global.JiraAPIURL == nil {
return fmt.Errorf("no global Jira Cloud URL set")
return errors.New("no global Jira Cloud URL set")
}
jira.APIURL = c.Global.JiraAPIURL
}
Expand All @@ -569,20 +580,20 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
// The root route must not have any matchers as it is the fallback node
// for all alerts.
if c.Route == nil {
return fmt.Errorf("no routes provided")
return errors.New("no routes provided")
}
if len(c.Route.Receiver) == 0 {
return fmt.Errorf("root route must specify a default receiver")
return errors.New("root route must specify a default receiver")
}
if len(c.Route.Match) > 0 || len(c.Route.MatchRE) > 0 || len(c.Route.Matchers) > 0 {
return fmt.Errorf("root route must not have any matchers")
return errors.New("root route must not have any matchers")
}
if len(c.Route.MuteTimeIntervals) > 0 {
return fmt.Errorf("root route must not have any mute time intervals")
return errors.New("root route must not have any mute time intervals")
}

if len(c.Route.ActiveTimeIntervals) > 0 {
return fmt.Errorf("root route must not have any active time intervals")
return errors.New("root route must not have any active time intervals")
}

// Validate that all receivers used in the routing tree are defined.
Expand Down Expand Up @@ -685,7 +696,7 @@ func parseURL(s string) (*URL, error) {
return nil, fmt.Errorf("unsupported scheme %q for URL", u.Scheme)
}
if u.Host == "" {
return nil, fmt.Errorf("missing host for URL")
return nil, errors.New("missing host for URL")
}
return &URL{u}, nil
}
Expand Down Expand Up @@ -848,7 +859,7 @@ func (r *Route) UnmarshalYAML(unmarshal func(interface{}) error) error {
}

if len(r.GroupBy) > 0 && r.GroupByAll {
return fmt.Errorf("cannot have wildcard group_by (`...`) and other other labels at the same time")
return errors.New("cannot have wildcard group_by (`...`) and other other labels at the same time")
}

groupBy := map[model.LabelName]struct{}{}
Expand All @@ -861,10 +872,10 @@ func (r *Route) UnmarshalYAML(unmarshal func(interface{}) error) error {
}

if r.GroupInterval != nil && time.Duration(*r.GroupInterval) == time.Duration(0) {
return fmt.Errorf("group_interval cannot be zero")
return errors.New("group_interval cannot be zero")
}
if r.RepeatInterval != nil && time.Duration(*r.RepeatInterval) == time.Duration(0) {
return fmt.Errorf("repeat_interval cannot be zero")
return errors.New("repeat_interval cannot be zero")
}

return nil
Expand Down Expand Up @@ -935,6 +946,7 @@ type Receiver struct {
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"`
}

Expand All @@ -945,7 +957,7 @@ func (c *Receiver) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err
}
if c.Name == "" {
return fmt.Errorf("missing name in receiver")
return errors.New("missing name in receiver")
}
return nil
}
Expand Down
Loading

0 comments on commit e4fb0fb

Please sign in to comment.