diff --git a/docs/configuration.md b/docs/configuration.md index 134f686bc8..d72257e9b8 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1457,7 +1457,7 @@ API](http://admin.wechat.com/wiki/index.php?title=Customer_Service_Messages). [ api_url: | default = global.webex_api_url ] # ID of the Webex Teams room where to send the messages. -room_id: +room_id: # Message template. [ message: default = '{{ template "webex.default.message" .}}' ] diff --git a/notify/webex/webex.go b/notify/webex/webex.go index 347dd63a47..486a13bf78 100644 --- a/notify/webex/webex.go +++ b/notify/webex/webex.go @@ -93,7 +93,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) w := webhook{ Markdown: message, - RoomID: n.conf.RoomID, + RoomID: tmpl(n.conf.RoomID), } var payload bytes.Buffer diff --git a/notify/webex/webex_test.go b/notify/webex/webex_test.go index 161751fb50..688edcc3cd 100644 --- a/notify/webex/webex_test.go +++ b/notify/webex/webex_test.go @@ -81,13 +81,31 @@ func TestWebexTemplating(t *testing.T) { expHeader: "Bearer anewsecret", }, { - name: "with templating errors, it fails.", + name: "with message templating errors, it fails.", cfg: &config.WebexConfig{ Message: "{{ ", }, commonCfg: &commoncfg.HTTPClientConfig{}, errMsg: "template: :1: unclosed action", }, + { + name: "with a valid roomID set, the roomID is used accordingly.", + cfg: &config.WebexConfig{ + RoomID: "my-room-id", + }, + commonCfg: &commoncfg.HTTPClientConfig{}, + expJSON: `{"markdown":"", "roomId":"my-room-id"}`, + retry: false, + }, + { + name: "with a valid roomID template, the roomID is used accordingly.", + cfg: &config.WebexConfig{ + RoomID: "{{.GroupLabels.webex_room_id}}", + }, + commonCfg: &commoncfg.HTTPClientConfig{}, + expJSON: `{"markdown":"", "roomId":"group-label-room-id"}`, + retry: false, + }, } for _, tt := range tc { @@ -111,6 +129,7 @@ func TestWebexTemplating(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() ctx = notify.WithGroupKey(ctx, "1") + ctx = notify.WithGroupLabels(ctx, model.LabelSet{"webex_room_id": "group-label-room-id"}) ok, err := notifierWebex.Notify(ctx, []*types.Alert{ {