I've seen quite a lot of examples of using whatsapp notifications with zabbix, and other monitoring systems, but this article inspired me for my own experiments with whatsapp. However, if everything is clear with the monitoring systems, then in the presence of an excellent “innate” system of email alerts, making a garden for one bacula was frankly lazy. And suddenly, then you want to put zabbix or something else to send? Every bot on vatsapu?yum -y update yum -y install epel-release openssh-server systemctl enable sshd systemctl start sshd yum -y install unzip wget tar nano yum -y install python python-dateutil python-argparse yum -y install libtiff-devel libjpeg-devel libzip-devel freetype-devel lcms2-devel yum -y install gcc yum -y install protobuf pycrypto python-axolotl-curve25519 yum -y install python-devel python-pip python-imaging pip install --upgrade pip cd /usr/src/ wget https://github.com/tgalal/yowsup/archive/master.zip unzip master cd yowsup-master/ python setup.py install yowsup-cli registration --requestcode sms --phone 7xxxxxxxxxx --cc 7 --mcc 250 --mnc xx --env android phone - your phone number starting with 7
cc - country code is the country code (for Russia it is 7)
mcc - mobile country code is a different country code (for Russia it is 250)
mnc - mobile network code - this is the code of your operator. (01 - MTS, 02 - megaphone, 20 - tele2, 99 - beeline)
yowsup-cli registration --register xxx-xxx --phone 7xxxxxxx --cc 7 status: ok
kind: free
pw: X1isWwe + 25d / aOXJpcSduzTV7fg =
price: 33,00 rub.
price_expiration: 1495380655
currency: RUB
cost: 33.00
expiration: 4444444444.0
login: 7xxxxxxxxxxx X1isWwe + 37d / aOXJpcSduzTV7fg =
type: new
nano yowsup-cli.config cc=7 phone=7xxxxxxx password=X1isWwe+25d/aOXJpcSduzTV7fg= yowsup-cli demos -c yowsup-cli.config -s 7 "alarm" localectl there are some problems in my setup, so: nano /etc/locale.conf LANG=ru_RU.UTF-8 , save and restart session nano /usr/lib/python2.7/site-packages/yowsup2-2.5.2-py2.7.egg/yowsup/demos/cli/layer.py reload(sys) sys.setdefaultencoding('utf8') from .cli import Cli, clicmd from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback from yowsup.layers.auth import YowAuthenticationProtocolLayer from yowsup.layers import YowLayerEvent, EventCallback from yowsup.layers.network import YowNetworkLayer import sys reload(sys) sys.setdefaultencoding('utf8') cd /usr/src wget https://github.com/adnanh/webhook/releases/download/2.6.3/webhook-linux-amd64.tar.gz tar -xvf webhook-linux-amd64.tar.gz -C /var mv /var/webhook-linux-amd64 /var/webhook mkdir /var/yowsup cp /usr/src/yowsup-master/yowsup-cli.config /var/yowsup hooks.json rules. cd /var/webhook​​​​​ nano hooks.json http:// :9000/hooks/wp-admin , process and send messages to the admins whatsapp. Inside the file, add a description of the conditions: [ { "id": "wp-admin", "execute-command": "/var/webhook/admin.sh", "command-working-directory": "/var/webhook", "pass-arguments-to-command": [ { "source": "url", "name": "msg" } ] } ] http:// :9000/hooks/wp-admin?msg= - /var/webhook/admin.sh script, and he, in turn, sends his regards to admin on whatsupp , and only him. I decided not to transmit a couple of phone messages each time, and if necessary, send to other numbers to create additional hooks. For example, a hook with sending to a specific contact list or universal with a pair of telephone message and some kind of token for greater security. ./webhook -hooks hooks.json -verbose [webhook] 2017/04/26 05:12:48 version 2.6.3 starting
[webhook] 2017/04/26 05:12:48 setting up os signal watcher
[webhook] 2017/04/26 05:12:48 attempting to load hooks from hooks.json
[webhook] 2017/04/26 05:12:48 found 1 hook (s) in file
[webhook] 2017/04/26 05:12:48 loaded: wp-admin
[webhook] 2017/04/26 05:12:48 serving hooks on 0.0.0.0 : 9000 / hooks / {id}
#! /bin/bash msg="$(echo "$*" | tr ' ' ' ')" if [[ ! -z "${msg/ //}" ]]; then /usr/bin/yowsup-cli demos -c /var/yowsup/yowsup-cli.config -s 7xxxxxxxxxx "$msg" fi http:// :9000/hooks/wp-admin?msg= . Everything should work. Add a hook to autoload. I did through systemd . nano /etc/systemd/system/webhook.service [Unit] Description=Webhook After=syslog.target After=network.target [Service] Type=simple PIDFile=/var/webhook/webhook-service.pid WorkingDirectory=/var/webhook User=root Group=root OOMScoreAdjust=-500 ExecStart=/var/webhook/webhook -hooks hooks.json -verbose ExecStop=/usr/bin/pkill -f webhook ExecReload= TimeoutSec=300 [Install] WantedBy=multi-user.target systemctl enable webhook systemctl start webhook systemctl -l status webhook curl -G http:// :9000/hooks/wp-admin?msg= export VAR="\n" export MSG=$(echo -e $VAR) curl -G http:// :9000/hooks/wp-admin --data-urlencode msg="$MSG" yum -y install bc curl # Variables HOUR=$(date +%d/%m/%Y\ %H:%M:%S) YOWSEXEC="curl -G http:// :9000/hooks/wp-admin" LOG="/var/log/bacula/whatsapp.log" # MySQL config DBUSER="bacula" DBPASSWORD="bacula" DBNAME="bacula" $YOWSEXEC demos --config $CONF --send $RECIPIENT_NUMBER "`echo -e "$MESSAGE${COUNT}"`" &>> $LOG FMSG=`echo -e "$MESSAGE${COUNT}"` $YOWSEXEC --data-urlencode msg="$FMSG" &>> $LOG chmod +x /etc/bacula/send_whatsapp.sh Command = "/etc/bacula/send_whatsapp.sh %i" 
Source: https://habr.com/ru/post/327404/
All Articles