Zabbix alerts via SMS using a GSM modem. Easy setup



Zabbix server is good. Properly configured, it monitors the servers and the nodes I need. In case of problems with them, he happily notifies me by e-mail. Not so long ago, it turned out that both of our favorite providers (primary and backup Internet channels) decided not to provide the UPS with their network equipment in the building. Therefore, when electricity is cut off (and it happens!) Zabbix would be glad to wake up with a cheerful letter, but nothing! In general, I decided to bother with a notification via sms. It is through a GSM modem that there is no dependence on the Internet.

After searching the Internet for options to send sms to Zabbix, I found solutions , but they seemed to me long. Therefore, I did it my way "on my knee." I will try to describe in detail a non-complicated working solution and a "rake".

So what I had:

  1. Zabbix 2.4 on OC Debian 7 - monitors several servers, one of them is connected via APC smart ups 3000 USB cable. UPS status monitoring is configured for this article .
  2. GSM modem Huawei e1550 (Megaphone) that has been lying around at home since the absence of wired Internet. As practice has shown, inserting another Huawei modem into an already configured system still works without requiring a reconfiguration!

To send sms from the terminal, I used gnokii.

Go:

# apt-get install gnokii

We insert the GSM modem into the server and check:

# lsusb

Among other things, we see something like:

Bus 001 Device 009: ID 12d1: 14ac Huawei Technologies Co., Ltd.


We check whether it was determined as a modem:

# ls /dev/ttyUSB*

If it's empty (and I was empty):

# apt-get install usb-modeswitch

We pull out and reinsert the modem.

We check whether it was determined:

# ls /dev/ttyUSB*

We see something like:

/ dev / ttyUSB0 / dev / ttyUSB1 / dev / ttyUSB2


It remains a little before the first sending sms!

Create the gnokii config. I put it in / home

# nano /home/user/sms.conf

Config text
[global]
port = /dev/ttyUSB0
model = AT
initlength = defaultconnection = serial
use_locking = no
serial_baudrate = 115200


Save and test:

# echo "text" | gnokii --config /home/user/sms.conf --sendsms +7ХХХХХХХХХХ

(+ 7XXXXXXXXXXX - here, of course, the number to which you need to send)

SMS should come without problems. There are a lot of instructions about all this on the Internet, and until that moment I had no problems.

Further important!

Zabbix in the system works from the user zabbix. We allow him to use a modem.

# nano /etc/group

dialout: x: 20: zabbix


Otherwise, when sending from this user, we get something like:

GNOKII Version 0.6.30
Gnokii serial_open: open: Permission denied
Couldn't open ATBUS device: Permission denied
Telephone interface init failed: Command failed.
Quitting.
Command failed.


Even when sending I met an error:

Cannot open logfile ./gnokii-errors
WARNING: cannot open logfile, logs will be directed to stderr


This means there was no file on the path:

~ / .cache / gnokii / gnokii-errors


We change permissions for the user to use sudo without a password:

# nano /etc/sudoers

zabbix ALL = (ALL) NOPASSWD: / usr / bin / gnokii


Next, log in as user zabbix and write a very simple script.

 nano /home/user/smsscript


Script text
#!/bin/sh
zabbixesmsto=$1
zabbixsubject=$2
echo "$zabbixsubject" | /usr/bin/sudo /usr/bin/gnokii --config /home/user/sms.conf --sendsms "$zabbixesmsto"



Save. Namely / usr / bin / sudo and / usr / bin / gnokii - for me this turned out to be important!

Do not forget to do from the root:

# chmod +x /home/user/smsscript

Check the script:

/home/user/smsscript +7XXXXXXXXXX test

If sms arrived - everything is almost ready! It remains to fasten to Zabbix. If you didn’t come, then we check to see if everything was done as described above.

I created the script for the zabbix in / home / user / because in the zabbix_server.conf config it is written: AlertScriptsPath = / home / user /

If you have something wrong, either change the location of the script or change the path to / home / user / in the config - do not forget to restart the zabbix server!

In the Zabbix interface, go to Administration - Notification Methods.

Create a notification method.

image

Then we set up an alert for your user in the zabbix. Administration - Users.

image

And Customization - Actions.

image

I did a separate action so that sms did not come for every reason, but only when certain triggers were triggered. Since when sending in sms only the topic is written, there is no point in writing something to the message itself. And he added to the condition:

image

That's all! I pulled from the IPB outlet and after a few minutes received an angry sms from zabbiksa! Now he will get me everywhere, infection!

PS: Since electricity is not often turned off, there are very few sms costs.

Also popular now: