Skip to content

2024

Telegram Notifications From AlertManager With Respect to 4096 Chars Limit

Issue

  • Telegram API has limit of 4096 characters per message
  • AlertManager sending notifications truncates text of message to fit this limit
  • As result markdown(or HTML depending on the parse_mode specified in telegram_configs of AlertManager config) may be broken and telegram API responses with Status Code 400

Solution

Telegram notification template should generate message that is always less than 4096 characters and has consistent markdown/html

Template below:

  • Builds full notification message with all alerts
  • If it is too big falls back to less verbose single alert format (no labels)
  • If even with less verbose format the message appears to be too big
    • removes some alerts to fit the size limit (alerts are removed as a whole, so telegram does not complain about broken markdown)
    • add notice about truncation to the message