Skip to content

Commit d4009f5

Browse files
sschnegotjosh
andauthored
feat(3920): add msteamsv2 receiver (prometheus#4024)
* feat(3920): add msteamsv2 receiver Signed-off-by: Simon Schneider <[email protected]> * Don't use `fmt.Errorf` when there's no formatting required on `config/config.go` Signed-off-by: gotjosh <[email protected]> * Don't use `fmt.Errorf` when there's no formatting required on `config/notifiers.go` Signed-off-by: gotjosh <[email protected]> * Remove additional documentation steps Signed-off-by: gotjosh <[email protected]> * add more info to the documentation Signed-off-by: gotjosh <[email protected]> * Change documentation links to convey the message better Signed-off-by: gotjosh <[email protected]> --------- Signed-off-by: Simon Schneider <[email protected]> Signed-off-by: gotjosh <[email protected]> Co-authored-by: gotjosh <[email protected]>
1 parent 3d66826 commit d4009f5

File tree

9 files changed

+577
-66
lines changed

9 files changed

+577
-66
lines changed

asset/assets_vfsdata.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/config.go

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ func resolveFilepaths(baseDir string, cfg *Config) {
263263
for _, cfg := range receiver.MSTeamsConfigs {
264264
cfg.HTTPConfig.SetDirectory(baseDir)
265265
}
266+
for _, cfg := range receiver.MSTeamsV2Configs {
267+
cfg.HTTPConfig.SetDirectory(baseDir)
268+
}
266269
for _, cfg := range receiver.JiraConfigs {
267270
cfg.HTTPConfig.SetDirectory(baseDir)
268271
}
@@ -282,7 +285,7 @@ func (mt *MuteTimeInterval) UnmarshalYAML(unmarshal func(interface{}) error) err
282285
return err
283286
}
284287
if mt.Name == "" {
285-
return fmt.Errorf("missing name in mute time interval")
288+
return errors.New("missing name in mute time interval")
286289
}
287290
return nil
288291
}
@@ -300,7 +303,7 @@ func (ti *TimeInterval) UnmarshalYAML(unmarshal func(interface{}) error) error {
300303
return err
301304
}
302305
if ti.Name == "" {
303-
return fmt.Errorf("missing name in time interval")
306+
return errors.New("missing name in time interval")
304307
}
305308
return nil
306309
}
@@ -346,19 +349,19 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
346349
}
347350

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

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

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

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

364367
names := map[string]struct{}{}
@@ -378,13 +381,13 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
378381
}
379382
if ec.Smarthost.String() == "" {
380383
if c.Global.SMTPSmarthost.String() == "" {
381-
return fmt.Errorf("no global SMTP smarthost set")
384+
return errors.New("no global SMTP smarthost set")
382385
}
383386
ec.Smarthost = c.Global.SMTPSmarthost
384387
}
385388
if ec.From == "" {
386389
if c.Global.SMTPFrom == "" {
387-
return fmt.Errorf("no global SMTP from set")
390+
return errors.New("no global SMTP from set")
388391
}
389392
ec.From = c.Global.SMTPFrom
390393
}
@@ -415,7 +418,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
415418
}
416419
if sc.APIURL == nil && len(sc.APIURLFile) == 0 {
417420
if c.Global.SlackAPIURL == nil && len(c.Global.SlackAPIURLFile) == 0 {
418-
return fmt.Errorf("no global Slack API URL set either inline or in a file")
421+
return errors.New("no global Slack API URL set either inline or in a file")
419422
}
420423
sc.APIURL = c.Global.SlackAPIURL
421424
sc.APIURLFile = c.Global.SlackAPIURLFile
@@ -432,7 +435,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
432435
}
433436
if pdc.URL == nil {
434437
if c.Global.PagerdutyURL == nil {
435-
return fmt.Errorf("no global PagerDuty URL set")
438+
return errors.New("no global PagerDuty URL set")
436439
}
437440
pdc.URL = c.Global.PagerdutyURL
438441
}
@@ -443,7 +446,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
443446
}
444447
if ogc.APIURL == nil {
445448
if c.Global.OpsGenieAPIURL == nil {
446-
return fmt.Errorf("no global OpsGenie URL set")
449+
return errors.New("no global OpsGenie URL set")
447450
}
448451
ogc.APIURL = c.Global.OpsGenieAPIURL
449452
}
@@ -452,7 +455,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
452455
}
453456
if ogc.APIKey == "" && len(ogc.APIKeyFile) == 0 {
454457
if c.Global.OpsGenieAPIKey == "" && len(c.Global.OpsGenieAPIKeyFile) == 0 {
455-
return fmt.Errorf("no global OpsGenie API Key set either inline or in a file")
458+
return errors.New("no global OpsGenie API Key set either inline or in a file")
456459
}
457460
ogc.APIKey = c.Global.OpsGenieAPIKey
458461
ogc.APIKeyFile = c.Global.OpsGenieAPIKeyFile
@@ -465,21 +468,21 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
465468

466469
if wcc.APIURL == nil {
467470
if c.Global.WeChatAPIURL == nil {
468-
return fmt.Errorf("no global Wechat URL set")
471+
return errors.New("no global Wechat URL set")
469472
}
470473
wcc.APIURL = c.Global.WeChatAPIURL
471474
}
472475

473476
if wcc.APISecret == "" {
474477
if c.Global.WeChatAPISecret == "" {
475-
return fmt.Errorf("no global Wechat ApiSecret set")
478+
return errors.New("no global Wechat ApiSecret set")
476479
}
477480
wcc.APISecret = c.Global.WeChatAPISecret
478481
}
479482

480483
if wcc.CorpID == "" {
481484
if c.Global.WeChatAPICorpID == "" {
482-
return fmt.Errorf("no global Wechat CorpID set")
485+
return errors.New("no global Wechat CorpID set")
483486
}
484487
wcc.CorpID = c.Global.WeChatAPICorpID
485488
}
@@ -494,7 +497,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
494497
}
495498
if voc.APIURL == nil {
496499
if c.Global.VictorOpsAPIURL == nil {
497-
return fmt.Errorf("no global VictorOps URL set")
500+
return errors.New("no global VictorOps URL set")
498501
}
499502
voc.APIURL = c.Global.VictorOpsAPIURL
500503
}
@@ -503,7 +506,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
503506
}
504507
if voc.APIKey == "" && len(voc.APIKeyFile) == 0 {
505508
if c.Global.VictorOpsAPIKey == "" && len(c.Global.VictorOpsAPIKeyFile) == 0 {
506-
return fmt.Errorf("no global VictorOps API Key set")
509+
return errors.New("no global VictorOps API Key set")
507510
}
508511
voc.APIKey = c.Global.VictorOpsAPIKey
509512
voc.APIKeyFile = c.Global.VictorOpsAPIKeyFile
@@ -528,7 +531,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
528531
discord.HTTPConfig = c.Global.HTTPConfig
529532
}
530533
if discord.WebhookURL == nil && len(discord.WebhookURLFile) == 0 {
531-
return fmt.Errorf("no discord webhook URL or URLFile provided")
534+
return errors.New("no discord webhook URL or URLFile provided")
532535
}
533536
}
534537
for _, webex := range rcv.WebexConfigs {
@@ -537,7 +540,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
537540
}
538541
if webex.APIURL == nil {
539542
if c.Global.WebexAPIURL == nil {
540-
return fmt.Errorf("no global Webex URL set")
543+
return errors.New("no global Webex URL set")
541544
}
542545

543546
webex.APIURL = c.Global.WebexAPIURL
@@ -548,7 +551,15 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
548551
msteams.HTTPConfig = c.Global.HTTPConfig
549552
}
550553
if msteams.WebhookURL == nil && len(msteams.WebhookURLFile) == 0 {
551-
return fmt.Errorf("no msteams webhook URL or URLFile provided")
554+
return errors.New("no msteams webhook URL or URLFile provided")
555+
}
556+
}
557+
for _, msteamsv2 := range rcv.MSTeamsV2Configs {
558+
if msteamsv2.HTTPConfig == nil {
559+
msteamsv2.HTTPConfig = c.Global.HTTPConfig
560+
}
561+
if msteamsv2.WebhookURL == nil && len(msteamsv2.WebhookURLFile) == 0 {
562+
return errors.New("no msteamsv2 webhook URL or URLFile provided")
552563
}
553564
}
554565
for _, jira := range rcv.JiraConfigs {
@@ -557,7 +568,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
557568
}
558569
if jira.APIURL == nil {
559570
if c.Global.JiraAPIURL == nil {
560-
return fmt.Errorf("no global Jira Cloud URL set")
571+
return errors.New("no global Jira Cloud URL set")
561572
}
562573
jira.APIURL = c.Global.JiraAPIURL
563574
}
@@ -569,20 +580,20 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
569580
// The root route must not have any matchers as it is the fallback node
570581
// for all alerts.
571582
if c.Route == nil {
572-
return fmt.Errorf("no routes provided")
583+
return errors.New("no routes provided")
573584
}
574585
if len(c.Route.Receiver) == 0 {
575-
return fmt.Errorf("root route must specify a default receiver")
586+
return errors.New("root route must specify a default receiver")
576587
}
577588
if len(c.Route.Match) > 0 || len(c.Route.MatchRE) > 0 || len(c.Route.Matchers) > 0 {
578-
return fmt.Errorf("root route must not have any matchers")
589+
return errors.New("root route must not have any matchers")
579590
}
580591
if len(c.Route.MuteTimeIntervals) > 0 {
581-
return fmt.Errorf("root route must not have any mute time intervals")
592+
return errors.New("root route must not have any mute time intervals")
582593
}
583594

584595
if len(c.Route.ActiveTimeIntervals) > 0 {
585-
return fmt.Errorf("root route must not have any active time intervals")
596+
return errors.New("root route must not have any active time intervals")
586597
}
587598

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

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

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

863874
if r.GroupInterval != nil && time.Duration(*r.GroupInterval) == time.Duration(0) {
864-
return fmt.Errorf("group_interval cannot be zero")
875+
return errors.New("group_interval cannot be zero")
865876
}
866877
if r.RepeatInterval != nil && time.Duration(*r.RepeatInterval) == time.Duration(0) {
867-
return fmt.Errorf("repeat_interval cannot be zero")
878+
return errors.New("repeat_interval cannot be zero")
868879
}
869880

870881
return nil
@@ -935,6 +946,7 @@ type Receiver struct {
935946
TelegramConfigs []*TelegramConfig `yaml:"telegram_configs,omitempty" json:"telegram_configs,omitempty"`
936947
WebexConfigs []*WebexConfig `yaml:"webex_configs,omitempty" json:"webex_configs,omitempty"`
937948
MSTeamsConfigs []*MSTeamsConfig `yaml:"msteams_configs,omitempty" json:"msteams_configs,omitempty"`
949+
MSTeamsV2Configs []*MSTeamsV2Config `yaml:"msteamsv2_configs,omitempty" json:"msteamsv2_configs,omitempty"`
938950
JiraConfigs []*JiraConfig `yaml:"jira_configs,omitempty" json:"jira_configs,omitempty"`
939951
}
940952

@@ -945,7 +957,7 @@ func (c *Receiver) UnmarshalYAML(unmarshal func(interface{}) error) error {
945957
return err
946958
}
947959
if c.Name == "" {
948-
return fmt.Errorf("missing name in receiver")
960+
return errors.New("missing name in receiver")
949961
}
950962
return nil
951963
}

0 commit comments

Comments
 (0)