HowToSendSMSWithGammu
From Wiki Centreon
Centreon can already send mail alerts, but for on call people who aren't on a computer checking mails, this can be useful. You need to own a GSM modem, wired and configured (PIN OK, network OK). Alternatively it is possible to get an older GSM mobile phone and a USB-Adapter with DATA and Power support (example: CA-70 for Nokia phones).
Contents |
Gammu Installation
sudo apt-get install gsm-utils gammu
Enventually add --fix-missing if it doesn't work!
Gammu Configuration
Now you need to find your GSM modem!
sudo gsmctl -d /dev/ttyS0
You need to know if your GSM is wired with serial or USB cable. To do this, look in /dev and try the different serial ports (ttyS0,ttyS1, ...) and USB (usb1,usb2,...).
If the command doesn't return any answer, you're on the right port! Otherwise try another one.
Once you found it we can continue!
To configure gammu, we need to import the example configuration file :
cp /usr/share/doc/gammu/examples/config/gammurc.gz /etc/gammurc.tar.gz cd /etc tar -zxf gammurc.gz
(however the extraction might not work, try using a graphical interface to extract it, or find another way)
Open the gammurc file
sudo gedit /etc/gammurc
Edit the following lines : (put ; (semicolons) before the other lines)
[gammu] port= /dev/ttyS0 connection = 115200
- the first line is the output port
- the second one is the rate which will be used to communicate (look in your GSM's user manual to find it)
Save.
SMS Sending test
sudo echo "sms test" | /usr/bin/gammu --sendsms TEXT +336xxxxxxxx
NB : TEXT isn't to be replaced by a text, leave it as is !
Wait a bit and it should work !
Granting SMS Sending Authorization to Nagios and www-data
First, we must allow www-data to send sms, thus to write in ttyS0 (or wherever your GSM modem is plugged in)
Check this first :
ls -l /dev/ttyS0
This should send that line back to you : (or something like that)
crw-rw---- 1 root dialout 4, 64 2008-05-21 14:23 ttyS0
We notice the usergroup is dialout and the owner is root. We won't change the owner, or it could cause conflicts.
So, we will add www-data (or apache) and nagios to the dialoutgroup
sudo usermod -G dialout nagios sudo usermod -G dialout www-data
You can now try to send an SMS :
su nagios echo "sms test" | /usr/bin/gammu --sendsms TEXT +336xxxxxxxxx
This should work, otherwise recheck the rights on gammu (or at worse change the owner but it is not advised)
Configuration on Centreon
Go to Configuration > Commands > Notification commands
Click on « Add » We will start with host-notify-by-sms :
/usr/bin/printf "%b" "Alert $HOSTNAME$ is $HOSTSTATE$" | /usr/bin/gammu --sendsms TEXT $CONTACTPAGER$
Then notify-by-sms :
/usr/bin/printf "%b" "Alert service $SERVICEDESC$ on $HOSTNAME$" is $SERVICESTATE$ | /usr/bin/gammu --sendsms TEXT $CONTACTPAGER$
Here it is it should give enough informations in the message, it would be useless to overload it.
Then go to Configuration > Users
And edit the pager field, by adding the number to contact when sending an sms, and add the notify-by-sms/host-notify-by-sms notifications to this user!
Voila we're done with these SMS! Enjoy receiving your alerts at 4 o'clock in the morning saing "Server XXXX is DOWN" !
VMWare Support
Warning for virtual machines users : Proper working isn't guaranteed, you need to connect your GSM modem or phone to the VM through the host machine! For VMWare and an USB cable as described above you can adopt the device0 entry, which must match the lsusb line, and add the following lines to your *.vmx file:
usb.present = "TRUE" usb.generic.autoconnect = "TRUE" usb.autoConnect.device0 = "name:Nokia"
Additionaly configure your cron daemon (or nagios itself) on the guest to check, that the phone is connected and responds by using a script like
#!/bin/sh connected=$(/usr/sbin/lsusb | /bin/grep -q Nokia; echo $?) if [ "$connected" = "0" ]; then check=$(/usr/bin/gammu --identify >/dev/null; echo $?) if [ "$check" = "0" ]; then exit 0 fi fi echo ' Please check Nagios/Centreon setup! ' | mail -s 'GSM Check @Monitor - NO phone found!' alert@mydomain.com exit 3
Troubleshooting
If sending doesn't work the following information may help in identifying the problem source.
- The notification command is executed as nagios user and implies his access rights. This is the reason, why user nagios should have access to gammu and belong to a user group with access to /dev/ttyS0. However the command seems not to be executed in a login shell, so $HOME is NOT set and ~/.gammurc can't be used.
- For debugging it might be helpful to wrap the above commands in a shell script, where additional debugging output may be inserted (for example by echo into a temp file or using the logger command).
- As first measure it is helpful to log in as nagios and execute the notification command by hand to check it is indeed working.

