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
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)"
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.
Paste the HTTP API token of your bot to the Telegram template settings.
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.
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.
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.
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.
Now you will receive notifications from Zabbix in Telegram