etc/serresponse
6dc8cd5a
 #!/bin/sh 
 #
 # $Id$
 #
 # use to check whether ser is still responding; if not mail an alert
 #
 
 
 NOTIFY=sr@iptel.org
e71148ce
 SIPSAK=/home/srouter/sipsak/sipsak
52ffe8f9
 SIPURI=sip:sipsak@iptel.org
b5450555
 LOCKDIR=/var/lock
 LOCKFILE=serresponse
 LOCK_TIMEOUT=240
6dc8cd5a
 TMP=/tmp/serresponse.$$
63103639
 MAILCOMMAND=/bin/mail
41845f2d
 HOSTN=`hostname`
e71148ce
 SMSSEND=/home/sms/smstools/bin/putsms
 SMSDEVICE=/dev/ttyS0
 SMSNUMBERS="491795061546"
6dc8cd5a
 
b5450555
 ############################
 
 LOCKF=$LOCKDIR/$LOCKFILE
5cf9d084
 TMP2=$TMP.dns
 TMP3=$TMP.ips
e71148ce
 SIPSAKCMD="$SIPSAK -v -s $SIPURI"
 SIPSAKNCMD="$SIPSAK -v -n -s $SIPURI"
 SMSCMD="$SMSSEND -d$SMSDEVICE -b9600"
b5450555
 
 if [ -e $LOCKF ] ; then
 	find $LOCKDIR -name $LOCKFILE -amin +$LOCK_TIMEOUT -exec rm {} ';'
 	if [ ! -e $LOCKF ] ; then
 		echo "This is a reminder !!!" > $TMP
 		echo "The lockfile $LOCKF" >> $TMP
 		echo "was just removed because ist was older then $LOCK_TIMEOUT minutes." >> $TMP
 		echo "But if you receive this mail the cause of this error still exists or respawned." >> $TMP
 	fi
 fi
 
 if [ ! -e $LOCKF ] ; then
e71148ce
 	if [ ! -x $SIPSAK ] ; then
 		echo "serresponse did not find the required sipsak executable $SIPSAK" >> $TMP
6dc8cd5a
 	else
830e791a
 		date >> $TMP2
e71148ce
 		echo "  $SIPSAKCMD" >> $TMP2
5cf9d084
 		echo "produced this output:" >> $TMP2
e71148ce
 		$SIPSAKCMD >> $TMP2 2>&1
 		if [ $? -eq 3 ] ; then
4c0f4376
 			grep "Connection refused" $TMP2
 			if [ $? -eq 0 ] ; then
 				sleep 15
 			fi
830e791a
 			date >> $TMP3
e71148ce
 			echo "  $SIPSAKNCMD" >> $TMP3
5cf9d084
 			echo "produced this output:" >> $TMP3
e71148ce
 			$SIPSAKNCMD >> $TMP3 2>&1
 			if [ $? -le 1 ] ; then
5cf9d084
 				echo "ser did not responses (fast enough) on the sipsak requests with fqdn in Via" >> $TMP
 				echo "but the test with IPs in Via succeeded." >> $TMP
 				echo "" >> $TMP
41845f2d
 				echo "Sending this alert is stopped for $LOCK_TIMEOUT minutes." >>$TMP
 				echo "If you want to re-enable alerts sooner, please remove the lock file" >> $TMP
99431bf5
 				echo "$LOCKF @ $HOSTN" >> $TMP
 				echo "(you presumably need to be root to do this)" >> $TMP
41845f2d
 				echo "" >> $TMP
830e791a
 				echo "Command output of sipsak with fqdn in Via follows:" >> $TMP
5cf9d084
 				cat $TMP2 >> $TMP
 			else
 				echo "ser did not responses (fast enough) on requests with fqdn in Via" >> $TMP
 				echo "but also requests with IPs in Via failed." >> $TMP
 				echo "" >> $TMP
41845f2d
 				echo "Sending this alert is stopped for $LOCK_TIMEOUT minutes." >>$TMP
 				echo "If you want to re-enable alerts sooner, please remove the lock file" >> $TMP
99431bf5
 				echo "$LOCKF @ $HOSTN" >> $TMP
 				echo "(you presumably need to be root to do this)" >> $TMP
41845f2d
 				echo "" >> $TMP
830e791a
 				echo "First command output with fqdn in Via:" >> $TMP
5cf9d084
 				cat $TMP2 >> $TMP
99431bf5
 				echo "" >> $TMP
 				echo "Second command output with IPs in Via:" >> $TMP
5cf9d084
 				cat $TMP3 >> $TMP
 			fi
 			rm -f $TMP3
 			rm -f $TMP2
99431bf5
 		elif [ $? -eq 2 ] ; then
 			echo "The ser response test failed due to a local error on" >> $TMP
 			echo "host $HOSTN ." >> $TMP
 			echo "" >> $TMP
 			echo "Sending this alert is stopped for $LOCK_TIMEOUT minutes." >>$TMP
 			echo "If you want to re-enable alerts sooner, please remove the lock file" >> $TMP
 			echo "$LOCKF @ $HOSTN" >> $TMP
 			echo "(you presumably need to be root to do this)" >> $TMP
 			echo "" >> $TMP
 			echo "Command output of sipsak with fqdn follows:" >> $TMP
 			cat $TMP2 >> $TMP
 			rm -f $TMP2
5cf9d084
 		else
 			rm -f $TMP2
6dc8cd5a
 			rm -f $TMP
 		fi
 	fi
 	
 	if [ -e $TMP ] ; then
 		$MAILCOMMAND -s "serresponse failed" $NOTIFY < $TMP
b17d7550
 		rm -f $TMP
 		touch $LOCKF
e71148ce
 		for i in $SMSNUMBERS; do
 			$SMSCMD $i "serresponse failed. please check your emails for details"
 		done
6dc8cd5a
 	fi
 fi