File: serresponse

package info (click to toggle)
kamailio 6.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 70,472 kB
  • sloc: ansic: 859,394; xml: 203,514; makefile: 9,688; sh: 9,105; sql: 8,571; yacc: 4,121; python: 3,086; perl: 2,955; java: 449; cpp: 289; javascript: 270; php: 258; ruby: 248; awk: 27
file content (137 lines) | stat: -rwxr-xr-x 4,555 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/sh 
#
# $Id$
#
# PLEASE configure before use !!!
#
# This script uses sipsak (http://sipsak.berlios.de) to test if a
# SIP server is still responding to requests and will send messages
# to the developers. It is configured for the iptel.org environment.
# PLEASE adapt it to your local environment.
#

NOTIFY=sr@iptel.org
SIPSAK=/home/srouter/sipsak/sipsak
SIPURI=sip:sipsak@iptel.org
LOCKDIR=/var/lock
LOCKFILE=serresponse
LOCK_TIMEOUT=240
TMP=/tmp/serresponse.$$
MAILCOMMAND=/bin/mail
HOSTN=`hostname`
RUNHOST=iptel.org
SMSSEND=/home/sms/smstools/bin/putsms
SMSDEVICE=/dev/ttyS0
SMSNUMBERS=""

############################

LOCKF=$LOCKDIR/$LOCKFILE
TMP2=$TMP.dns
TMP3=$TMP.ips
SIPSAKCMD="$SIPSAK -v -s $SIPURI"
SIPSAKNCMD="$SIPSAK -v -n -s $SIPURI"
SMSCMD="$SMSSEND -d$SMSDEVICE -b9600"

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 it was older than $LOCK_TIMEOUT minutes." >> $TMP
		echo "But if you receive this mail the cause of this error still exists or respawned." >> $TMP
		SERR_SUBJECT="serresponse reminder"
	fi
fi

if [ ! -e $LOCKF ] ; then
	if [ ! -x $SIPSAK ] ; then
		echo "serresponse did not find the required sipsak executable $SIPSAK" >> $TMP
		SERR_SUBJECT="serresponse config failure"
	elif [ ! -x $SMSSEND ]; then
		echo "serresponse did not find the required SMS send executable $SMSSEND" >> $TMP
		SERR_SUBJECT="serresponse config failure"
	else
		date >> $TMP2
		echo "  $SIPSAKCMD" >> $TMP2
		echo "produced this output:" >> $TMP2
		$SIPSAKCMD >> $TMP2 2>&1
		if [ $? -eq 3 ] ; then
			grep -i "Connection refused" $TMP2
			if [ $? -eq 0 ] ; then
				sleep 30
			fi
			date >> $TMP3
			echo "  $SIPSAKNCMD" >> $TMP3
			echo "produced this output:" >> $TMP3
			$SIPSAKNCMD >> $TMP3 2>&1
			if [ $? -le 1 ] ; then
				echo "ser did not responsed (fast enough) on the sipsak requests with fqdn in Via" >> $TMP
				echo "but the test with IPs in Via succeeded." >> $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 in Via follows:" >> $TMP
				cat $TMP2 >> $TMP
				SERR_SUBJECT="serresponse delayed"
			else
				echo "ser did not responsed (fast enough) on requests with fqdn in Via" >> $TMP
				echo "but also requests with IPs in Via failed." >> $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 "First command output with fqdn in Via:" >> $TMP
				cat $TMP2 >> $TMP
				echo "" >> $TMP
				echo "Second command output with IPs in Via:" >> $TMP
				cat $TMP3 >> $TMP
				SERR_SUBJECT="serresponse failed"
			fi
			rm -f $TMP3
			rm -f $TMP2
		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
			SERR_SUBJECT="serresponse local failure"
		else
			rm -f $TMP2
			rm -f $TMP
		fi
	fi
	
	if [ -e $TMP ] ; then
		if [ $HOSTN = $RUNHOST ] ; then
			$MAILCOMMAND -s "$SERR_SUBJECT" $NOTIFY < $TMP
			rm -f $TMP
			touch $LOCKF
			for i in $SMSNUMBERS; do
				$SMSCMD $i "serresponse failed. please check your emails for details"
			done
		else
			echo "unconfigured serresponse executed on ${HOSTN}." > $TMP
			echo "Warning: This script is configured for the iptel.org environment."
			echo "         Please configure it to your local settings first."
			echo
			echo "If you do not press CTRL-C within 2 seconds an informational message"
			echo "with your hostname will be sent to the ser developers."
			sleep 2
			$MAILCOMMAND -s "serresponse executed on ${HOSTN}" $NOTIFY < $TMP
			rm -f $TMP
		fi
	fi
fi