Configure:Send SMS with Gammu
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).
Warning for virtual machines users : Proper working isn't guaranteed, you need to connect the GSM modem to the VM through the host machine !
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 GMS 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" !

