Skip to content

Commit

Permalink
Alerting: Adding color option to slack contact point (#2010)
Browse files Browse the repository at this point in the history
* Adding color option to slack contact point

* Generating docs
  • Loading branch information
wymangr authored Jan 31, 2025
1 parent 70e344b commit 397e224
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/resources/contact_point.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ Read-Only:

Optional:

- `color` (String) Templated color of the slack message.
- `disable_resolve_message` (Boolean) Whether to disable sending resolve messages. Defaults to `false`.
- `endpoint_url` (String) Use this to override the Slack API endpoint URL to send requests to.
- `icon_emoji` (String) The name of a Slack workspace emoji to use as the bot icon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ resource "grafana_contact_point" "receiver_types" {
mention_channel = "here"
mention_users = "user"
mention_groups = "group"
color = "color"
}

teams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,11 @@ func (s slackNotifier) schema() *schema.Resource {
Optional: true,
Description: "Comma-separated list of groups to mention in the message.",
}
r.Schema["color"] = &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "Templated color of the slack message.",
}
return r
}

Expand All @@ -1533,6 +1538,7 @@ func (s slackNotifier) pack(p *models.EmbeddedContactPoint, data *schema.Resourc
packNotifierStringField(&settings, &notifier, "mentionChannel", "mention_channel")
packNotifierStringField(&settings, &notifier, "mentionUsers", "mention_users")
packNotifierStringField(&settings, &notifier, "mentionGroups", "mention_groups")
packNotifierStringField(&settings, &notifier, "color", "color")

packSecureFields(notifier, getNotifierConfigFromStateWithUID(data, s, p.UID), s.meta().secureFields)

Expand All @@ -1557,6 +1563,7 @@ func (s slackNotifier) unpack(raw interface{}, name string) *models.EmbeddedCont
unpackNotifierStringField(&json, &settings, "mention_channel", "mentionChannel")
unpackNotifierStringField(&json, &settings, "mention_users", "mentionUsers")
unpackNotifierStringField(&json, &settings, "mention_groups", "mentionGroups")
unpackNotifierStringField(&json, &settings, "color", "color")

return &models.EmbeddedContactPoint{
UID: uid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func TestAccContactPoint_notifiers(t *testing.T) {
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "slack.0.mention_channel", "here"),
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "slack.0.mention_users", "user"),
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "slack.0.mention_groups", "group"),
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "slack.0.color", "color"),
// teams
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "teams.#", "1"),
resource.TestCheckResourceAttr("grafana_contact_point.receiver_types", "teams.0.url", "http://teams-webhook"),
Expand Down

0 comments on commit 397e224

Please sign in to comment.