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?