mirror of
https://github.com/prometheus/alertmanager
synced 2024-12-27 08:32:15 +00:00
Reflect Discord's max length message limits (#3597)
* Reflect Discord's max length message limits Signed-off-by: Tomas Kozak <kozak@talko.cz> * Fix log key name Signed-off-by: Tomas Kozak <kozak@talko.cz> --------- Signed-off-by: Tomas Kozak <kozak@talko.cz>
This commit is contained in:
parent
9dbc8b6b91
commit
d2b6692f2c
@ -30,6 +30,13 @@ import (
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-limits - 256 characters or runes.
|
||||
maxTitleLenRunes = 256
|
||||
// https://discord.com/developers/docs/resources/channel#embed-object-embed-limits - 4096 characters or runes.
|
||||
maxDescriptionLenRunes = 4096
|
||||
)
|
||||
|
||||
const (
|
||||
colorRed = 0x992D22
|
||||
colorGreen = 0x2ECC71
|
||||
@ -90,14 +97,20 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
|
||||
return false, err
|
||||
}
|
||||
|
||||
title := tmpl(n.conf.Title)
|
||||
title, truncated := notify.TruncateInRunes(tmpl(n.conf.Title), maxTitleLenRunes)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
description := tmpl(n.conf.Message)
|
||||
if truncated {
|
||||
level.Warn(n.logger).Log("msg", "Truncated title", "key", key, "max_runes", maxTitleLenRunes)
|
||||
}
|
||||
description, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), maxDescriptionLenRunes)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if truncated {
|
||||
level.Warn(n.logger).Log("msg", "Truncated message", "key", key, "max_runes", maxDescriptionLenRunes)
|
||||
}
|
||||
|
||||
color := colorGrey
|
||||
if alerts.Status() == model.AlertFiring {
|
||||
|
Loading…
Reference in New Issue
Block a user