diff --git a/notify/opsgenie/opsgenie.go b/notify/opsgenie/opsgenie.go index 627e8095..fc74f05e 100644 --- a/notify/opsgenie/opsgenie.go +++ b/notify/opsgenie/opsgenie.go @@ -34,6 +34,9 @@ import ( "github.com/prometheus/alertmanager/types" ) +// https://docs.opsgenie.com/docs/alert-api - 130 characters meaning runes. +const maxMessageLenRunes = 130 + // Notifier implements a Notifier for OpsGenie notifications. type Notifier struct { conf *config.OpsGenieConfig @@ -171,10 +174,9 @@ func (n *Notifier) createRequests(ctx context.Context, as ...*types.Alert) ([]*h } requests = append(requests, req.WithContext(ctx)) default: - // https://docs.opsgenie.com/docs/alert-api - 130 characters meaning runes. - message, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), 130) + message, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), maxMessageLenRunes) if truncated { - level.Debug(n.logger).Log("msg", "Truncated message", "alert", key) + level.Debug(n.logger).Log("msg", "Truncated message", "alert", key, "runes", maxMessageLenRunes) } createEndpointURL := n.conf.APIURL.Copy() diff --git a/notify/pagerduty/pagerduty.go b/notify/pagerduty/pagerduty.go index 6d871325..1e549db8 100644 --- a/notify/pagerduty/pagerduty.go +++ b/notify/pagerduty/pagerduty.go @@ -36,7 +36,13 @@ import ( "github.com/prometheus/alertmanager/types" ) -const maxEventSize int = 512000 +const ( + maxEventSize int = 512000 + // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTc4-send-a-v1-event - 1024 characters or runes. + maxV1DescriptionLenRunes = 1024 + // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event - 1024 characters or runes. + maxV2SummaryLenRunes = 1024 +) // Notifier implements a Notifier for PagerDuty notifications. type Notifier struct { @@ -149,10 +155,9 @@ func (n *Notifier) notifyV1( var tmplErr error tmpl := notify.TmplText(n.tmpl, data, &tmplErr) - // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event - 1204 characters or runes. - description, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), 1024) + description, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), maxV1DescriptionLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated description", "key", key) + level.Warn(n.logger).Log("msg", "Truncated description", "key", key, "runes", maxV1DescriptionLenRunes) } serviceKey := string(n.conf.ServiceKey) @@ -215,10 +220,9 @@ func (n *Notifier) notifyV2( n.conf.Severity = "error" } - // https://developer.pagerduty.com/docs/ZG9jOjExMDI5NTgx-send-an-alert-event - 1204 characters or runes. - summary, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), 1024) + summary, truncated := notify.TruncateInRunes(tmpl(n.conf.Description), maxV2SummaryLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated summary", "key", key) + level.Warn(n.logger).Log("msg", "Truncated summary", "key", key, "runes", maxV2SummaryLenRunes) } routingKey := string(n.conf.RoutingKey) diff --git a/notify/pushover/pushover.go b/notify/pushover/pushover.go index fa67a11e..3a3361a0 100644 --- a/notify/pushover/pushover.go +++ b/notify/pushover/pushover.go @@ -31,6 +31,15 @@ import ( "github.com/prometheus/alertmanager/types" ) +const ( + // https://pushover.net/api#limits - 250 characters or runes. + maxTitleLenRunes = 250 + // https://pushover.net/api#limits - 1024 characters or runes. + maxMessageLenRunes = 1024 + // https://pushover.net/api#limits - 512 characters or runes. + maxURLLenRunes = 512 +) + // Notifier implements a Notifier for Pushover notifications. type Notifier struct { conf *config.PushoverConfig @@ -78,10 +87,9 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) parameters.Add("token", tmpl(string(n.conf.Token))) parameters.Add("user", tmpl(string(n.conf.UserKey))) - // https://pushover.net/api#limits - 250 characters or runes. - title, truncated := notify.TruncateInRunes(tmpl(n.conf.Title), 250) + title, truncated := notify.TruncateInRunes(tmpl(n.conf.Title), maxTitleLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated title", "incident", key) + level.Warn(n.logger).Log("msg", "Truncated title", "incident", key, "runes", maxTitleLenRunes) } parameters.Add("title", title) @@ -92,10 +100,9 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) message = tmpl(n.conf.Message) } - // https://pushover.net/api#limits - 1024 characters or runes. - message, truncated = notify.TruncateInRunes(message, 1024) + message, truncated = notify.TruncateInRunes(message, maxMessageLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated message", "incident", key) + level.Warn(n.logger).Log("msg", "Truncated message", "incident", key, "runes", maxMessageLenRunes) } message = strings.TrimSpace(message) if message == "" { @@ -104,10 +111,9 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) } parameters.Add("message", message) - // https://pushover.net/api#limits - 512 characters or runes. - supplementaryURL, truncated := notify.TruncateInRunes(tmpl(n.conf.URL), 512) + supplementaryURL, truncated := notify.TruncateInRunes(tmpl(n.conf.URL), maxURLLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated URL", "incident", key) + level.Warn(n.logger).Log("msg", "Truncated URL", "incident", key, "runes", maxURLLenRunes) } parameters.Add("url", supplementaryURL) parameters.Add("url_title", tmpl(n.conf.URLTitle)) diff --git a/notify/slack/slack.go b/notify/slack/slack.go index 4622950c..42851939 100644 --- a/notify/slack/slack.go +++ b/notify/slack/slack.go @@ -33,6 +33,9 @@ import ( "github.com/prometheus/alertmanager/types" ) +// https://api.slack.com/reference/messaging/attachments#legacy_fields - 1024, no units given, assuming runes or characters. +const maxTitleLenRunes = 1024 + // Notifier implements a Notifier for Slack notifications. type Notifier struct { conf *config.SlackConfig @@ -99,14 +102,14 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error) } else { markdownIn = n.conf.MrkdwnIn } - // No reference in https://api.slack.com/reference/messaging/attachments#legacy_fields - assuming runes or characters. - title, truncated := notify.TruncateInRunes(tmplText(n.conf.Title), 1024) + + title, truncated := notify.TruncateInRunes(tmplText(n.conf.Title), maxTitleLenRunes) if truncated { key, err := notify.ExtractGroupKey(ctx) if err != nil { return false, err } - level.Warn(n.logger).Log("msg", "Truncated title", "key", key) + level.Warn(n.logger).Log("msg", "Truncated title", "key", key, "runes", maxTitleLenRunes) } att := &attachment{ Title: title, diff --git a/notify/telegram/telegram.go b/notify/telegram/telegram.go index fbb26d5c..f02b8bdb 100644 --- a/notify/telegram/telegram.go +++ b/notify/telegram/telegram.go @@ -29,6 +29,9 @@ import ( "github.com/prometheus/alertmanager/types" ) +// Telegram supports 4096 chars max - from https://limits.tginfo.me/en. +const maxMessageLenRunes = 4096 + // Notifier implements a Notifier for telegram notifications. type Notifier struct { conf *config.TelegramConfig @@ -71,10 +74,9 @@ func (n *Notifier) Notify(ctx context.Context, alert ...*types.Alert) (bool, err return false, fmt.Errorf("group key missing") } - // Telegram supports 4096 chars max - from https://limits.tginfo.me/en. - messageText, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), 4096) + messageText, truncated := notify.TruncateInRunes(tmpl(n.conf.Message), maxMessageLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "Truncated message", "alert", key) + level.Warn(n.logger).Log("msg", "Truncated message", "alert", key, "runes", maxMessageLenRunes) } message, err := n.client.Send(telebot.ChatID(n.conf.ChatID), messageText, &telebot.SendOptions{ diff --git a/notify/victorops/victorops.go b/notify/victorops/victorops.go index 774a0e1c..55f061f8 100644 --- a/notify/victorops/victorops.go +++ b/notify/victorops/victorops.go @@ -34,6 +34,9 @@ import ( "github.com/prometheus/alertmanager/types" ) +// https://help.victorops.com/knowledge-base/incident-fields-glossary/ - 20480 characters. +const maxMessageLenRunes = 20480 + // Notifier implements a Notifier for VictorOps notifications. type Notifier struct { conf *config.VictorOpsConfig @@ -134,10 +137,9 @@ func (n *Notifier) createVictorOpsPayload(ctx context.Context, as ...*types.Aler messageType = victorOpsEventResolve } - // https://help.victorops.com/knowledge-base/incident-fields-glossary/ - 20480 characters. - stateMessage, truncated := notify.TruncateInRunes(stateMessage, 20480) + stateMessage, truncated := notify.TruncateInRunes(stateMessage, maxMessageLenRunes) if truncated { - level.Warn(n.logger).Log("msg", "truncated stateMessage", "incident", key) + level.Warn(n.logger).Log("msg", "truncated stateMessage", "incident", key, "runes", maxMessageLenRunes) } msg := map[string]string{