SMS Notifications in Nagios XI
Posted: Tue Apr 14, 2015 3:30 am
I am using Nagios XI in order to monitor many servers across our infrastructure. I have been getting email notifications successfully, but wish to configure SMS notifications in Nagios XI.
The main problem is, SMS gateway is on another server and in order to send any SMS from Nagios server, I need to use ssh as follows:
where, send_sms_script.sh is the script that takes to parameters - contact_list.txt, list of contact numbers to which SMS is to be sent and message.txt is the file that bears the actual message.
In order to send any Nagios notification to a user, the message.txt has to be edited accordingly with the service/host details. For that, I chose to edit the file message.txt before sending any SMS notification.
With these considerations, I created a command notify_service_by_sms.sh on Nagios server as follows:
I tested the above script with following command to verify that it works well, and it worked well too:
Then I created a command notify-service-by-sms in Nagios XI (CCM > Commands) as follows:
Then, in CCM > Contacts, I selected a user and in "Alert Settings" tab, I selected 'notify-service-by-email' and 'notify-service-by-sms' as the "Service Notification Commands".
I also made sure that, this particular user is allocated a particular service that is always in critical condition, so that I get notified periodically (5 minutes).
After saving the configurations, I could find that, I am getting email notifications, but SMS notifications are not being received.
Can you please advice me in this concern?
The main problem is, SMS gateway is on another server and in order to send any SMS from Nagios server, I need to use ssh as follows:
Code: Select all
ssh -i /path/to/ssh-key user@SMS-GATEWAY '/path/to/send_sms_script.sh /path/to/contact_list.txt /path/to/message.txt'In order to send any Nagios notification to a user, the message.txt has to be edited accordingly with the service/host details. For that, I chose to edit the file message.txt before sending any SMS notification.
With these considerations, I created a command notify_service_by_sms.sh on Nagios server as follows:
Code: Select all
#!/bin/bash
while read line
do
DATA="$line"
done
SDESC=`echo $DATA | awk -F"," '{print $1}'`
HALIAS=`echo $DATA | awk -F"," '{print $2}'`
SSTATE=`echo $DATA | awk -F"," '{print $3}'`
SDATE=`echo $DATA | awk -F"," '{print $4}'`
ADDINFO=`echo $DATA | awk -F"," '{print $5}'`
SMSG="/path/to/message.txt"
SCONT="/path/to/contact_list.txt"
MSG="**Nagios Alert**\nService:$SDESC\nHost:$HALIAS\nState:$SSTATE\nTime:$SDATE\nAdditional Info:$ADDINFO"
/usr/bin/ssh -i /path/to/ssh-key user@SMS-GATEWAY "echo \"$MSG\" > /path/to/message.txt && /path/to/send_sms_script.sh /path/to/contact_list.txt /path/to/message.txt"Code: Select all
printf "%b" "Load Average,Test Host,Warning,14-Apr-2015 14:00,Test Info" | /usr/local/nagios/libexex/notify_service_by_sms.shCode: Select all
/usr/bin/printf "%b" "$SERVICEDESC$,$HOSTALIAS$,$SERVICESTATE$,$LONGDATETIME$,$SERVICEOUTPUT$\n" | /usr/local/nagios/libexec/notify_service_by_sms.shI also made sure that, this particular user is allocated a particular service that is always in critical condition, so that I get notified periodically (5 minutes).
After saving the configurations, I could find that, I am getting email notifications, but SMS notifications are not being received.
Can you please advice me in this concern?