Skip to main content

Sending Telegram Alerts in Grafana

Let's understand how Grafana sends alerts in Telegram by understanding this flow.


Prerequisites

Before setting up Telegram alerts, ensure the following:

  1. You have administrator access to your Grafana instance.
  2. You have a Telegram account and can create bots using the BotFather.

Step 1: Create a Telegram Bot

  1. Open Telegram and search for BotFather.
  2. Start a conversation with BotFather and send the command /newbot.
  3. Follow the prompts to:
    • Name your bot.
    • Set a unique username for your bot (e.g., MyGrafanaBot).
  4. After completing the setup, you’ll receive an API Token (e.g., 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11).

Step 2: Find Your Chat ID

  1. Search for your bot in Telegram and start a conversation with it.
  2. Send any message to the bot (e.g., "Hello").
  3. Use a tool like curl or a browser to get the chat ID:
    • Replace <API_TOKEN> with your bot's API token:
      curl https://api.telegram.org/bot<API_TOKEN>/getUpdates
    • Look for "chat":{"id":<chat_id>} in the response.
    • Note down the <chat_id>.

Step 3: Configure Telegram Notification Channel in Grafana

  1. Log in to your Grafana instance.
  2. Navigate to Alerting > Notification channels.
  3. Click New Notification Channel and choose Telegram.
  4. Fill in the details:
    • Name: Provide a name (e.g., Telegram Alerts).
    • Bot Token: Paste the API token from Step 1.
    • Chat ID: Enter the chat ID from Step 2.
    • Message: Customize the message template, if needed.
  5. Click Send Test to verify the configuration.
  6. Save the notification channel.

Step 4: Create an Alert Rule

  1. Go to a Grafana dashboard and click Edit for a panel.
  2. Switch to the Alert tab and click Create Alert.
  3. Define the alert conditions:
    • Set the metric thresholds, evaluation frequency, and duration.
  4. Add a notification:
    • Select the Telegram notification channel configured earlier.
  5. Save the changes.

Testing the Telegram Alert

  1. Trigger the alert by ensuring the condition is met (e.g., CPU usage exceeding 80%).
  2. Verify that the alert message is sent to your Telegram chat.