mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix Slack push notifications (#52391)
This commit fixes push notifications for Slack which used to show "This content cannot be displayed". The text field is shown in both the message and the push notification.
This commit is contained in:
parent
c087198b1b
commit
094dfd0d4d
@ -166,6 +166,7 @@ func NewSlackNotifier(config *SlackConfig,
|
|||||||
// slackMessage is the slackMessage for sending a slack notification.
|
// slackMessage is the slackMessage for sending a slack notification.
|
||||||
type slackMessage struct {
|
type slackMessage struct {
|
||||||
Channel string `json:"channel,omitempty"`
|
Channel string `json:"channel,omitempty"`
|
||||||
|
Text string `json:"text,omitempty"`
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
IconEmoji string `json:"icon_emoji,omitempty"`
|
IconEmoji string `json:"icon_emoji,omitempty"`
|
||||||
IconURL string `json:"icon_url,omitempty"`
|
IconURL string `json:"icon_url,omitempty"`
|
||||||
@ -299,6 +300,7 @@ func (sn *SlackNotifier) buildSlackMessage(ctx context.Context, alrts []*types.A
|
|||||||
|
|
||||||
req := &slackMessage{
|
req := &slackMessage{
|
||||||
Channel: tmpl(sn.Recipient),
|
Channel: tmpl(sn.Recipient),
|
||||||
|
Text: tmpl(sn.Title),
|
||||||
Username: tmpl(sn.Username),
|
Username: tmpl(sn.Username),
|
||||||
IconEmoji: tmpl(sn.IconEmoji),
|
IconEmoji: tmpl(sn.IconEmoji),
|
||||||
IconURL: tmpl(sn.IconURL),
|
IconURL: tmpl(sn.IconURL),
|
||||||
|
@ -64,6 +64,7 @@ func TestSlackNotifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expMsg: &slackMessage{
|
expMsg: &slackMessage{
|
||||||
Channel: "#testchannel",
|
Channel: "#testchannel",
|
||||||
|
Text: "[FIRING:1] (val1)",
|
||||||
Username: "Grafana",
|
Username: "Grafana",
|
||||||
IconEmoji: ":emoji:",
|
IconEmoji: ":emoji:",
|
||||||
Attachments: []attachment{
|
Attachments: []attachment{
|
||||||
@ -99,6 +100,7 @@ func TestSlackNotifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expMsg: &slackMessage{
|
expMsg: &slackMessage{
|
||||||
Channel: "#testchannel",
|
Channel: "#testchannel",
|
||||||
|
Text: "[FIRING:1] (val1)",
|
||||||
Username: "Grafana",
|
Username: "Grafana",
|
||||||
IconEmoji: ":emoji:",
|
IconEmoji: ":emoji:",
|
||||||
Attachments: []attachment{
|
Attachments: []attachment{
|
||||||
@ -134,6 +136,7 @@ func TestSlackNotifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expMsg: &slackMessage{
|
expMsg: &slackMessage{
|
||||||
Channel: "#testchannel",
|
Channel: "#testchannel",
|
||||||
|
Text: "[FIRING:1] (val1)",
|
||||||
Username: "Grafana",
|
Username: "Grafana",
|
||||||
IconEmoji: ":emoji:",
|
IconEmoji: ":emoji:",
|
||||||
Attachments: []attachment{
|
Attachments: []attachment{
|
||||||
@ -177,6 +180,7 @@ func TestSlackNotifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expMsg: &slackMessage{
|
expMsg: &slackMessage{
|
||||||
Channel: "#testchannel",
|
Channel: "#testchannel",
|
||||||
|
Text: "2 firing, 0 resolved",
|
||||||
Username: "Grafana",
|
Username: "Grafana",
|
||||||
IconEmoji: ":emoji:",
|
IconEmoji: ":emoji:",
|
||||||
Attachments: []attachment{
|
Attachments: []attachment{
|
||||||
@ -225,6 +229,7 @@ func TestSlackNotifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expMsg: &slackMessage{
|
expMsg: &slackMessage{
|
||||||
Channel: "#testchannel",
|
Channel: "#testchannel",
|
||||||
|
Text: "[FIRING:1] (val1)",
|
||||||
Username: "Grafana",
|
Username: "Grafana",
|
||||||
IconEmoji: ":emoji:",
|
IconEmoji: ":emoji:",
|
||||||
Attachments: []attachment{
|
Attachments: []attachment{
|
||||||
|
@ -2099,6 +2099,7 @@ var expNonEmailNotifications = map[string][]string{
|
|||||||
"slack_recv1/slack_test_without_token": {
|
"slack_recv1/slack_test_without_token": {
|
||||||
`{
|
`{
|
||||||
"channel": "#test-channel",
|
"channel": "#test-channel",
|
||||||
|
"text": "Integration Test [FIRING:1] SlackAlert1 (default)",
|
||||||
"username": "Integration Test",
|
"username": "Integration Test",
|
||||||
"icon_emoji": "🚀",
|
"icon_emoji": "🚀",
|
||||||
"icon_url": "https://awesomeemoji.com/rocket",
|
"icon_url": "https://awesomeemoji.com/rocket",
|
||||||
@ -2128,6 +2129,7 @@ var expNonEmailNotifications = map[string][]string{
|
|||||||
"slack_recvX/slack_testX": {
|
"slack_recvX/slack_testX": {
|
||||||
`{
|
`{
|
||||||
"channel": "#test-channel",
|
"channel": "#test-channel",
|
||||||
|
"text": "[FIRING:1] SlackAlert2 (default)",
|
||||||
"username": "Integration Test",
|
"username": "Integration Test",
|
||||||
"attachments": [
|
"attachments": [
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user