|
| 1 | +This guide explains how to configure [OpenObserve alerts]() to send notifications directly to Telegram. You will create a template, configure an alert destination, and attach it to an alert rule. |
| 2 | + |
| 3 | +## Configure OpenObserve alerts |
| 4 | +??? "Prerequisites" |
| 5 | + - A Telegram account |
| 6 | + - Telegram bot token: Create a bot in Telegram using **BotFather**. BotFather provides the token. |
| 7 | + - Telegram chat ID: Start a chat with your bot, send a message, and run `getUpdates` with your bot token to retrieve the `chat.id`. |
| 8 | + |
| 9 | + Verify the bot token and chat ID with the following commands: |
| 10 | + |
| 11 | + **Get updates** |
| 12 | + ```bash |
| 13 | + curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates" |
| 14 | + ``` |
| 15 | + |
| 16 | + **Get bot details** |
| 17 | + ```bash |
| 18 | + curl "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getMe" |
| 19 | + ``` |
| 20 | + |
| 21 | + **Send a test message** |
| 22 | + ```bash |
| 23 | + set TOKEN=<YOUR_BOT_TOKEN> |
| 24 | + set CHAT=<YOUR_CHAT_ID> |
| 25 | + |
| 26 | + curl.exe -X POST "https://api.telegram.org/bot%TOKEN%/sendMessage" ^ |
| 27 | + --data-urlencode "chat_id=%CHAT%" ^ |
| 28 | + --data-urlencode "text=OpenObserve test" |
| 29 | + ``` |
| 30 | + If the message appears in Telegram, your setup is correct. |
| 31 | + |
| 32 | +??? "Step 1: Create Template" |
| 33 | + 1. Go to **Management > Templates > Add Template**. |
| 34 | + 2. Enter a name, for example `Telegram_alert`. |
| 35 | + 3. Select **Web Hook**. |
| 36 | + 4. In the Body, add the following JSON. Replace <YOUR_CHAT_ID> with your chat ID. |
| 37 | +  |
| 38 | + 5. Save the template. |
| 39 | + |
| 40 | +??? "Step 2: Create Alert Destination" |
| 41 | + 1. Go to **Management > Alert Destinations > Add Destination**. |
| 42 | + 2. Enter a name, for example `Telegram_alert`. |
| 43 | + 3. Select the template you created earlier (Telegram_alert). |
| 44 | + 4. Set **URL** to: https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage |
| 45 | + 5. Set **Method** to POST. |
| 46 | + 6. Add the header: Content-Type = application/json |
| 47 | + 7. Save the destination. |
| 48 | +  |
| 49 | + |
| 50 | +??? "Step 3: Create Alert" |
| 51 | + 1. Go to **Alerts > Add Alert**. |
| 52 | + 2. Configure the alert: |
| 53 | + |
| 54 | + - Name: any name |
| 55 | + - Stream Type: logs |
| 56 | + - Stream Name: select your stream. For example, default. |
| 57 | + - Alert Type: Scheduled |
| 58 | + - Condition: for example service_name = ingress-nginx |
| 59 | +  |
| 60 | + - Threshold: >= 1 time |
| 61 | + - Period: 1 minute |
| 62 | + - Frequency: 1 minute |
| 63 | + - Destination: select `Telegram_alert` |
| 64 | +  |
| 65 | + - In Row Template, define the row format, for example: `Alert was active at {_timestamp}` |
| 66 | + 3. Save the alert. |
| 67 | + |
| 68 | +??? "Step 4: Verify alert delivery" |
| 69 | + After you save the alert, wait until the condition is met. |
| 70 | + If configured correctly, you will receive a message in Telegram that looks similar to the following: |
| 71 | +  |
| 72 | + |
| 73 | +??? "Troubleshooting" |
| 74 | + **Issue:** No message received in Telegram <br> |
| 75 | + **Solution:** Verify that the template body includes a valid `chat_id`. Without `chat_id`, Telegram cannot deliver the message. |
| 76 | + |
| 77 | + Example of a valid body: |
| 78 | + |
| 79 | + { |
| 80 | + "chat_id": "8237******", |
| 81 | + "text": "{alert_name} is active \nDetails:\n{rows}" |
| 82 | + } |
0 commit comments