Sending Zabbix Alerts to Telegram

PowerADM.com / Zabbix / Sending Zabbix Alerts to Telegram

You can send Zabbix alerts as notifications to the Telegram messenger. Starting with version 5, Zabbix has built-in support for sending notifications to Telegram using the API and webhook.

First, you need to create a new Telegram bot using @BotFather. Open the bot and send the following commands:

/start
/newboot

Set the bot name and username. BotFather will generate an HTTP API token for you, which you need to copy.

HTTP API token: xxxxxxxxxxxxxxxxxxxxxxxxxxxx

Telegram BotFather create bot

Go to your Telegram bot and click:

/start

You can test sending notifications via your Telegram bot from the command prompt using curl or PowerShell. To do this, you will need a bot token and your user (or group) name.

To get your account ID, open the @my_id_bot bot and type /start. It will return:

Your user ID: 123456789

Now you can send test messages to Telegram bot using curl:

curl --header 'Content-Type: application/json' --request 'POST' --data '{"chat_id":"<strong>123456789</strong>","text":"Test message to Telegram from curl"}' "https://api.telegram.org/bot<strong>xxxxxxxxxxxxxxxxxxxxxxxxxxxx</strong>/sendMessage"

Or you can send a Telegram notification from PowerShell:

$Message ="Test message from PowerShell to TG bot"
$Telegramtoken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$Telegramchatid = "123456789"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$Response = Invoke-RestMethod -Uri "https://api.telegram.org/bot$($Telegramtoken)/sendMessage?chat_id=$($Telegramchatid)&text=$($Message)"

send zabbix alert from poweshell cli

Check that you have received a notification in the Telegram app.

Now you need to configure the Telegram notification method in the Zabbix web interface. As we said earlier, built-in support for sending notifications to Telegram via webhook is available in Zabbix 5 and newer.

Go to Administration -> Media types-> select Telegram template.

If the Telegram template is not available in Zabbix, you can import it from the official repository (https://github.com/zabbix/zabbix/tree/master/templates/media/telegram).

Paste the HTTP API token of your bot to the Telegram template settings.

Configure Telegram media type in Zabbix

You can change the notification settings on the Message templates tab. I’ve added emojis to the notification subjects (which makes the notifications more descriptive) and the hostname via the {HOST.NAME} variable.

You can copy and paste emoji characters from the clipboard.

edit zabbix message template

Now try to send a Zabbix notification to Telegram. Enter your account ID in the TO field and click the Test button. You should see a message from the bot in the chat.

Send test notification from zabbix to telegram

Now you need to assign Telegram notifications to your user. Go to Administration -> Users -> select a user, go to the Media tab and add a new Telegram alert type.

Specify your Telegram user ID and select triggers (Use if severity), when you need to send notifications to the Telegram bot.

zabbix - configure triggers

Select your alert trigger under Configuration -> Actions -> Trigger actions. Go to the Operations section and add a new operation. Select the user or group to be notified. Select Telegram in the Send only to section.

operation - send alert to telegram

Now you will receive notifications from Zabbix in Telegram

checj alert actions on zabbix

The disadvantage of the standard Zabbix template for Telegram is that it can only display plain text messages, without any formatting and graphics. Only Emoji characters are allowed to be used
Leave a Reply

Your email address will not be published. Required fields are marked *