Alerting Zabbix issues over the phone via Asterisk
The wonderful Zabbix monitoring system offers out of the box several ways to notify the administrator about problems that have occurred: e-mail, SMS and Jabber.
In this topic, I will tell you how to make friends Zabbix and Asterisk-based office PBX. When an emergency occurs, the robot will call you and speak a message describing the problem.
Email alerts work well when there are few. With a large number of letters there is a chance to miss a critical error. Therefore, it is logical to set up alerts for all levels of problems by e-mail, and only the most critical ones by SMS.
But, unfortunately, not all fellow administrators have a budget to purchase a GMS modem and pay for SMS. Sending SMS via online services is not reliable, because we may have dropped the channel on the Internet. A notification through your PBX will be free. You can set up a call to an internal number in the office, a group of subscribers, or to a mobile. If the PBX is connected to a physical telephone line, then the fall of the Internet channel will not be scary for her.
Online I found pa py sample scripts for solving this problem. However, both of them have significant drawbacks: they use PHP (why?) And do not know how to read the message text - only a standard message, that there is some kind of problem.
Our script will work like this:
The whole process takes only 1-2 seconds.
Zabbix can run scripts when problems arise. The scripts are in the folder specified in the AlertScriptsPath variable of the Zabbix server config.
Like all such scripts, our script should take 3 parameters: addressee, message subject, message text.
It all depends on your OS / distribution, so I can’t give 100% exact recommendations.
If, in brief, firstly, we need to install text2wave ( Festival package ) on Asterisk , optionally install a Russian voice.
Secondly, you need to configure passwordless SSH authentication between Zabbix and Asterisk. You can use this instruction (paragraphs 1-6). The key will have to be done without passphrase. You can configure authentication for both the users Zabbix and Asterisk work under, as well as for others, but in the second case, you will need to use sudo in the script.
Also make sure that Asterisk has all the rights to the generated call-file.
If necessary, create a separate extension from which the call will occur.
After everything is configured, you can check the script by running it from the console:
If it doesn’t work, pick the Zabbix, ssh and Asterisk logs. I spent most of my time setting up sudo and ssh.
The simplest:
In Administration - Media types, create a new alert type.

For the necessary users (Administration - Users) in the Media tab indicate their phone number. This can be either an internal number or a mobile number, in accordance with the plan for dialing your PBX.
In Actions, we edit or create a new action by specifying notified users. I recommend setting the message header to {TRIGGER.STATUS} {TRIGGER.NAME} {HOSTNAME} so that it is clear which machine was in trouble.
We have received another admin notification channel in addition to e-mail and SMS.
In this topic, I will tell you how to make friends Zabbix and Asterisk-based office PBX. When an emergency occurs, the robot will call you and speak a message describing the problem.
Why is it necessary
Email alerts work well when there are few. With a large number of letters there is a chance to miss a critical error. Therefore, it is logical to set up alerts for all levels of problems by e-mail, and only the most critical ones by SMS.
But, unfortunately, not all fellow administrators have a budget to purchase a GMS modem and pay for SMS. Sending SMS via online services is not reliable, because we may have dropped the channel on the Internet. A notification through your PBX will be free. You can set up a call to an internal number in the office, a group of subscribers, or to a mobile. If the PBX is connected to a physical telephone line, then the fall of the Internet channel will not be scary for her.
How it works
Online I found pa py sample scripts for solving this problem. However, both of them have significant drawbacks: they use PHP (why?) And do not know how to read the message text - only a standard message, that there is some kind of problem.
Our script will work like this:
- when an alert occurs, Zabbix launches a bash script;
- The bash script prepares a call file for Asterisk and an error message in text form;
- files are sent via SCP to the Asterisk server;
- over SSH, Asterisk launches text2wave, which reads text into a wav file;
- The wav file and call file are copied to the corresponding Asterisk folders;
- Asterisk sees files, makes a call and plays a message.
The whole process takes only 1-2 seconds.
Script
Zabbix can run scripts when problems arise. The scripts are in the folder specified in the AlertScriptsPath variable of the Zabbix server config.
Like all such scripts, our script should take 3 parameters: addressee, message subject, message text.
#!/bin/bash
# Asterisk сервер
server="asterisk@pbx.roga-i-kopyta.com"
# Уникальная метка
ts=$(date +%s%N)
# Создаем два файла
txtname=/tmp/zabbix-alert.$ts.txt
callname=/tmp/zabbix-alert.$ts.call
# Наговариваемый текст.
# Приветствие. Запятые для паузы.
echo "Zabbix alert,,,,,,,,,,,,,,,,," > $txtname
# $2 - subject триггера. Можно поставить $3 - сообщение.
echo "$2" >> $txtname
# Call-файл Asterisk
echo "Channel: Local/$1@from-internal" > $callname
echo "Extension: s" >> $callname
echo "MaxRetries: 2" >> $callname
echo "RetryTime: 60" >> $callname
echo "WaitTime: 30" >> $callname
# С какого номера звоним
echo "Callerid: 999" >> $callname
echo "Application: Playback" >> $callname
# Повторяем 3 раза
echo "Data: zabbix-alert.$ts&zabbix-alert.$ts&zabbix-alert.$ts" >> $callname
scp $txtname $server:$txtname
scp $callname $server:$callname
rm -f $txtname
rm -f $callname
ssh $server "cat $txtname | /usr/bin/text2wave -F 8000 > /var/lib/asterisk/sounds/zabbix-alert.$ts.wav && mv $callname /var/spool/asterisk/outgoing/ && rm -f $txtname && find /var/lib/asterisk/sounds/ -name 'zabbix-alert*' -type f -mmin +10 -delete"
We configure servers
It all depends on your OS / distribution, so I can’t give 100% exact recommendations.
If, in brief, firstly, we need to install text2wave ( Festival package ) on Asterisk , optionally install a Russian voice.
Secondly, you need to configure passwordless SSH authentication between Zabbix and Asterisk. You can use this instruction (paragraphs 1-6). The key will have to be done without passphrase. You can configure authentication for both the users Zabbix and Asterisk work under, as well as for others, but in the second case, you will need to use sudo in the script.
Also make sure that Asterisk has all the rights to the generated call-file.
If necessary, create a separate extension from which the call will occur.
After everything is configured, you can check the script by running it from the console:
./call_sip.sh номер "текст" ""If it doesn’t work, pick the Zabbix, ssh and Asterisk logs. I spent most of my time setting up sudo and ssh.
Customize Zabbix
The simplest:
In Administration - Media types, create a new alert type.

For the necessary users (Administration - Users) in the Media tab indicate their phone number. This can be either an internal number or a mobile number, in accordance with the plan for dialing your PBX.
In Actions, we edit or create a new action by specifying notified users. I recommend setting the message header to {TRIGGER.STATUS} {TRIGGER.NAME} {HOSTNAME} so that it is clear which machine was in trouble.
Total
We have received another admin notification channel in addition to e-mail and SMS.