
The dude. Sending SMS Notifications
I would like to talk about a little refinement of the monitoring system Mikrotik The Dude. This system was already mentioned by gsandul and cedr . The revision that will be discussed, I once described in my blog, but here more people can see and evaluate it.
So, in short: The Dude is a fairly powerful and flexible network device monitoring system that supports various types of service availability checks and can interrogate devices via SNMP. It supports two types of sending event messages to the outside world: e-mail and syslog.
To notify the administrator via SMS about any alerts, you can go in the traditional way - that is, through the email-sms gateway, but in this case there is a chance that when the uplink falls the system will not reach the gateway and the message will not be sent. On the other hand, I had a Huawei E220 modem from somewhere outside the red-and-white operator, a corporate SIM card with conditionally unlimited SMS and the machine itself, on which The Dude was standing, it worked through wine under Ubuntu.
So, we connect the modem to the same machine on which Dude runs through wine. Ubuntu cheerfully defines it:
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 put firewood and a control program under Windows from it, which puts it into modem mode. Here the usb-modeswitch package will come to our aid. Install it and execute the command:
After that, you need to disconnect and reconnect the modem. We check that he switched to the desired mode:
If ttyUSB ports did not appear, then you need to additionally run the command:
Now everything should be in order. For work with SMS messages we will use gnokii. Install, configure:
Be sure to remove the PIN request from the SIM card. We check:
So gnokii identifies the modem and sees the network. Trying to send SMS:
If the SMS is delivered as intended, then everything works. Let's move on to setting up a bunch of gnokii with The Dude. She, as I said, can send event notifications in two ways: by e-mail or through syslog. Just in the second way we will use it, since you can set any external IP and any port to which notifications will be sent in clear text over UDP. Our task is to listen to the port where The Dude will send them, and send these messages to gnokii. To do this, I wrote a small script in perl:
As you can see from the code, the script listens on port 12345 and transmits all messages arriving into it no longer than 160 characters (maximum SMS message length) to gnokii, indicating the mobile number where to send them.
In Dude, create a new syslog type alert, specify the IP address of the machine where the modem is connected and the script is running as IP (in my case it is the same server), select the port similar to that 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 a script modification that allows sending SMS notifications via any 3G modem connected to Asterisk via chan_dongle.
So, in short: The Dude is a fairly powerful and flexible network device monitoring system that supports various types of service availability checks and can interrogate devices via SNMP. It supports two types of sending event messages to the outside world: e-mail and syslog.
To notify the administrator via SMS about any alerts, you can go in the traditional way - that is, through the email-sms gateway, but in this case there is a chance that when the uplink falls the system will not reach the gateway and the message will not be sent. On the other hand, I had a Huawei E220 modem from somewhere outside the red-and-white operator, a corporate SIM card with conditionally unlimited SMS and the machine itself, on which The Dude was standing, it 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 put firewood and a control program under Windows from it, which puts it into modem mode. Here the usb-modeswitch package will come to our aid. 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. We check that he switched to the desired mode:
~# ls -l /dev | grep ttyUSB
lrwxrwxrwx 1 root root 7 2011-12-30 15:00 gsmmodem -> ttyUSB0
crw-rw—- 1 root dialout 188, 0 2011-12-31 15:09 ttyUSB0
crw-rw—- 1 root dialout 188, 1 2011-12-30 15:00 ttyUSB1
If ttyUSB ports did not appear, then you need to additionally run the command:
~# modprobe usbserial vendor=0x12d1 product=0×1003
Now everything should be in order. For work with SMS messages we will use gnokii. Install, configure:
[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. We check:
~# gnokii --identify
GNOKII Version 0.6.29
IMEI : ***************
Manufacturer : huawei
Model : E220
Product name : E220
Revision : 11.117.10.00.184
~# gnokii --getnetworkinfo
GNOKII Version 0.6.29
Network : MTS (Российская Федерация)
Network code : 250 01
LAC : 0000 (0)
Cell id : 00000000 (0)
So gnokii identifies the modem and sees the network. Trying to send SMS:
~# echo test | gnokii --sendsms +7**********
GNOKII Version 0.6.29
Send succeeded with reference 40!
If the SMS is delivered as intended, then everything works. Let's move on to setting up a bunch of gnokii with The Dude. She, as I said, can send event notifications in two ways: by e-mail or through syslog. Just in the second way we will use it, since you can set any external IP and any port to which notifications will be sent in clear text over UDP. Our task is to listen to the port where The Dude will send them, and send these messages to gnokii. To do this, I wrote a small script in perl:
#!/usr/bin/perl -w
use strict;
use IO::Socket;
my($server, $newmsg,
$max_len, $server_port);
$max_len = 160;
$server_port = 12345;
$server = IO::Socket::INET->new(LocalPort=>$server_port, Broadcast=>0, Proto=>"udp")
or die "Error starting UDP Server on port $server_port: $@\n";
print "UDP Server started on port $server_port\n";
$newmsg = "";
while($server->recv($newmsg,$max_len)){
if($newmsg){
#my($port, $ipaddr) = sockaddr_in($server->peername);
print "Received: $newmsg \n";
open(GNOKII, "| gnokii --sendsms +7**********») || die "Starting gnokii failed: $!\n";
print GNOKII $newmsg;
close(GNOKII);
}
}
die "recv: $!";
As you can see from the code, the script listens on port 12345 and transmits all messages arriving into it no longer than 160 characters (maximum SMS message length) to gnokii, indicating the mobile number where to send them.
In Dude, create a new syslog type alert, specify the IP address of the machine where the modem is connected and the script is running as IP (in my case it is the same server), select the port similar to that 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 a script modification that allows sending SMS notifications via any 3G modem connected to Asterisk via chan_dongle.