Différences entre les versions de « Lvs verification »
De BlaxWiki
Aller à la navigationAller à la recherche| Ligne 2 : | Ligne 2 : | ||
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. | ||
Il gère : | |||
<pre> | |||
Si une VIP n'est pas une IP de VRRP, cela ne genere plus d'erreurs | |||
Affiche le nombre de connexions globales | |||
Affiche le type de repartition (rr, sh...) | |||
Supporte les VRRPs declarees sous le format IP/MASQUE ou IP | |||
</pre> | |||
Cela remonte un état des vip et des virtual routers comme ca : | Cela remonte un état des vip et des virtual routers comme ca : | ||
| Ligne 16 : | Ligne 24 : | ||
OUTIPV="/tmp/output.ipv" | OUTIPV="/tmp/output.ipv" | ||
VISION=/opt/agarik/Vision/bin/bb_send_raw | VISION=/opt/agarik/Vision/bin/bb_send_raw | ||
DISPLAY="supervision.agarik.com" | DISPLAY="supervision.agarik.com:1984" | ||
TARGET=" | TARGET="`/bin/hostname -f`" | ||
SERVICE=appli | SERVICE=appli | ||
LOG=/var/log/appli_sup.log | LOG=/var/log/appli_sup.log | ||
| Ligne 34 : | Ligne 42 : | ||
exec > $LOG | exec > $LOG | ||
total_sessions=0 | |||
total_inactive_sessions=0 | |||
color="green" | color="green" | ||
echo "Virtuals routers" | 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] | 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]?)$|\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 | do | ||
vrrp_clean=`echo $vrrp | cut -d '/' -f 1` | |||
host="" | host="" | ||
isactive=0 | isactive=0 | ||
| Ligne 44 : | Ligne 56 : | ||
isstate="SLAVE" | isstate="SLAVE" | ||
shouldbestate="SLAVE" | shouldbestate="SLAVE" | ||
if [ `cat $OUTIP | grep -c "$ | if [ `cat $OUTIP | grep -c "$vrrp_clean/"` -eq 1 ]; then | ||
isactive=1 | isactive=1 | ||
isstate="MASTER" | isstate="MASTER" | ||
fi | fi | ||
if [ `egrep -e "state|$ | if [ `egrep -e "state|$vrrp_clean$|$vrrp_clean/" $KCONF | grep -B1 $vrrp_clean | grep -c MASTER` -ne 0 ]; then | ||
shouldbeactive=1 | shouldbeactive=1 | ||
shouldbestate="MASTER" | shouldbestate="MASTER" | ||
| Ligne 54 : | Ligne 66 : | ||
fi | fi | ||
if [ $LOOKUPVIP -eq 1 ]; then | if [ $LOOKUPVIP -eq 1 ]; then | ||
host=$(lookup $ | host=$(lookup $vrrp_clean) | ||
fi | fi | ||
echo "$isstate" > /tmp/tmp_$vrrp_clean | |||
echo "$isstate" > /tmp/tmp_$ | |||
if [ "$shouldbeactive" == "$isactive" ]; then | if [ "$shouldbeactive" == "$isactive" ]; then | ||
printf "%15s ($isstate &green) $host\n" $ | printf "%15s ($isstate &green) $host\n" $vrrp_clean | ||
else | else | ||
echo "$ | echo "$vrrp_clean ($isstate != $shouldbestate &red) $host" | ||
color="red" | color="red" | ||
fi | fi | ||
done | done | ||
echo "====================== VIPS ==========================" | 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 | 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 | do | ||
vcolor="green" | vcolor="green" | ||
| Ligne 83 : | Ligne 95 : | ||
thisone=0 | thisone=0 | ||
echo > /tmp/tmp_$$ | echo > /tmp/tmp_$$ | ||
for real in `egrep -e "virtual_server|real_server" $KCONF | for real in `egrep -e "virtual_server|real_server" $KCONF | awk '{print $1"_"$2"_"$3}'` | ||
do | do | ||
host="" | host="" | ||
| Ligne 99 : | Ligne 111 : | ||
rport=`echo $real | cut -d '_' -f 4` | rport=`echo $real | cut -d '_' -f 4` | ||
active=`egrep -e "$vip:$port|$rip:$rport" $OUTIPV | grep -A1 $vip |grep $rip | awk '{print $5}'` | active=`egrep -e "$vip:$port|$rip:$rport" $OUTIPV | grep -A1 $vip |grep $rip | awk '{print $5}'` | ||
total_sessions=$(($active+$total_sessions)); | |||
inactive=`egrep -e "$vip:$port|$rip:$rport" $OUTIPV | grep -A1 $vip |grep $rip | awk '{print $6}'` | inactive=`egrep -e "$vip:$port|$rip:$rport" $OUTIPV | grep -A1 $vip |grep $rip | awk '{print $6}'` | ||
total_inactive_sessions=$(($inactive+$total_inactive_sessions)) | |||
if [ $LOOKUPRIP -eq 1 ]; then | if [ $LOOKUPRIP -eq 1 ]; then | ||
host=$(lookup $rip) | host=$(lookup $rip) | ||
| Ligne 121 : | Ligne 135 : | ||
host=$(lookup $vip) | host=$(lookup $vip) | ||
fi | fi | ||
echo -n " VIP : $vip:$port (`cat /tmp/tmp_$vip` &$rcolor) $host" | rmode=`grep "$vip:$port" $OUTIPV | awk '{print $3}'` | ||
if [ -f /tmp/tmp_$vip ]; then | |||
echo -n " VIP : $vip:$port (`cat /tmp/tmp_$vip` &$rcolor) $rmode $host" | |||
cat /tmp/tmp_$$ | |||
else | |||
echo -n " VIP : $vip:$port &$rcolor $host" | |||
fi | |||
echo "------------------------------------------------------" | echo "------------------------------------------------------" | ||
done | done | ||
echo "Sessions Globales : $total_sessions/$total_inactive_sessions" | |||
rm -f $OUTIP | rm -f $OUTIP | ||
| Ligne 134 : | Ligne 155 : | ||
$VISION $DISPLAY "$DATA" | $VISION $DISPLAY "$DATA" | ||
</pre> | </pre> | ||
[[Catégorie:Script]] | [[Catégorie:Script]] | ||
Version actuelle datée du 7 août 2014 à 15:45
Ce script vérifie l'état de la synchro drdb, certaines lignes concernent de la supervision spécifique, elles peuvent etre ignorées.
Il gère :
Si une VIP n'est pas une IP de VRRP, cela ne genere plus d'erreurs Affiche le nombre de connexions globales Affiche le type de repartition (rr, sh...) Supporte les VRRPs declarees sous le format IP/MASQUE ou IP
Cela remonte un état des vip et des virtual routers comme ca :
Script pour lvs + keepalive avec vrrp[modifier]
S'assurer que le /etc/hosts du serveur est bon, et que "hostname -f" retourne bien le fqdn du serveur et non pas localhost.
#!/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.agarik.com:1984"
TARGET="`/bin/hostname -f`"
SERVICE=appli
LOG=/var/log/appli_sup.log
LOOKUPVIP=0
LOOKUPRIP=0
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
total_sessions=0
total_inactive_sessions=0
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]?)$|\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
vrrp_clean=`echo $vrrp | cut -d '/' -f 1`
host=""
isactive=0
shouldbeactive=0
isstate="SLAVE"
shouldbestate="SLAVE"
if [ `cat $OUTIP | grep -c "$vrrp_clean/"` -eq 1 ]; then
isactive=1
isstate="MASTER"
fi
if [ `egrep -e "state|$vrrp_clean$|$vrrp_clean/" $KCONF | grep -B1 $vrrp_clean | grep -c MASTER` -ne 0 ]; then
shouldbeactive=1
shouldbestate="MASTER"
fi
if [ $LOOKUPVIP -eq 1 ]; then
host=$(lookup $vrrp_clean)
fi
echo "$isstate" > /tmp/tmp_$vrrp_clean
if [ "$shouldbeactive" == "$isactive" ]; then
printf "%15s ($isstate &green) $host\n" $vrrp_clean
else
echo "$vrrp_clean ($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}'`
total_sessions=$(($active+$total_sessions));
inactive=`egrep -e "$vip:$port|$rip:$rport" $OUTIPV | grep -A1 $vip |grep $rip | awk '{print $6}'`
total_inactive_sessions=$(($inactive+$total_inactive_sessions))
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
rmode=`grep "$vip:$port" $OUTIPV | awk '{print $3}'`
if [ -f /tmp/tmp_$vip ]; then
echo -n " VIP : $vip:$port (`cat /tmp/tmp_$vip` &$rcolor) $rmode $host"
cat /tmp/tmp_$$
else
echo -n " VIP : $vip:$port &$rcolor $host"
fi
echo "------------------------------------------------------"
done
echo "Sessions Globales : $total_sessions/$total_inactive_sessions"
rm -f $OUTIP
rm -f $OUTIPV
rm -f /tmp/tmp_*
DATA="status+12 $TARGET.$SERVICE $color `/bin/date` $SERVICE
`cat $LOG`"
$VISION $DISPLAY "$DATA"
