📜 ⬆️ ⬇️

Zabbix alerts via sms using GSM modem. Easy setup



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

Searching on the internet for sending sms to Zabbix, I found solutions , but they seemed to be long. Therefore, I did it in my own way. I will try to describe in detail not a complicated working solution and “rakes”.

So, what I had was:
')
  1. Zabbix 2.4 on OC Debian 7 - monitors several servers, one of them is connected via USB cable APC smart ups 3000. Monitoring the status of the UPS is configured for this article .
  2. GSM modem Huawei e1550 (Megaphone) which was lying 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 reconfiguration!

To send sms from the terminal, I used gnokii.

Go:

# apt-get install gnokii 

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. 


Check whether it was defined as a modem:

 # ls /dev/ttyUSB* 

If empty (and I was empty):

 # apt-get install usb-modeswitch 

We take out and re-insert the modem.

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!

We create gnokii config. I put it in / home

 # nano /home/user/sms.conf 

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


Save and test:

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

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

Sms should come without problems. All of this has a lot of instructions 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 be logged open, logs will be directed to stderr

This means there was no file in the path:

  ~ / .cache / gnokii / gnokii-errors 


Change permissions for user to use sudo without password:

 # nano /etc/sudoers 

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


Further we log in under the user of zabbix and we write 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"



We save. It is / usr / bin / sudo and / usr / bin / gnokii - this turned out to be important for me!

Do not forget to do from the root:

 # chmod +x /home/user/smsscript 

Check the script work:

 /home/user/smsscript +7XXXXXXXXXX test 

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

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

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

In the interface of the zabbiks we go to Administration - Alert methods.

Create an alert method.

image

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

image

And Setup - Actions.

image

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

image

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

PS: Since electricity is not often disconnected, then the cost of sms is very small.

Source: https://habr.com/ru/post/270497/


All Articles