diff --git a/docs/user-guide/alerts/.pages b/docs/user-guide/alerts/.pages index 5d04b8c2..1f7d9096 100644 --- a/docs/user-guide/alerts/.pages +++ b/docs/user-guide/alerts/.pages @@ -6,3 +6,4 @@ nav: - Import and Export Alerts: import-export-alerts.md - Multi-window Selector in Scheduled Alerts (SQL Mode): multi-window-selector-scheduled-alerts-concept.md - Use Multi-window Selector in Scheduled Alerts: how-to-access-multi-window-selector-scheduled-alerts.md + - Use Telegram for Alerts: alerting-example-telegram.md \ No newline at end of file diff --git a/docs/user-guide/alerts/alerting-example-telegram.md b/docs/user-guide/alerts/alerting-example-telegram.md new file mode 100644 index 00000000..f2708ee3 --- /dev/null +++ b/docs/user-guide/alerts/alerting-example-telegram.md @@ -0,0 +1,82 @@ +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. + +## Configure OpenObserve alerts +??? "Prerequisites" + - A Telegram account + - Telegram bot token: Create a bot in Telegram using **BotFather**. BotFather provides the token. + - Telegram chat ID: Start a chat with your bot, send a message, and run `getUpdates` with your bot token to retrieve the `chat.id`. + + Verify the bot token and chat ID with the following commands: + + **Get updates** + ```bash + curl "https://api.telegram.org/bot/getUpdates" + ``` + + **Get bot details** + ```bash + curl "https://api.telegram.org/bot/getMe" + ``` + + **Send a test message** + ```bash + set TOKEN= + set CHAT= + + curl.exe -X POST "https://api.telegram.org/bot%TOKEN%/sendMessage" ^ + --data-urlencode "chat_id=%CHAT%" ^ + --data-urlencode "text=OpenObserve test" + ``` + If the message appears in Telegram, your setup is correct. + +??? "Step 1: Create Template" + 1. Go to **Management > Templates > Add Template**. + 2. Enter a name, for example `Telegram_alert`. + 3. Select **Web Hook**. + 4. In the Body, add the following JSON. Replace with your chat ID. + ![Create Template](alerting-telegram-template.png) + 5. Save the template. + +??? "Step 2: Create Alert Destination" + 1. Go to **Management > Alert Destinations > Add Destination**. + 2. Enter a name, for example `Telegram_alert`. + 3. Select the template you created earlier (Telegram_alert). + 4. Set **URL** to: https://api.telegram.org/bot/sendMessage + 5. Set **Method** to POST. + 6. Add the header: Content-Type = application/json + 7. Save the destination. + ![Create Alert Destination](alerting-telegram-destination.png) + +??? "Step 3: Create Alert" + 1. Go to **Alerts > Add Alert**. + 2. Configure the alert: + + - Name: any name + - Stream Type: logs + - Stream Name: select your stream. For example, default. + - Alert Type: Scheduled + - Condition: for example service_name = ingress-nginx + ![Config Alert](alerting-telegram-config.png) + - Threshold: >= 1 time + - Period: 1 minute + - Frequency: 1 minute + - Destination: select `Telegram_alert` + ![Config Alert](alerting-telegram-config-conditions.png) + - In Row Template, define the row format, for example: `Alert was active at {_timestamp}` + 3. Save the alert. + +??? "Step 4: Verify alert delivery" + After you save the alert, wait until the condition is met. + If configured correctly, you will receive a message in Telegram that looks similar to the following: + ![Verify alert delivery](alerting-telegram-alert-delivery.png) + +??? "Troubleshooting" + **Issue:** No message received in Telegram
+ **Solution:** Verify that the template body includes a valid `chat_id`. Without `chat_id`, Telegram cannot deliver the message. + + Example of a valid body: + + { + "chat_id": "8237******", + "text": "{alert_name} is active \nDetails:\n{rows}" + } diff --git a/docs/user-guide/alerts/alerting-telegram-alert-delivery.png b/docs/user-guide/alerts/alerting-telegram-alert-delivery.png new file mode 100644 index 00000000..10a7bc87 Binary files /dev/null and b/docs/user-guide/alerts/alerting-telegram-alert-delivery.png differ diff --git a/docs/user-guide/alerts/alerting-telegram-config-conditions.png b/docs/user-guide/alerts/alerting-telegram-config-conditions.png new file mode 100644 index 00000000..3729de21 Binary files /dev/null and b/docs/user-guide/alerts/alerting-telegram-config-conditions.png differ diff --git a/docs/user-guide/alerts/alerting-telegram-config.png b/docs/user-guide/alerts/alerting-telegram-config.png new file mode 100644 index 00000000..7e7034c0 Binary files /dev/null and b/docs/user-guide/alerts/alerting-telegram-config.png differ diff --git a/docs/user-guide/alerts/alerting-telegram-destination.png b/docs/user-guide/alerts/alerting-telegram-destination.png new file mode 100644 index 00000000..743ceb95 Binary files /dev/null and b/docs/user-guide/alerts/alerting-telegram-destination.png differ diff --git a/docs/user-guide/alerts/alerting-telegram-template.png b/docs/user-guide/alerts/alerting-telegram-template.png new file mode 100644 index 00000000..6096274b Binary files /dev/null and b/docs/user-guide/alerts/alerting-telegram-template.png differ