Ultima modificación a linkcheck
#!/bin/sh
#Ignacio Rodriguez Haberlin (ultima modificacion 2012)
[ -e /tmp/qosarranco ] && { echo "OK"; } || { logger "ISP CHECK no cargo el qos... abortando"; echo "No cargo QOS esperando"; exit; }
if [ -e /tmp/qosbusy ] ; then
logger "Qos en carga no chequeando"
echo "Qos en carga no chequeando"
else
internet="OK"
test="0"
conta="0"
defaultgw=`ip route show | grep default | cut -f 3 -d ’ ’`
if [ "$defaultgw" = "ppp0" ] ; then
echo "variable defaultgw inadecuada"
logger "variable defaultgw inadecuada"
logger "capturando gateway adecuado"
defaultgw=`route | grep ppp0 | head -n 1 | cut -f 1 -d " "`
logger "el default gateway es $defaultgw"
fi
mail_estado="/partition/mail_estado"
echo "default gateway: $defaultgw"
. /etc/coyote/coyote.conf
. /argentoqos/link/isp_check.conf
. /argentoqos/variables.conf
if [ "$activo" = "yes" ] ; then
if [ -e /partition/link ]; then
echo "chequeando directorio de httpd"
else
mkdir /partition/link
fi
webmin=`ps | grep /usr/sbin/thttpd`
if [ -n $webmin ] ; then
/etc/rc.d/pkgs/rc.webadmin start
fi
thttpd=`ps | grep thttpd | grep nobody`
if [ -n $thttpd ] ; then
thttpd -p $httpport -d /partition/link
fi
if [ "$qoscheck" = "yes" ] ; then
/argentoqos/link/qoscheck
fi
if [ "$tcshow" = "yes" ] ; then
/argentoqos/tclan
fi
if [ "$failover" = "yes" ] ; then
cd /tmp
wget $argentobrip:$httpport/emergency
. /tmp/emergency
if [ "$emergency" = "yes" ] ; then
. /tmp/qos
if [ "$type" = "emergency" ] ; then
echo "QOS de emergencia ya esta activado"
else
echo "Activando QOS de emergencia"
logger "ISP CHECK activando qos de emergencia"
cp /partion/qos /partion/qosanterior
/argentoqos/qosbr reload emergency
fi
else
. /tmp/qos
if [ "$type" = "emergency" ] ; then
echo "Desactivando QOS de emergencia"
logger "ISP CHECK desactivando qos de emergencia"
cp /partion/qosanterior /partion/qos
/argentoqos/qosbr reload lastprofile
else
echo "QOS de emergencia innesesario"
fi
fi
fi
if [ "$bridgemode" = "no" ] ; then
echo "bridgemode NO"
ping -c 1 $defaultgw
if [ "$?" = "0" ] ; then
internet="OK"
echo "ping gateway ok"
ping -c 10 $defaultgw > /tmp/ping
if [ -e /tmp/ping ]; then
congestion=`cat /tmp/ping | grep avg | cut -b5- | cut -f 2 -d "=" | cut -f 2 -d " " | cut -f 1 -d "/" | cut -f 1 -d "."`
fi
echo $congestion
if [ "$congestion" -gt "$max_congestion" ] ; then
if [ "$mail_alert_congestion" = "yes" ] ; then
if [ -e /etc/.msmtprc ]; then
echo "Mandando Mail"
logger "ISP CHECK Mandando Mail de congestion"
echo "From: $from <$mail_source>" > /tmp/mail2
echo "Subject: Latencia ALTA" >> /tmp/mail2
echo "To: $to <$mail_dest>" >> /tmp/mail2
echo "Informe de congestion: $congestion milisegundos" >> /tmp/mail2
cat /tmp/mail2 | msmtp -t -C /etc/.msmtprc
echo "listo"
logger "ISP CHECK Mail congestion enviado"
else
echo "no tiene instalado msmtp"
fi
fi
else
echo "congestion normal"
logger "congestion normal"
fi ########################
else
logger "ISP CHECK internet DOWN default gateway no responde "
internet="down"
fi
if [ "$internet" = "OK" ] ; then
##Compruebo internet
if [ "$dnstest" = "yes" ] ; then
/argentoqos/link/dns.test
. /tmp/dnslog
if [ "$dns" = "OK" ] ; then
logger "ISP CHECK internet esta OK"
internet="OK"
else
logger "ISP CHECK internet esta DOWN"
internet="down"
fi
else
ping -c 1 $defaultgw > /dev/null
if [ "$?" = "0" ] ; then
echo "internet esta OK"
internet="OK"
else
echo "no funka, internet DOWN"
internet="down"
logger "ISP CHECK gateway inalcansable, internet DOWN"
fi
fi
fi
#. /tmp/link
if [ "$internet" = "OK" ] ; then
echo "Todo ok"
echo "internet="OK"" > /tmp/internet
if [ -e $mail_estado ]; then
echo "`date` ISP CHECK volvio internet" >> $mail_estado
if [ "$mail_alert_status" = "yes" ] ; then
if [ -e /etc/.msmtprc ]; then
echo "Mandando Mail"
logger "ISP CHECK Mandando Mail"
echo "From: $from <$mail_source>" > /tmp/mail
echo "Subject: Status de Internet Restablecido" >> /tmp/mail
echo "To: $to <$mail_dest>" >> /tmp/mail
cuerpo=`cat $mail_estado`
echo "Informe de linkcheck: $cuerpo " >> /tmp/mail
cat /tmp/mail | msmtp -t -C /etc/.msmtprc
rm $mail_estado
echo "listo"
logger "ISP CHECK Mail enviado"
else
echo "no tiene instalado msmtp"
fi
fi
fi
###########
if [ "$tipo_isp" = "default" ] ; then
echo "default="OK"" > /partition/link/default
else
echo "alternative="OK"" > /partition/link/alternative
fi
else
logger "ISP CHECK Intentando recuperar internet"
echo "`date` Internet DOWN" >> $log
echo "internet="BAD"" > /tmp/internet
if [ "$tipo_isp" = "default" ] ; then
echo "default="BAD"" > /partition/link/default
else
echo "alternative="BAD"" > /partition/link/alternative
fi
echo " "
case "$INETTYPE" in
PPPOE)
contador="1"
until [ $contador = 5 ]; do
sleep 20
if [ "$dnstest" = "yes" ] ; then
/argentoqos/link/dns.test
. /tmp/dnslog
if [ "$dns" = "OK" ] ; then
logger "ISP CHECK luego de aguardar 30 segundos, internet esta OK"
internet="OK"
contador="5"
else
logger "ISP CHECK no funka, internet DOWN"
internet="down"
contador=$(($contador+1))
fi
else
ping -c 1 $defaultgw > /dev/null
if [ "$?" = "0" ] ; then
logger "ISP CHECK internet esta OK"
internet="OK"
contador="5"
else
logger "ISP CHECK no funka, internet DOWN"
internet="down"
contador=$(($contador+1))
fi
fi
done
;;
ETHERNET_DHCP)
contador="1"
until [ $contador = 5 ]; do
/usr/sbin/dhcp.release
sleep 20
/usr/sbin/dhcp.renew
sleep 15
if [ "$dnstest" = "yes" ] ; then
/argentoqos/link/dns.test
. /tmp/dnslog
if [ "$dns" = "OK" ] ; then
echo "internet esta OK"
echo "`date` Internet OK se recupero la conección" >> $log
logger "ISP CHECK internet OK, se recupero la conección"
internet="OK"
contador="5"
else
echo "no funka, internet DOWN"
internet="down"
contador=$(($contador+1))
fi
else
ping -c 1 $defaultgw > /dev/null
if [ "$?" = "0" ] ; then
echo "internet esta OK"
internet="OK"
contador="5"
else
echo "no funka, internet DOWN"
logger "ISP CHECK no funka, internet DOWN, default gateway no responde!"
internet="down"
contador=$(($contador+1))
fi
fi
done
;;
*)
echo "Solo para PPPOE y DHCP";
;;
esac
fi
if [ "$internet" = "OK" ] ; then
echo "Todo Ok"
else
echo "reiniciando sistema"
echo "`date` ISP CHECK sin internet" >> $mail_estado
if [ "$INETTYPE" = "PPPOE" ] ; then
sleep 20
if [ "$resetmodem" = "yes" ] ; then
backup argentoqos
logger "ISP CHECK reseteando modem"
echo "ISP CHECK reseteando modem" >> $log
/argentoqos/link/resetmodem
sleep 40
logger "ISP CHECK reiniciando sistema"
echo "ISP CHECK reiniciando sistema" >> $log
reboot
else
backup argentoqos
echo "ISP CHECK reiniciando sistema" >> $log
reboot
fi
else
if [ "$resetmodem" = "yes" ] ; then
backup argentoqos
logger "ISP CHECK reseteando modem"
echo "ISP CHECK reseteando modem" >> $log
/argentoqos/link/resetmodem
sleep 40
logger "ISP CHECK reiniciando sistema"
echo "ISP CHECK reiniciando sistema" >> $log
reboot
else
backup argentoqos
echo "ISP CHECK reiniciando sistema" >> $log
reboot
fi
fi
fi
else
echo "bridgemode YES"
ping -c 1 $defaultgw > /tmp/ping
fi
else
echo "debe activar el linckchek"
fi
fi
0 comentarios