There are many tutorials on the Internet to send event notifications from Zabbix by Whatsapp, so I thought why not adapt to send Bacula notifications. To perform sending messages by Whatsapp, it is used an API called Yowsup.
Yowsup is a python library that enables you build application which use WhatsApp service. Yowsup has been used to create an unofficial WhatsApp client Nokia N9 through the Wazapp project which was in use by 200K + users as well as another fully featured unofficial client for Blackberry 10
Required dependencies to install using apt-get
Required dependencies to install using pip
(Pip is a package management system used to install and manage software packages written in Python)
After installing the dependencies you need to create a text file in /etc/whatsapp.conf with the following content:
Requesting a registration code
Please note: You need a unique number for this purpose, because if you use your own number, it can be blocked by reason of being used in two devices at the same time.
Registering on WhatsApp
After running the above command you should receive in a few minutes an SMS with the activation code, which is usually composed of 6 characters.
Replace the command below the code you received via SMS
Get the value obtained in the field pw and include in /etc/whatsapp.conf file in the password field. Now, it is already possible to send messages using youwsup.
Sending a whatsapp message
For sending to a whatsapp group, the process is a kind different. Is necessary create a new group or use an existing one and add the in group, the number that will be used to send the messages.
To find the group number, type the following command in the terminal, and send a message in the group:
After sending the message in the group the output of the command will look as follows:
The group number is the value in the field from: 1XXXXXXXXXX-YYYYYYYYYY@g.us. In the script replace the RECIPIENT_NUMBER = “XXXXXXXXXXX” by RECIPIENT_NUMBER = “1XXXXXXXXXX-YYYYYYYYYY@g.us”
Create an script file /etc/bacula/scripts/_send_whatsapp.sh and give permission a+x. (For the Emoji works properly it is necessary that the file is in UTF8 encoding)
Change Bacula Config
You can set in a few some Jobs, but how I wanted in all, I set up in JobDefs. It should include the RunScript, as indicated below, save and do reload in bconsole: