serresponse 4.4 KB

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