Friday, April 27, 2012

sms notification using nagios


We have discussed how to install and configure nagios monitoring system and configuring nrpe with nagios in previous posts. But it sends only email notifications. What if we are not able to access mail? Internet is not working? Or forgot to check the mails. So it is always better to have a better notification system. Notifications via SMS is an alternative. We can know if a service or host is down by sms even if dont check mail. But how to enable notifications via sms? What are the requirements? Which files needs to modified? How to configure sms gateway? We discuss all these things in this post.

Requirements :
To set up sms alerts notification with nagios we need a few things.
1. Existing Nagios implementation: -We need a working Nagios implementation with email alerts are already
2. SMS gateway account and API details: For this testing purpose we have used sms gateway provided by We have used their HTTP API for this. We need following credentials to use this.

● Username of account
● Client ID
● Password
● Mobile numbers

Configuration :
We have to edit mainly two configuration files and include the fields required for configuring alerts via sms.

1. Commands.cfg
We have to add the commands for
● Host notification via sms
● Service notification via sms
Only via mail will be defined by default.

2. Contacts.cfg
We have to add the commands defined in commands.cfg for notifications via sms in
● Service notification commands
● Host notification commands
● Mobile numbers
● Notification periods
● Notification options

Add the following lines to the commands.cfg file in order to send sms notifactions via HTTP API of The fields USERNAME,PASSWORD and API_ID needs to be replaced with
original ones.
# host-notify-by-sms
define command{
command_name host-notify-by-sms
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type:
$HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | wget "http:

# service-notify-by-sms
define command{
command_name service-notify-by-sms
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type:
$HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | wget "http:

The following lines need to be added in contacts.cfg
service_notification_options            w,u,c,r,f,s #statuses –warning/critical/fapping/restarted etc.
host_notification_options                d,u,r,f,s
service_notification_commands       notify-service-by-email service-notify-by-sms #mail and sms
host_notification_commands           notify-host-by-email host-notify-by-sms
pager                                             91xxxxxxxxxx #mobile number
service_notification_period             24x7    #Notifications will be sent 24x7
host_notification_period                 24x7

IF you want to get notified to multiple numbers, define multiple contacts.

Testing :
We can test the Gateway using a simple command from the command line

We can test the alerts working by stopping a service such as mysql and checking the
mobile for the sms. If the service is working properly we will get the following lines in Nagios log file.

#tail -f   /usr/local/nagios/var/nagios.log
[1335345427] SERVICE ALERT: nagios-server;MYSQL;CRITICAL;SOFT;3;Connection
[1335345487] SERVICE ALERT: nagios-server;MYSQL;CRITICAL;HARD;4;Connection
[1335345487] SERVICE NOTIFICATION: nagiosadmin;nagios-server;MYSQL;CRITICAL;
service-notify-by-sms;Connection refused
[1335345488] SERVICE NOTIFICATION: nagiosadmin;nagios-server;MYSQL;CRITICAL;
notify-service-by-email;Connection refused

We will get the sms’ with original content only after we buy credit. Else we will get a test
success notification from only.

1 comment:

  1. These configurations are hectic and sometimes they dont work. The best is to try Nagios SMS Alerts. It sends out SMS text message to you whenever you get email from nagios. Its fast and works in more than 200 counties. Try it.


Be nice. That's all.