Skip to content

Commit 356e6cb

Browse files
update the alerting-example-telegram.md docs (#180)
* create the alerting example- Telegram doc * update the alerting example - telegram doc
1 parent 57e0cf4 commit 356e6cb

7 files changed

+83
-0
lines changed

docs/user-guide/alerts/.pages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ nav:
66
- Import and Export Alerts: import-export-alerts.md
77
- Multi-window Selector in Scheduled Alerts (SQL Mode): multi-window-selector-scheduled-alerts-concept.md
88
- Use Multi-window Selector in Scheduled Alerts: how-to-access-multi-window-selector-scheduled-alerts.md
9+
- Use Telegram for Alerts: alerting-example-telegram.md
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
![Create Template](alerting-telegram-template.png)
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+
![Create Alert Destination](alerting-telegram-destination.png)
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+
![Config Alert](alerting-telegram-config.png)
60+
- Threshold: >= 1 time
61+
- Period: 1 minute
62+
- Frequency: 1 minute
63+
- Destination: select `Telegram_alert`
64+
![Config Alert](alerting-telegram-config-conditions.png)
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+
![Verify alert delivery](alerting-telegram-alert-delivery.png)
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+
}
157 KB
Loading
59.4 KB
Loading
96.3 KB
Loading
57.2 KB
Loading
74.1 KB
Loading

0 commit comments

Comments
 (0)