Skip to content

feat: allow Slack receiver to edit existing messages#5007

Merged
siavashs merged 18 commits intoprometheus:mainfrom
chazapp:edit-slack-messages
Feb 24, 2026
Merged

feat: allow Slack receiver to edit existing messages#5007
siavashs merged 18 commits intoprometheus:mainfrom
chazapp:edit-slack-messages

Conversation

@chazapp
Copy link
Contributor

@chazapp chazapp commented Feb 11, 2026

Details

This PR adds an update_message config to Slack notifiers, that enables AlertManager to edit previously sent notifications rather than sending new ones for alert status change. It uses the nflog Store introduced in v0.31.0 to persist Slack's message Timestamp and channel ID. If retrieved, the feature will change the API endpoint to chat.update and the request payload to attempt to edit the message.

The PR is backwards compatible and this new feature requires opt-in.


Testing

Test Config
global:
  resolve_timeout: 5m

route:
  receiver: 'slack'
  group_by: ['alertname']
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 12h

receivers:
  - name: 'slack'
    slack_configs:
      - send_resolved: true
        api_url: 'https://slack.com/api/chat.postMessage'
        http_config:
          authorization:
            credentials: 'xoxb-....'
        channel: '#test-channel'
        update_message: true  # This enables message updates! 
        title: '{{ .GroupLabels.alertname }} - {{ .Status | toUpper }}'
        text: |
          {{ if eq .Status "firing" }}
          🔥 *{{ .Alerts.Firing | len }} alert(s) firing*
          {{ else }}
          ✅ *All alerts resolved*
          {{ end }}
          
          {{ range .Alerts }}
          • {{ if .Annotations.summary }}{{ .Annotations.summary }}{{ else }}{{ .Labels.alertname }}{{ end }}
          {{ end }}
        
        color: '{{ if eq .Status "firing" }}danger{{ else }}good{{ end }}'
Test script
#!/bin/bash

## Sends an Alertmanager alert
## Usage:
## ./alert.sh
## ./alert.sh resolve

case $1 in
    "")
	curl -X POST http://localhost:9093/api/v2/alerts -H 'Content-Type: application/json' -d '[{
	  "labels": {"alertname": "TestAlert", "severity": "warning"},
	    "annotations": {"summary": "This alert will resolve in the same message"}
	}]';;
    "resolve")
	curl -X POST http://localhost:9093/api/v2/alerts -H 'Content-Type: application/json' -d '[{
	  "labels": {"alertname": "TestAlert", "severity": "warning"},
	    "annotations": {"summary": "This alert will resolve in the same message"},
	     "endsAt": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
	}]';
esac

Misc

Special thanks to @kruchkov-alexandr for preliminary PR (#4682) and @Spaceman1701 for the nflog data store implementation (#4899).

Alexandre Joris added 2 commits February 11, 2026 19:09
Signed-off-by: Alexandre Joris <chaz@chaz.pro>
Signed-off-by: Alexandre Joris <chaz@chaz.pro>
@chazapp chazapp force-pushed the edit-slack-messages branch from 30954b4 to bf5fe52 Compare February 11, 2026 18:10
Copy link
Contributor

@siavashs siavashs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this LGTM in general.
Just added few comments to potentially improve the logic and config.

Alexandre Joris added 4 commits February 12, 2026 16:16
Signed-off-by: Alexandre Joris <chaz@chaz.pro>
Signed-off-by: Alexandre Joris <chaz@chaz.pro>
Signed-off-by: Alexandre Joris <chaz@chaz.pro>
Signed-off-by: Alexandre Joris <chaz@chaz.pro>
@chazapp chazapp requested a review from siavashs February 12, 2026 16:02
Copy link
Contributor

@siavashs siavashs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the previous comments, I added a few more.

chazapp and others added 7 commits February 17, 2026 10:13
Signed-off-by: Alexandre Joris <chaz@chaz.pro>
Signed-off-by: Alexandre Joris <chaz@chaz.pro>
Signed-off-by: Alexandre Joris <chaz@chaz.pro>
…o warn

Signed-off-by: Alexandre Joris <chaz@chaz.pro>
Co-authored-by: Siavash Safi <git@hosted.run>
Signed-off-by: Alexandre Joris <alexandre.joris@gmail.com>
Signed-off-by: Alexandre Joris <chaz@chaz.pro>
@chazapp chazapp requested a review from siavashs February 17, 2026 11:47
Copy link
Contributor

@siavashs siavashs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

Signed-off-by: Alexandre Joris <chaz@chaz.pro>
@chazapp chazapp force-pushed the edit-slack-messages branch from a0b4aec to 1653d20 Compare February 18, 2026 17:42
Copy link
Contributor

@Spaceman1701 Spaceman1701 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very good to me!

I don't have any problems with the implementation or logic, just a few small code-style requests.

I don't think it should be (or needs to be) included in this PR, but it might be nice for a future change to provide some way for the user's template to discover it's updating an existing message. Unfortunately I think this will be a little complicated, so we can save it for later.

chazapp and others added 2 commits February 23, 2026 10:00
@chazapp chazapp requested a review from Spaceman1701 February 23, 2026 09:11
@siavashs siavashs merged commit 8ad8af9 into prometheus:main Feb 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants