#!/bin/bash
#cat > /tmp/nagiosalert.tmp
#kill minicom process
cd ~
#Add mobile phone NO.
phone=(0123456789 09123456789)
#Nagios alert messages
SOURCE_IP=$(cat /tmp/nagiosalert.tmp |grep Address |cut -d: -f 2)
SOURCE_IP=`sed -n '/Address/s/Address://p' /tmp/nagiosalert.tmp`
DIP=`sed -n '/Address/s/Address://p' /tmp/nagiosalert.tmp`
SOURCE_USER_NAME="Nagios"
SOURCE_HOST_NAME=`sed -n '/Host/s/Host://p' /tmp/nagiosalert.tmp`
DTSTR=`date`
ET=$(date -d "$DTSTR" +%F~%T~24~+0800)
DEVICE_EVT_TIME=$(date -d "$DTSTR" +%s)000
#MESSAGE="Device=$SOURCE_HOST_NAME,IP Address=$SOURCE_IP.Device Down"
MESSAGE="Alert Messages!!Host is $SOURCE_HOST_NAME,IP Address is $SOURCE_IP.Host Down or Unreachable!!"
#check sms.txt , if sms.txt exit,the script sleep 30 second, if sms.txt not exit , the will keep going..
while [ -e /tmp/sms.txt ]
do
sleep 30
done
#send sms messages, each messages will delay 5 second!
echo $MESSAGE > /tmp/sms.txt
for ((i=0; i<${#phone[@]}; i++)); do
echo -en "AT+CMGF=1\r" > /dev/ttys0
echo -en "AT+CMGS=\"${phone[$i]}\"\r" > /dev/ttyS0
echo -en "$MESSAGE \032" > /dev/ttyS0
sleep 5
done
rm -rf /tmp/sms.txt
exit
沒有留言:
張貼留言