One night at the station, the air conditioners turned off and the temperature started to rise, naturally, I received email notifications on the phone, but since it was night, I only saw them in the morning, so it was necessary for such an emergency to quickly make the possibility of phone call notifications.
I will give an example of the variant of Zabbix alerts using a phone call through Asterisk.
Asterisk should have a module loaded, to do this, open the module configuration file, for example, in the nano editor (Ctrl+X to exit, y/n to save or cancel changes):
sudo nano /etc/asterisk/modules.conf
And check if there is a string, if not, add:
load => pbx_spool.so
And also load it at the moment:
sudo asterisk -rvv module load pbx_spool quit
In my case, Zabbix and Asterisk are on different servers.
On the server with Asterisk, I wrote a Russian notification text in a high_temperature.txt text file that should be played back during the call.
I installed festival, a Russian male voice to convert text into an audio file and rsync to copy the call file to the Asterisk server:
sudo apt-get install festival festvox-ru rsync
Actually the command to convert text to an audio file:
text2wave -eval '(voice_msu_ru_nsh_clunits)' < high_temperature.txt > high_temperature.wav
Then I converted the format of the wav file to ulaw, since I use it:
sox -V high_temperature.wav -r 8000 -c 1 -t ul high_temperature.ulaw
And moved the finished audio file to the directory with Asterisk audio files:
sudo mv high_temperature.ulaw /usr/share/asterisk/sounds/ru_RU/high_temperature.ulaw
See also my article – How to convert audio files to ulaw, alaw, gsm, g722, etc. for Asterisk
On the server with Zabbix using the nano text editor, I created the file:
sudo nano /etc/zabbix/zabbix.call
And I added content to it (where 0670000000 is the phone number to call, and 4 is the Goip4 GSM gateway channel number from which the call will be made):
Channel: SIP/goip4/40670000000 Application: Playback Data: high_temperature MaxRetries: 10 RetryTime: 60 WaitTime: 30
I set 777 permissions on the file to allow access for everyone, the zabbix user will copy it, and on another server, the asterisk user will read and delete after the call:
sudo chmod 777 /etc/zabbix/zabbix.call
You also need to create the script file itself that Zabbix will execute (I created it in the directories with the scripts zabbix /alert.d/asterisk_call.sh):
rsync -avh -e "ssh -p 22" /etc/zabbix/zabbix.call firstname.lastname@example.org:/var/spool/asterisk/outgoing/zabbix.call
The script simply copies the zabbix.call file to the server with Asterisk in the /var/spool/asterisk/outgoing/ directory, after which Asterisk immediately hits it and processes it and makes the call.
In fact, the script can transfer the caller’s number and create the file zabbix.call, but I did not need it.
If Asterisk and Zabbix are on the same server, then we replace the line in the script with:
cp /etc/zabbix/zabbix.call /var/spool/asterisk/outgoing/zabbix.call
rsync -avh /etc/zabbix/zabbix.call /var/spool/asterisk/outgoing/zabbix.call
In order for rsync to copy without asking for a password, you need to generate an SSH key and copy it to the Astersik server, as I described in this article – Connect to SSH using the keys
If access to the server via SSH is granted to the root user, then for security reasons you can restrict access via IP using SSH:
sudo nano /etc/ssh/sshd_config AllowUsers user1 user2 email@example.com sudo service ssh restart
If you have rights problems on the server with Zabbix, for example, when copying the call file, you can specify the following parameter in the /etc/zabbix/zabbix_server.conf configuration file:
It remains to add a new type of alert in the Zabbix panel (“Administration” – “Alert methods”).
Then he created a new group of nodes and added a device for which he was working on a high temperature trigger.
Created a separate user, indicated the created alert type to it and added it to the created node group.
Also added an action in the “Settings” – “Actions” indicating the sending of messages through the script.
Done, after the trigger is triggered, Zabbix will execute a script that will copy the finished call file to the Asterisk server, and it will process it and make the call, as indicated in the file – “MaxRetries: 10”, will try to call you 10 times.