I would like to talk about a minor refinement of the monitoring system Mikrotik The Dude. This system was previously
mentioned by the
gsandul and
cedr habrauser . I once described the revision that will be discussed in my blog, but here more people will be able to see and appreciate it.
So, in short: The Dude is a fairly powerful and flexible system for monitoring network devices, supporting various types of service availability checks and able to interrogate devices via SNMP. It supports two types of sending event messages to the outside world: e-mail and syslog.
To notify the admin via SMS about any alerts, you can go in the traditional way - that is, via email-sms gateway, but in this case there is a possibility that if the uplink falls, the system will not reach the gateway and the message will not be sent. I also had a Huawei E220 3G modem from a red and white operator, a corporate SIM with conditional unlimited SMS, and the actual machine itself, on which The Dude stood, that I had worked through wine under Ubuntu.
')
So, we connect the modem to the same machine on which Dude runs through wine. Ubuntu cheerfully defines it:
Bus 003 Device 002: ID 12d1:1003 Huawei Technologies Co., Ltd. E220 HSDPA Modem / E270 HSDPA/HSUPA Modem
However, the system sees the modem as a USB CD-ROM. It is logical, because in this mode the modem works by default in order to install firewood and a control program from it under Windows, which transfers it to modem mode. This is where the usb-modeswitch package comes to our rescue. Install it and execute the command:
echo 'SUBSYSTEM==»usb», SYSFS{idProduct}==»1003″, SYSFS{idVendor}==»12d1″, RUN+=»/lib/udev/modem-modeswitch –vendor 0x12d1 –product 0×1003 –type option-zerocd»' | sudo tee /etc/udev/rules.d/45-huawei220.rules
After that, you need to disconnect and reconnect the modem. Check that he switched to the desired mode:
~
If the ttyUSB ports did not appear, then you need to additionally run the command:
~
Now everything should be fine. We will use gnokii to work with SMS messages. Install, customize:
[global] port = /dev/ttyUSB0 model = AT initlength = default connection = serial use_locking = yes serial_baudrate = 115200
Be sure to remove the PIN request from the SIM card. Checking:
~
So gnokii detects the modem and sees the network. We try to send SMS:
~
If the SMS is delivered to the destination, then everything works. Go to setting up a bunch of gnokii with The Dude. She, as I said, can send event notifications in two ways: via e-mail or via syslog. We will use the second way, the benefit is to set any external IP and any port to which notifications will be sent via UDP protocol in clear form. Our task is to listen to the port where The Dude will send them, and transmit these messages to gnokii. For this, I wrote a small perl script:
As can be seen from the code, the script listens on port 12345 and transmits all messages arriving in it no longer than 160 characters (maximum length of an SMS message) in gnokii, indicating the mobile number where to send them.
In Dude, we create a new syslog-type alert, set the IP address of the machine as the IP where the modem is connected and the script is running (in my case it is the same server), choose the port similar to the one specified in the script.

Now click "Test". If everything is done correctly, a test message from The Dude will be sent to the number indicated in the script.
Update. If the material is of interest - I will describe the modification of the script that allows you to send SMS notifications via any 3G modem connected to Asterisk via chan_dongle.