How to Configure Grafana to Send Alerts to Slack and Telegram

This guide leverages Versus Incident as an intermediary to route Grafana alerts to both Slack and Telegram with customizable messages, using a real-world JSON payload from Grafana. Grafana is a powerful platform for monitoring and observability, with robust alerting capabilities. By integrating it with Versus Incident, you can extend its notification options to Slack and Telegram with tailored messages. In this guide, we’ll configure Grafana to send alerts to Versus Incident based on a sample JSON payload, then forward them to Slack and Telegram. Prerequisites A running Grafana instance (version 8.0+ recommended for unified alerting) connected to a data source (e.g., Prometheus). A Slack workspace with permission to create a bot and obtain a token. A Telegram account with a bot created via BotFather and a chat ID for your target group or channel. Docker installed (optional, for easy Versus Incident deployment). Step 1: Set Up Slack and Telegram Bots Slack Bot Visit api.slack.com/apps and click Create New App. Name your app (e.g., “Grafana Alerts”) and select your Slack workspace. Under Bot Users, add a bot (e.g., “GrafanaBot”) and enable it. Go to OAuth & Permissions, add the chat:write scope under Scopes. Install the app to your workspace and copy the Bot User OAuth Token (starts with xoxb-). Save it securely. Invite the bot to your Slack channel by typing /invite @GrafanaBot and note the channel ID (right-click the channel, copy the link, and extract the ID). Telegram Bot Open Telegram, search for BotFather, and start a chat. Type /newbot and follow the prompts to name your bot (e.g., “GrafanaAlertBot”). BotFather will provide a Bot Token (e.g., 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11). Save it securely. Create a group or channel, add your bot, and get the Chat ID. Step 2: Deploy Versus with Slack and Telegram Enabled Versus Incident will process Grafana’s JSON payload and route alerts to Slack and Telegram. Create a configuration directory: mkdir -p ./config Create config/config.yaml with the following content: name: versus host: 0.0.0.0 port: 3000 alert: slack: enable: true token: ${SLACK_TOKEN} channel_id: ${SLACK_CHANNEL_ID} template_path: "/app/config/slack_message.tmpl" telegram: enable: true bot_token: ${TELEGRAM_BOT_TOKEN} chat_id: ${TELEGRAM_CHAT_ID} template_path: "/app/config/telegram_message.tmpl" Create a Slack template at config/slack_message.tmpl, tailored to the JSON structure:

Mar 25, 2025 - 15:20
 0
How to Configure Grafana to Send Alerts to Slack and Telegram

This guide leverages Versus Incident as an intermediary to route Grafana alerts to both Slack and Telegram with customizable messages, using a real-world JSON payload from Grafana.

Grafana is a powerful platform for monitoring and observability, with robust alerting capabilities. By integrating it with Versus Incident, you can extend its notification options to Slack and Telegram with tailored messages.

In this guide, we’ll configure Grafana to send alerts to Versus Incident based on a sample JSON payload, then forward them to Slack and Telegram.

Prerequisites

  • A running Grafana instance (version 8.0+ recommended for unified alerting) connected to a data source (e.g., Prometheus).
  • A Slack workspace with permission to create a bot and obtain a token.
  • A Telegram account with a bot created via BotFather and a chat ID for your target group or channel.
  • Docker installed (optional, for easy Versus Incident deployment).

Step 1: Set Up Slack and Telegram Bots

Slack Bot

  1. Visit api.slack.com/apps and click Create New App.
  2. Name your app (e.g., “Grafana Alerts”) and select your Slack workspace.
  3. Under Bot Users, add a bot (e.g., “GrafanaBot”) and enable it.
  4. Go to OAuth & Permissions, add the chat:write scope under Scopes.
  5. Install the app to your workspace and copy the Bot User OAuth Token (starts with xoxb-). Save it securely.
  6. Invite the bot to your Slack channel by typing /invite @GrafanaBot and note the channel ID (right-click the channel, copy the link, and extract the ID).

Telegram Bot

  1. Open Telegram, search for BotFather, and start a chat.
  2. Type /newbot and follow the prompts to name your bot (e.g., “GrafanaAlertBot”).
  3. BotFather will provide a Bot Token (e.g., 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11). Save it securely.
  4. Create a group or channel, add your bot, and get the Chat ID.

Step 2: Deploy Versus with Slack and Telegram Enabled

Versus Incident will process Grafana’s JSON payload and route alerts to Slack and Telegram.

Create a configuration directory:

   mkdir -p ./config

Create config/config.yaml with the following content:

   name: versus
   host: 0.0.0.0
   port: 3000

   alert:
     slack:
       enable: true
       token: ${SLACK_TOKEN}
       channel_id: ${SLACK_CHANNEL_ID}
       template_path: "/app/config/slack_message.tmpl"

     telegram:
       enable: true
       bot_token: ${TELEGRAM_BOT_TOKEN}
       chat_id: ${TELEGRAM_CHAT_ID}
       template_path: "/app/config/telegram_message.tmpl"

Create a Slack template at config/slack_message.tmpl, tailored to the JSON structure: