mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Don't include image_url field with Slack message if empty (#22372)
This commit is contained in:
parent
8c2107cd35
commit
bf908424a7
@ -276,22 +276,25 @@ func (sn *SlackNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
},
|
||||
}
|
||||
}
|
||||
body := map[string]interface{}{
|
||||
"text": evalContext.GetNotificationTitle(),
|
||||
"blocks": blocks,
|
||||
"attachments": []map[string]interface{}{
|
||||
{
|
||||
attachment := map[string]interface{}{
|
||||
"color": evalContext.GetStateModel().Color,
|
||||
"title": evalContext.GetNotificationTitle(),
|
||||
"title_link": ruleURL,
|
||||
"text": msg,
|
||||
"fallback": evalContext.GetNotificationTitle(),
|
||||
"fields": fields,
|
||||
"image_url": imageURL,
|
||||
"footer": "Grafana v" + setting.BuildVersion,
|
||||
"footer_icon": "https://grafana.com/assets/img/fav32.png",
|
||||
"ts": time.Now().Unix(),
|
||||
},
|
||||
}
|
||||
if imageURL != "" {
|
||||
attachment["image_url"] = imageURL
|
||||
}
|
||||
body := map[string]interface{}{
|
||||
"text": evalContext.GetNotificationTitle(),
|
||||
"blocks": blocks,
|
||||
"attachments": []map[string]interface{}{
|
||||
attachment,
|
||||
},
|
||||
"parse": "full", // to linkify urls, users and channels in alert message.
|
||||
}
|
||||
@ -313,6 +316,7 @@ func (sn *SlackNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd := &models.SendWebhookSync{Url: sn.URL, Body: string(data)}
|
||||
if err := bus.DispatchCtx(evalContext.Ctx, cmd); err != nil {
|
||||
sn.log.Error("Failed to send slack notification", "error", err, "webhook", sn.Name)
|
||||
|
Loading…
Reference in New Issue
Block a user