mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 14:12:15 +08:00
Alerting: Fix notifications for Microsoft Teams (#53810)
This commit fixes notifications for Microsoft Teams where notifications would just contain "Card" rather than the title.
This commit is contained in:
@ -43,6 +43,7 @@ const (
|
|||||||
// AdaptiveCardsMessage represents a message for adaptive cards.
|
// AdaptiveCardsMessage represents a message for adaptive cards.
|
||||||
type AdaptiveCardsMessage struct {
|
type AdaptiveCardsMessage struct {
|
||||||
Attachments []AdaptiveCardsAttachment `json:"attachments"`
|
Attachments []AdaptiveCardsAttachment `json:"attachments"`
|
||||||
|
Summary string `json:"summary,omitempty"` // Summary is the text shown in notifications
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,6 +318,9 @@ func (tn *TeamsNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
msg := NewAdaptiveCardsMessage(card)
|
||||||
|
msg.Summary = tmpl(tn.Title)
|
||||||
|
|
||||||
// This check for tmplErr must happen before templating the URL
|
// This check for tmplErr must happen before templating the URL
|
||||||
if tmplErr != nil {
|
if tmplErr != nil {
|
||||||
tn.log.Warn("failed to template Teams message", "err", tmplErr.Error())
|
tn.log.Warn("failed to template Teams message", "err", tmplErr.Error())
|
||||||
@ -329,7 +333,7 @@ func (tn *TeamsNotifier) Notify(ctx context.Context, as ...*types.Alert) (bool,
|
|||||||
u = tn.URL
|
u = tn.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
b, err := json.Marshal(NewAdaptiveCardsMessage(card))
|
b, err := json.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("failed to marshal JSON: %w", err)
|
return false, fmt.Errorf("failed to marshal JSON: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,8 @@ func TestTeamsNotifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"contentType": "application/vnd.microsoft.card.adaptive",
|
"contentType": "application/vnd.microsoft.card.adaptive",
|
||||||
}},
|
}},
|
||||||
"type": "message",
|
"summary": "[FIRING:1] (val1)",
|
||||||
|
"type": "message",
|
||||||
},
|
},
|
||||||
expMsgError: nil,
|
expMsgError: nil,
|
||||||
}, {
|
}, {
|
||||||
@ -125,7 +126,8 @@ func TestTeamsNotifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
"contentType": "application/vnd.microsoft.card.adaptive",
|
"contentType": "application/vnd.microsoft.card.adaptive",
|
||||||
}},
|
}},
|
||||||
"type": "message",
|
"summary": "alert1",
|
||||||
|
"type": "message",
|
||||||
},
|
},
|
||||||
expMsgError: nil,
|
expMsgError: nil,
|
||||||
}, {
|
}, {
|
||||||
|
@ -2229,6 +2229,7 @@ var expNonEmailNotifications = map[string][]string{
|
|||||||
"contentType": "application/vnd.microsoft.card.adaptive"
|
"contentType": "application/vnd.microsoft.card.adaptive"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"summary": "[FIRING:1] TeamsAlert (default)",
|
||||||
"type": "message"
|
"type": "message"
|
||||||
}`,
|
}`,
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user