Advertisements
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
configured.
2. SMS gateway account and API details: For this testing purpose we have used sms gateway provided by
clickatell.com. We have used their HTTP API for this. We need following credentials to use this.
● Username of clickatell.com account
● Client ID
● API 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
Commands.cfg
Add the following lines to the commands.cfg file in order to send sms notifactions via HTTP API of
clickatell.com. 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:
$NOTIFICATIONTYPE$\nHost: $HOSTNAME$ \nState: $HOSTSTATE$\nAddress:
$HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | wget "http:
//api.clickatell.com/http/sendmsg?
user=USERNAME&password=PASSWORD&api_id=API_ID&to=$CONTACTPAGER$&text='**
$NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ @ $LONGDATETIME$ **'"
}
# service-notify-by-sms
define command{
command_name service-notify-by-sms
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type:
$NOTIFICATIONTYPE$\nHost: $HOSTNAME$ \nState: $HOSTSTATE$\nAddress:
$HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | wget "http:
//api.clickatell.com/http/sendmsg?
user=USERNAME&password=PASSWORD&api_id=API_ID&to=$CONTACTPAGER$&text='**
$NOTIFICATIONTYPE$ Service Alert: $SERVICEDESC$ on $HOSTNAME$ State:
$SERVICESTATE$ @ $LONGDATETIME$ **'"
}
Contacts.cfg
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
#Wget http://api.clickatell.com/http/sendmsg?
user=USERNAME&password=PASSWORD&api_id=API_ID53&to=MOBILE_NUMBER&t
ext=Message
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
refused
[1335345487] SERVICE ALERT: nagios-server;MYSQL;CRITICAL;HARD;4;Connection
refused
[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 clickatell.com only.
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.
ReplyDelete