Introduction
One of the most important feature of the monitoring platform is the notification system; by default they use the local mail daemon (postfix, mail, exim) installed on the server to send the notifications.
Using local mail daemon has many issues :
- You need to install and configure your smtp server.
- Maybe your mail server go down so you can’t receive the alert.
- Maybe this kind of emails from a not verified source like nagios can be filtered by the same company antispam system.
In order to avoid all issues, In this article I am going to explain how to send alert from monitoring tool Nagios Core using SMS.
This task was not so easy since communicating with the smsgateway through a linux server was requiring to install smstools.
If you still didn’t install Nagios Core , check the following articles.
- Install and Configure Nagios On CentOS, RHEL, Scientific Linux 6.5/6.4
- Install and configure Nagios 4 In CentOS 7
- Install and configure Nagios 4 in Ubuntu 15.04
Install SmsTools
The SMS Server Tools are made to send and receive short messages through GSM modems. It supports easy file interfaces and it can run external programs for automatic actions.
To be able to send SMS in a team with Linux will need the following:
- A modem GSM GPRS.
- A card SIM mobile with data activated to be able to send SMS. It is convenient to review that the sending of SMS works properly inserting the card SIM in a mobile and sending a SMS .
- Coverage of the mobile network in the zone where place the modem GSM: obviously it has to have coverage of the mobile network so that it work the sending of SMS from the modem GSM.
Then you insert the card SIM in the modem GSM and will connect the modem GSM by USB to the server where nagios is hosted.
In this tuto we will show to how to configure Nagios to send sms hosted in Vmware.
Next step is to add usb controller to the nagios server.
Then choose your mobile phone.
Then check your configuration using dmesg | grep tty. You should see usb port (ttyACM0)
Now you need to install the smstool under nagios server using the flowing command in centos:
yum install smstools
Make Sure you have the Following SMSTOOLS3 SERVER Files and Folders Installed
- incoming = /var/spool/sms/incoming
- outgoing = /var/spool/sms/outgoing
- checked = /var/spool/sms/checked
- failed = /var/spool/sms/failed
- sent = /var/spool/sms/sent
- logfile = /var/log/smsd.log
- Configuration = /etc/smsd.conf
Also make sure that SMSTools has the Right Configuration Setting for your modem in: /etc/smsd.conf
( GSM Modem is on ttyACM0 in this example)
device = /dev/ttyACM0
Next step is to configure smstool service to autorun with the server.
chkconfig smsd on
Then restart the service using this command:
service smsd restart
Then you can test to send sms
sendsms 12128654549 'test'
Nagios Configuration
After this go under /usr/local/nagios/etc/objects/ and edit the file commands.cfg but that perform a backup of the config file:
cd /usr/local/nagios/etc/objects/
cp commands.cfg commands.cfg.oldEdit the commands.cfg file and you will add two commands ‘notify-host-by-sms’ and ‘notify-service-by-sms’ notify-host-by-sms
/usr/bin/printf “%b” ” hostname : $HOSTNAME$ State: $HOSTSTATE$ Address: $HOSTADDRESS$ Date/Time: $DATE$ ” | smssend $CONTACTPAGER$
notify-host-by-whatsapp
/usr/bin/printf “%b” ” $SERVICEDESC$ State: $SERVICESTATE$ Date/Time: $LONGDATETIME$ ” | smssend $CONTACTPAGER$
And we should define the contact under contacts.cfg file like this example
contact_name admin use generic-contact alias Admin email admin@unixmen.com pager xxxxxxxxxxxxxxxxxxxxx service_notification_commands notify-service-by-email notify-service-by-sms host_notification_commands notify-host-by-email notify-host-by-sms
Now the configuration is finished. Before applying the new configuration, run the following command to check for any error or mistake:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there are no errors, restart the nagios service:
service nagios restart