Failover WAN entre dois links
Publicado por Phillipe Farias Costa (última atualização em 02/03/2017)
[ Hits: 2.256 ]
Homepage: br.linkedin.com/pub/phillipe-farias/53/b2a/13b/
Script desenvolvido para realizar o processo de FailOver WAN entre dois links.
Como requisito, é necessário a instalação do software sendEmail para envio dos logs por e-mail. Entretanto, o mesmo pode ser alterado a forma de envio.
#!/bin/bash #===============================================================================# # FailOver WAN # # # # Created by.: pH # # Contact.: phillipe@phconsultoria.com.br # # Version.: 1.0 # # # # Requirements.: Application sendEmail installed # # # #===============================================================================# #==============# #=== Settings ===# #==============# #=== General ===# log=/var/log/failover_wan.log # Set the file log check_delay="120" # Set the time for check gateways gw01name="gwoperator01" # Name for Gateway (Telecom Operator) gw02name="gwoperator02" # Name for Gateway (Telecom Operator) packagelost=20 #Set the packages lost for gateways #=== Network ===# gw01=xxx.xxx.xxx.xxx # Primary Gateway gw02=xxx.xxx.xxx.xxx # Secondary Gateway iface01=ethx # Network adapter for gw01 iface02=ethx # Network adapter for gw02 #=== Mail Settings ===# server="mail.domain.com" # Mail server FQDN port="587" # Port mail server (SMTP) user="no-reply@domain.com" # Account of domain password="password" # Passoword for account fo domain sender="no-reply@domain.com" # User Sender recipients="support@domain.com" # Account you received the email cc="it@domain.com" # Another Account you received the email (With copy) #=== Commands ===# ip=/sbin/ip # ip command (full path) ping=/bin/ping # ping command ( full path ) grep=/bin/grep # grep command ( full path ) awk=/usr/bin/awk #awk command ( full path ) cut=/bin/cut # cut command ( full path ) sleep=/usr/bin/sleep # sleep command ( full path ) tail=/bin/tail # tail command ( full path ) sendemail=/usr/local/bin/sendEmail # sendEmail comand ( full path ) #=== Monitor ===# link01_state=$($ping -c 10 -I $iface01 $ip_monitor | $awk '{ print }' | $grep "0% packet loss" | $awk '{ print $6 $7 $8 }' | $cut -d % -f 1) link02_state=$($ping -c 10 -I $iface02 $ip_monitor | $awk '{ print }' | $grep "0% packet loss" | $awk '{ print $6 $7 $8 }' | $cut -d % -f 1) ip_monitor=200.221.2.45 # Set the IP Monitor. By default, is usaged the IP Address of uol.com.br. #==================================# #=== Primary Configuration ===# #==================================# # The primary configuration, apply the traffic for gateway gw01. $ip route del default via $gw01 $ip route replace default via $gw01 #===============================# #=== Start FailOver Function ===# #===============================# failover () { while [ 1 ] do # Checking the communication with WAN Primary if [ $link01_state -le $packagelost ] then $ip route replace default via $gw01 else #==========================================# #== Change the traffic for gateway gw02 ===# #==========================================# $ip route replace default via $gw02 #=========================================# #=== Check if the secundary link is UP ===# #=========================================# if [ $link02_state -le $packagelost ] then echo "#================================================================================================#" >> $log echo "# FailOver Monitor #" >> $log echo "# #" >> $log echo "# The secundary Link ($gw02name) is UP on `date +%d/%m/%y-%H:%M:%S` #" >> $log echo "# #" >> $log echo "# Summary.: #" >> $log echo "# #" >> $log echo "# The Primary Link $gw01name it is DOWN with $link01_state % Packages Lost! #" >> $log echo "# #" >> $log echo "#================================================================================================#" >> $log echo >> $log echo >> $log #==========================# #=== Send Logs ===# #==========================# subject="FailOver Monitor - Primary Link is Down!" $tail -n 12 $log | $sendemail -s "$server:$port" -o tls=no -xu "$user" -xp "$password" -f "$sender" -u "$subject" -t "$recipients" -cc "$cc" $sleep $check_delay #==========================================# #=== Check if the primary link Recovery ===# #==========================================# $ip route replace $ip_monitor/32 via $gw01 if [ $link01_state -le $packagelost ] then $ip route replace default via $gw01 $ip route del $ip_monitor/32 via $gw01 echo "#================================================================================================#" >> $log echo "# FailOver Monitor #" >> $log echo "# #" >> $log echo "# The primary Link ( $gw01name) RECOVERY on `date +%d/%m/%y-%H:%M:%S` #" >> $log echo "# #" >> $log echo "#================================================================================================#" >> $log echo >> $log echo >> $log #==========================# #=== Send Logs ===# #==========================# subject="FailOver Monitor - Primary Link Recovery!" $tail -n 12 $log | $sendemail -s "$server:$port" -o tls=no -xu "$user" -xp "$password" -f "$sender" -u "$subject" -t "$recipients" -cc "$cc" else echo "#================================================================================================#" >> $log echo "# FailOver Monitor #" >> $log echo "# #" >> $log echo "# The primary Link ( $gw01name) remains DOWN on `date +%d/%m/%y-%H:%M:%S` #" >> $log echo "# #" >> $log echo "#================================================================================================#" >> $log echo >> $log echo >> $log #==========================# #=== Send Logs ===# #==========================# subject="FailOver Monitor - Primary Link Remains Down!" $tail -n 12 $log | $sendemail -s "$server:$port" -o tls=no -xu "$user" -xp "$password" -f "$sender" -u "$subject" -t "$recipients" -cc "$cc" fi fi fi $sleep $check_delay done } failover
Dell 1390 WLAN (Broadcom 4311)
Manutencao de arquivos no Squid-Cache
shradio.sh - ouça rádios online
Avisos de segurança do espaço em uso!
Barra de progresso em shell script com cores roxa e verde
Nenhum comentário foi encontrado.
Enviar mensagem ao usuário trabalhando com as opções do php.ini
Meu Fork do Plugin de Integração do CVS para o KDevelop
Compartilhando a tela do Computador no Celular via Deskreen
Como Configurar um Túnel SSH Reverso para Acessar Sua Máquina Local a Partir de uma Máquina Remota
Configuração para desligamento automatizado de Computadores em um Ambiente Comercial
Compartilhamento de Rede com samba em modo Público/Anônimo de forma simples, rápido e fácil
Cups: Mapear/listar todas as impressoras de outro Servidor CUPS de forma rápida e fácil
Criando uma VPC na AWS via CLI
Tem como instalar o gerenciador AMD Adrenalin no Ubuntu 24.04? (16)
Arch Linux - Guia para Iniciantes (2)
Problemas ao instalar o PHP (11)
Tenho dois Link's ( IP VÁLIDOS ), estou tentando fazer o failover... (0)