Last active
November 23, 2015 20:38
-
-
Save josemalcher/d8916bbcbbd98b0f5076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
############CONFIGURACAO | |
local=/monitor | |
log=$local/logs/”LOG-`date +%d%m%y`.txt” | |
numero=5498979897 | |
EMAIL_DE=”@gmail.com” | |
EMAIL_PARA=”@outlook.com” | |
EMAIL_PARA2=”” | |
SERVIDOR_SMTP=”smtp.gmail.com:587″ | |
SENHA=’senha’ | |
######################### | |
echo “—————————————” >> $log | |
for i in $( cat $local/servidores.txt) | |
do | |
ping -c 1 -W 3 “$i” > /dev/null # -c para 1 ping e -W para 1 segundo de espera por ping | |
if [ “$?” -ne 1 ];then | |
# RECONECTADO | |
if [ -e $local/$i-OFF.txt ]; then | |
printf “%13s – %12s – %6s\n” $i RECONECTADO `date +%H:%M:%S` >> $log | |
if [ $(cat $local/$i-OFF.txt) -ge 3 ]; then | |
# ENVIA EMAIL | |
ASSUNTO=”SERVIDOR RECONECTADO – $i” | |
MENSAGEM=”Servidor $i reconectado – `date +%H:%M:%S`” | |
ANEXO=”” | |
sendEmail -f $EMAIL_DE -t $EMAIL_PARA -bcc $EMAIL_PARA2 -u “$ASSUNTO” -m “$MENSAGEM” -a $ANEXO -s $SERVIDOR_SMTP -xu $EMAIL_DE -xp $SENHA > | |
$local/log_email.txt | |
# ENVIA SMS | |
echo “$MENSAGEM” | gammu –sendsms TEXT $numero > $local/log_sms.txt | |
fi | |
rm $local/$i-OFF.txt | |
else | |
# CONECTADO | |
printf “%13s – %12s – %6s\n” $i CONECTADO `date +%H:%M:%S` >> $log | |
fielse | |
# DESCONETADO | |
printf “%13s – %6s – %6s\n” $i DESCONECTADO `date +%H:%M:%S` >> $log | |
if [ -e $local/$i-OFF.txt ]; then | |
cont=$(cat $local/$i-OFF.txt) && soma=$(($cont + 1)) && echo “$soma” > $local/$i-OFF.txt | |
else | |
echo “1” > $local/$i-OFF.txt | |
fi | |
if [ $(cat $local/$i-OFF.txt) -eq 3 ]; then | |
# PERDEU 3 PINGS ENVIA EMAIL | |
ASSUNTO=”PERDA DE REDE – $i” | |
MENSAGEM=”Servidor $i sem resposta – Primeiro Alerta – `date +%H:%M:%S`” | |
ANEXO=”” | |
sendEmail -f $EMAIL_DE -t $EMAIL_PARA -bcc $EMAIL_PARA2 -u “$ASSUNTO” -m “$MENSAGEM” -a $ANEXO -s $SERVIDOR_SMTP -xu $EMAIL_DE -xp $SENHA > | |
$local/log_email.txt | |
# ENVIA SMS | |
echo “$MENSAGEM” | gammu –sendsms TEXT $numero > $local/log_sms.txt | |
#rm $local/$i-OFF.txt | |
elif [ $(cat $local/$i-OFF.txt) -eq 34 ]; then | |
# PERDEU + de 4 PINGS ENVIA EMAIL | |
ASSUNTO=”PERDA DE REDE – $i” | |
MENSAGEM=”Servidor $i sem resposta – Alerta Continuo – `date +%H:%M:%S`” | |
ANEXO=”” | |
sendEmail -f $EMAIL_DE -t $EMAIL_PARA -bcc $EMAIL_PARA2 -u “$ASSUNTO” -m “$MENSAGEM” -a $ANEXO -s $SERVIDOR_SMTP -xu $EMAIL_DE -xp $SENHA > | |
$local/log_email.txt | |
# ENVIA SMS | |
echo “$MENSAGEM” | gammu –sendsms TEXT $numero > $local/log_sms.txt | |
echo “4” > $local/$i-OFF.txt | |
fi | |
fi | |
done | |
echo “—————————————” >> $log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment