Skip to content

Commit

Permalink
allow webex roomID from template (prometheus#3801)
Browse files Browse the repository at this point in the history
Signed-off-by: bakito <github@bakito.ch>
  • Loading branch information
bakito authored and TheMeier committed Sep 29, 2024
1 parent 40257ab commit b87a2ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ API](http://admin.wechat.com/wiki/index.php?title=Customer_Service_Messages).
[ api_url: <string> | default = global.webex_api_url ]
# ID of the Webex Teams room where to send the messages.
room_id: <string>
room_id: <tmpl_string>
# Message template.
[ message: <tmpl_string> default = '{{ template "webex.default.message" .}}' ]
Expand Down
2 changes: 1 addition & 1 deletion notify/webex/webex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion notify/webex/webex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{
{
Expand Down

0 comments on commit b87a2ca

Please sign in to comment.