Différences entre les versions de « Lvs verification »
De BlaxWiki
Aller à la navigationAller à la recherche| Ligne 1 : | Ligne 1 : | ||
Ce script vérifie l'état de la synchro drdb, certaines lignes concernent de la supervision spécifique, elles peuvent etre ignorées. | Ce script vérifie l'état de la synchro drdb, certaines lignes concernent de la supervision spécifique, elles peuvent etre ignorées. | ||
Cela remonte un état des vip et des virtual routers comme ca : [[ | Cela remonte un état des vip et des virtual routers comme ca : [[Média:Check_lvs_rapport.png]] | ||
<pre> | <pre> | ||
Version du 21 août 2013 à 15:02
Ce script vérifie l'état de la synchro drdb, certaines lignes concernent de la supervision spécifique, elles peuvent etre ignorées. Cela remonte un état des vip et des virtual routers comme ca : Média:Check_lvs_rapport.png
#!/bin/bash
KCONF="/opt/applis/keepalived/etc/keepalived/keepalived.conf"
OUTIP="/tmp/output.ipb"
OUTIPV="/tmp/output.ipv"
VISION=/opt/agarik/Vision/bin/bb_send_raw
DISPLAY="supervision.so.agarik.eu:1984"
TARGET="`/bin/hostname -f`"
SERVICE=appli
LOG=/var/log/appli_sup.log
LOOKUPVIP=1
LOOKUPRIP=1
function lookup() {
ip=$1
host=`host $ip | awk '{print $5}'`
echo $host
}
ip a l > $OUTIP
/sbin/ipvsadm -ln | tee > $OUTIPV # le | tee permet d'eviter un bug sur CA
exec > $LOG
color="green"
echo "Virtuals routers"
for vrrp in `egrep -e "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" $KCONF | grep -v server | grep -v ^#`
do
host=""
isactive=0
shouldbeactive=0
isstate="SLAVE"
shouldbestate="SLAVE"
if [ `cat $OUTIP | grep -c "$vrrp/"` -eq 1 ]; then
isactive=1
isstate="MASTER"
fi
if [ `egrep -e "state|$vrrp$|$vrrp/" $KCONF | grep -B1 $vrrp | grep -c MASTER` -ne 0 ]; then
shouldbeactive=1
shouldbestate="MASTER"
fi
if [ $LOOKUPVIP -eq 1 ]; then
host=$(lookup $vrrp)
fi
echo "$isstate" > /tmp/tmp_$vrrp
if [ "$shouldbeactive" == "$isactive" ]; then
printf "%15s ($isstate &green) $host\n" $vrrp
else
echo "$vrrp ($isstate != $shouldbestate &red) $host"
color="red"
fi
done
echo "====================== VIPS =========================="
for service in `cat $KCONF | egrep "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) " | grep -v real_server | grep -v ^# | grep -v sorry_server | awk '{print $1"_"$2"_"$3}' `
do
vcolor="green"
rcolor="clear"
if [ `echo $service | grep -c "virtual_server"` -eq 1 ]; then
vip=`echo $service| cut -d '_' -f 3`
port=`echo $service| cut -d '_' -f 4`
groupname="";
else
vip=`echo $service| cut -d '_' -f 1`
port=`echo $service| cut -d '_' -f 2`
groupname=`cat $KCONF | egrep "virtual_server_group|$vip $port" | grep -B1 "$vip $port" | grep "group" | cut -d " " -f 2`
fi
# TODO : Ajouter un check sur l'etat de la VIP en plus de l'etat des REAL
thisone=0
echo > /tmp/tmp_$$
for real in `egrep -e "virtual_server|real_server" $KCONF | awk '{print $1"_"$2"_"$3}'`
do
host=""
if [ `echo $real | grep -c virtual_server` -eq 1 ]; then
thisone=0; # De base, je ne suis pas dans la bonne vip si je commence une nouvelle VIP
fi
if [ "virtual_server_"$vip"_$port" == "$real" -o "virtual_server_group_$groupname" == "$real" ]; then
thisone=1 # par contre, si je suis dans la bonne, j'active
continue;
fi
if [ $thisone -eq 0 ]; then
continue; # Et je passe tout de suite au suivant si ca n'est pas le cas
fi
rip=`echo $real | cut -d '_' -f 3`
rport=`echo $real | cut -d '_' -f 4`
active=`egrep -e "$vip:$port|$rip:$rport" $OUTIPV | grep -A1 $vip |grep $rip | awk '{print $5}'`
inactive=`egrep -e "$vip:$port|$rip:$rport" $OUTIPV | grep -A1 $vip |grep $rip | awk '{print $6}'`
if [ $LOOKUPRIP -eq 1 ]; then
host=$(lookup $rip)
fi
if [ `grep -c $rip:$rport $OUTIPV` -eq 0 ]; then
isactive=0;
isstate="DOWN &red ($active/$inactive) $host";
color="red";
vcolor="red";
if [ "$rcolor" == "green" -o "$rcolor" == "yellow" ]; then rcolor="yellow";else rcolor="red";fi
else
isactive=1;
isstate="UP &green ($active/$inactive) $host";
if [ "$rcolor" == "red" -o "$rcolor" == "yellow" ]; then rcolor="yellow";else rcolor="green";fi
fi
printf " Real : %15s:$rport : $isstate\n" $rip >> /tmp/tmp_$$
done
host=""
if [ $LOOKUPVIP -eq 1 ]; then
host=$(lookup $vip)
fi
echo -n " VIP : $vip:$port (`cat /tmp/tmp_$vip` &$rcolor) $host"
cat /tmp/tmp_$$
echo "------------------------------------------------------"
done
rm -f $OUTIP
rm -f $OUTIPV
rm -f /tmp/tmp_*
DATA="status+12 $TARGET.$SERVICE $color `/bin/date` $SERVICE
`cat $LOG`"
$VISION $DISPLAY "$DATA"