alertmanager: Support Block Kit with Slack notifications

Hi Prometheus

Currently <slack-config> is using Simple formatting.

This is marked by Slack themselves as deprecated (or at least most hints dropped say: Format using Block Kit).

The new way to go seems to be Block-Kit.

I don’t want to ask “Is there a plan?” as this would be a question. I’d like to pose as feature request to add something like:

<slack_config_blocks> which would then accept stuff like:

image

And configuration like so (I am new to Yaml and Go Tmpl):

blocks:
- type: section
  text:
    type: mrkdwn
    text: ":fire: `Critical` alert in *production*: `ELK running out of shards (2
      left)`"
- type: section
  fields:
  - type: mrkdwn
    text: |-
      *Value before:*
      22
  - type: mrkdwn
    text: |-
      *Value now:*
      2
  - type: mrkdwn
    text: |-
      *Action:*
      Contact operations.
  - type: mrkdwn
    text: |-
      *Outcome:*
      X will happen.
- type: actions
  elements:
  - type: button
    text:
      type: plain_text
      emoji: true
      text: Victorops
    style: primary
    value: click_me_123
  - type: button
    text:
      type: plain_text
      emoji: true
      text: Silence
    style: danger
    value: click_me_123

Obvisouly my hardcoded strings would be replaced by {{ .alertProperties }}

Adding this I believe would make our DevOps plans (and hopefully others) dreams come true ❤️

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 127
  • Comments: 17 (3 by maintainers)

Most upvoted comments

Hey, I’m willing to make a PR for that.

I see two ways of doing that:

  • blocks field in slack_config is a tmpl_string that must render the JSON object sent to slack:
blocks: >
  {
    "type": "header",
    "text": {
      "type": "plain_text",
      "text": "{{ template "slack.default.title" . }}",
      "emoji": true
    }
  },
  {{ range .Alerts.Firing }}
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": "*Alert:* '{{ .Annotations.summary }} - `{{ .Labels.severity }}`'\n*Description:* '{{ .Annotations.description }}'"
    }
  }, # Find a way to deal with comma after last block
  {{ end }}
  • blocks field in slack_config is a complex object that replicate Slack API with added options like repeat_for:
blocks:
  - type: header
    text:
      type: plain_text
      text: '{{ template "slack.default.title" . }}'
  - type: section
    text:
      type: mrkdwn
      text: >-
        *Alert:* '{{ .Annotations.summary }} - `{{ .Labels.severity }}`
        *Description:* '{{ .Annotations.description }}'
      repeat_for: firing # Could be firing, resolved or all

As an administrator I prefer option 2, I find it clearer, but it’s way more work to implement it and it’s less flexible than option 1.

What do you think?

It was just bad copy/paste, I fixed the snippets.