parser: some more const-correctness for the other functions in msg_parser.[c,h]
[sip-router] / etc / serresponse
1 #!/bin/sh 
2 #
3 # $Id$
4 #
5 # PLEASE configure before use !!!
6 #
7 # This script uses sipsak (http://sipsak.berlios.de) to test if a
8 # SIP server is still responding to requests and will send messages
9 # to the developers. It is configured for the iptel.org enviroment.
10 # PLEASE adapt it to your local enviroment.
11 #
12
13 NOTIFY=sr@iptel.org
14 SIPSAK=/home/srouter/sipsak/sipsak
15 SIPURI=sip:sipsak@iptel.org
16 LOCKDIR=/var/lock
17 LOCKFILE=serresponse
18 LOCK_TIMEOUT=240
19 TMP=/tmp/serresponse.$$
20 MAILCOMMAND=/bin/mail
21 HOSTN=`hostname`
22 RUNHOST=iptel.org
23 SMSSEND=/home/sms/smstools/bin/putsms
24 SMSDEVICE=/dev/ttyS0
25 SMSNUMBERS=""
26
27 ############################
28
29 LOCKF=$LOCKDIR/$LOCKFILE
30 TMP2=$TMP.dns
31 TMP3=$TMP.ips
32 SIPSAKCMD="$SIPSAK -v -s $SIPURI"
33 SIPSAKNCMD="$SIPSAK -v -n -s $SIPURI"
34 SMSCMD="$SMSSEND -d$SMSDEVICE -b9600"
35
36 if [ -e $LOCKF ] ; then
37         find $LOCKDIR -name $LOCKFILE -amin +$LOCK_TIMEOUT -exec rm {} ';'
38         if [ ! -e $LOCKF ] ; then
39                 echo "This is a reminder !!!" > $TMP
40                 echo "The lockfile $LOCKF" >> $TMP
41                 echo "was just removed because ist was older then $LOCK_TIMEOUT minutes." >> $TMP
42                 echo "But if you receive this mail the cause of this error still exists or respawned." >> $TMP
43                 SERR_SUBJECT="serresponse reminder"
44         fi
45 fi
46
47 if [ ! -e $LOCKF ] ; then
48         if [ ! -x $SIPSAK ] ; then
49                 echo "serresponse did not find the required sipsak executable $SIPSAK" >> $TMP
50                 SERR_SUBJECT="serresponse config failure"
51         elif [ ! -x $SMSSEND ]; then
52                 echo "serresponse did not find the required SMS send executable $SMSSEND" >> $TMP
53                 SERR_SUBJECT="serresponse config failure"
54         else
55                 date >> $TMP2
56                 echo "  $SIPSAKCMD" >> $TMP2
57                 echo "produced this output:" >> $TMP2
58                 $SIPSAKCMD >> $TMP2 2>&1
59                 if [ $? -eq 3 ] ; then
60                         grep -i "Connection refused" $TMP2
61                         if [ $? -eq 0 ] ; then
62                                 sleep 30
63                         fi
64                         date >> $TMP3
65                         echo "  $SIPSAKNCMD" >> $TMP3
66                         echo "produced this output:" >> $TMP3
67                         $SIPSAKNCMD >> $TMP3 2>&1
68                         if [ $? -le 1 ] ; then
69                                 echo "ser did not responsed (fast enough) on the sipsak requests with fqdn in Via" >> $TMP
70                                 echo "but the test with IPs in Via succeeded." >> $TMP
71                                 echo "" >> $TMP
72                                 echo "Sending this alert is stopped for $LOCK_TIMEOUT minutes." >>$TMP
73                                 echo "If you want to re-enable alerts sooner, please remove the lock file" >> $TMP
74                                 echo "$LOCKF @ $HOSTN" >> $TMP
75                                 echo "(you presumably need to be root to do this)" >> $TMP
76                                 echo "" >> $TMP
77                                 echo "Command output of sipsak with fqdn in Via follows:" >> $TMP
78                                 cat $TMP2 >> $TMP
79                                 SERR_SUBJECT="serresponse delayed"
80                         else
81                                 echo "ser did not responsed (fast enough) on requests with fqdn in Via" >> $TMP
82                                 echo "but also requests with IPs in Via failed." >> $TMP
83                                 echo "" >> $TMP
84                                 echo "Sending this alert is stopped for $LOCK_TIMEOUT minutes." >>$TMP
85                                 echo "If you want to re-enable alerts sooner, please remove the lock file" >> $TMP
86                                 echo "$LOCKF @ $HOSTN" >> $TMP
87                                 echo "(you presumably need to be root to do this)" >> $TMP
88                                 echo "" >> $TMP
89                                 echo "First command output with fqdn in Via:" >> $TMP
90                                 cat $TMP2 >> $TMP
91                                 echo "" >> $TMP
92                                 echo "Second command output with IPs in Via:" >> $TMP
93                                 cat $TMP3 >> $TMP
94                                 SERR_SUBJECT="serresponse failed"
95                         fi
96                         rm -f $TMP3
97                         rm -f $TMP2
98                 elif [ $? -eq 2 ] ; then
99                         echo "The ser response test failed due to a local error on" >> $TMP
100                         echo "host $HOSTN ." >> $TMP
101                         echo "" >> $TMP
102                         echo "Sending this alert is stopped for $LOCK_TIMEOUT minutes." >>$TMP
103                         echo "If you want to re-enable alerts sooner, please remove the lock file" >> $TMP
104                         echo "$LOCKF @ $HOSTN" >> $TMP
105                         echo "(you presumably need to be root to do this)" >> $TMP
106                         echo "" >> $TMP
107                         echo "Command output of sipsak with fqdn follows:" >> $TMP
108                         cat $TMP2 >> $TMP
109                         rm -f $TMP2
110                         SERR_SUBJECT="serresponse local failure"
111                 else
112                         rm -f $TMP2
113                         rm -f $TMP
114                 fi
115         fi
116         
117         if [ -e $TMP ] ; then
118                 if [ $HOSTN = $RUNHOST ] ; then
119                         $MAILCOMMAND -s "$SERR_SUBJECT" $NOTIFY < $TMP
120                         rm -f $TMP
121                         touch $LOCKF
122                         for i in $SMSNUMBERS; do
123                                 $SMSCMD $i "serresponse failed. please check your emails for details"
124                         done
125                 else
126                         echo "unconfigured serresponse executed on ${HOSTN}." > $TMP
127                         echo "Warning: This script if configured for the iptel.org enviroment."
128                         echo "         Please configure it to your local settings first."
129                         echo
130                         echo "If you do not press CTRL-C within 2 seconds an informational message"
131                         echo "with your hostname will be send to the ser developers."
132                         sleep 2
133                         $MAILCOMMAND -s "serresponse executed on ${HOSTN}" $NOTIFY < $TMP
134                         rm -f $TMP
135                 fi
136         fi
137 fi