Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow webex roomID from template #3801

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
allow webex roomID from template
Signed-off-by: bakito <github@bakito.ch>
  • Loading branch information
bakito committed Apr 10, 2024
commit b70194ad1d339467db48eb416bb5ca4b938e1556
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,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