mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix bug in Discord for when name for metric value is absent (#31257)
* Make sure Metric field in Discord notification is never empty Discord uniquely does not send the alert if the metric field is empty, which can happen in some cases, such as when the legend is {{hostname}}. Signed-off-by: Levi Harrison <levisamuelharrison@gmail.com> * Changed name of empty metric in Discord alert Signed-off-by: Levi Harrison <levisamuelharrison@gmail.com>
This commit is contained in:
parent
4bc6a7c407
commit
d3a590ca19
@ -89,7 +89,9 @@ func (dn *DiscordNotifier) Notify(evalContext *alerting.EvalContext) error {
|
||||
|
||||
for _, evt := range evalContext.EvalMatches {
|
||||
fields = append(fields, map[string]interface{}{
|
||||
"name": evt.Metric,
|
||||
// Discord uniquely does not send the alert if the metric field is empty,
|
||||
// which it can be in some cases
|
||||
"name": notEmpty(evt.Metric),
|
||||
"value": evt.Value.FullString(),
|
||||
"inline": true,
|
||||
})
|
||||
@ -213,3 +215,11 @@ func (dn *DiscordNotifier) embedImage(cmd *models.SendWebhookSync, imagePath str
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func notEmpty(metric string) string {
|
||||
if metric == "" {
|
||||
return "<NO_METRIC_NAME>"
|
||||
}
|
||||
|
||||
return metric
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user