Find Offline and Unknown VIPs. The reason they are down, their pools/members and irules

Problem this snippet solves:

I needed a way to search a LTM and identify offline and unknown VIPs.

If the VIPs have a pool I needed to identify what was wrong with it. If the VIP had an iRule with multiple pool statements in it, I needed to also get the stats for those pools as well.

How to use this snippet:

Simply load on LTM in any directory and run it (with nice)

The output file is placed in the /tmp directory and is called vipdetails-csv.txt

The file is delimited by "|" pipes. You can open it with excel using import wizard.

Code :

#!/bin/bash

##########################################################################
# Find Offline and Unknown VIPs
# Gather why VIPs are down
# IF VIP is down due to pool, gather pool and pool member info
# if VIP is unknown due to iRule Get pools in iRule and gather member info
###########################################################################

##########
#FUNCTIONS
##########
getVIPArray() {
getlines="$(wc -l $1)"
linecount=$(echo $getlines | awk '{print $1}')
z=1
viparr=() # Create array

while IFS= read -r line # Read a line
do
echo -ne "$((100*$z/$linecount))% Complete\r"
viparr+=("$line") # Append line to the array
let z=$z+1
done < "$1"
viparr+=(" ")
}

getRuleArray() {
getlines="$(wc -l $1)"
linecount=$(echo $getlines | awk '{print $1}')
z=1
rulearr=() # Create array
while IFS= read -r line # Read a line
do
echo -ne "$((100*$z/$linecount))% Complete\r"
rulearr+=("$line") # Append line to the array
let z=$z+1
done < "$1"
rulearr+=(" ")
}
contains() {
  local string=$1 substring=$2
  [[ $string = *"$substring"* ]]
}
###############
#END FUNCTIONS
###############

############
#MAIN SCRIPT
############

# SETTING SOME VARIABLES FOR INPUT / OUTPUT FILES

vipfile="/tmp/vipdetails.txt"
poolfile="/tmp/pooldetails.txt"
rulefile="/tmp/ruledetails.txt"
outfile="/tmp/vipdetails-csv.txt"

#initialize outfile
echo "VIP NAME|VIP IP|VIP PORT|IRULE NAME / RULE POOL COUNT|POOL NAME|POOL MEMBERS|VIP STATE|ENABLED/DISABLED|REASON" > $outfile

#find F5 version 

# NOTE - ENABLE BEFORE DOING LIVE

version=$(tmsh show sys version | grep -v Sys::Version | grep Version | awk 'BEGIN{FS="Version"}{print $2}' | awk 'BEGIN{FS="."}{print $1}')

#get show details on VIPs and Pool, and get iRule configurations

# **************************************
# **************************************
# UNCOMMENT TMSH COMMANDS BELOW FOR THIS TO WORK LIVE
# **************************************
# **************************************


echo "*********************"
echo "***GATHERING VIP INFO"
echo "*****PLEASE WAIT*****"
echo "*********************"
echo ""

# NOTE - WRITE IF STATEMENT TO SWITCH COMMAND BASED ON VERSION
if [[ $version == *"10"* ]];then 
#v10
 $(nice tmsh -q show ltm virtual all detail field-fmt  | egrep -A1 "server.status|ltm virtual|rules {|pools {" | egrep -v "pools|rules|clientside|}|--" > /tmp/vipdetails.txt)
else
#v11
$(nice tmsh -q show ltm virtual all detail field-fmt  | egrep -A1 "status.availability-state|enabled-state|ltm virtual|rules {|pools {" | egrep -v "pools {|rules {|actual-pva|            status|--" > /tmp/vipdetails.txt)
fi

#need to put empty line at bottom of file for later use
 echo " " >> /tmp/vipdetails.txt
getVIPArray $vipfile 

echo "***********************"
echo "***GATHERING iRULE INFO"
echo "******PLEASE WAIT******"
echo "***********************"
echo ""

 tmsh -q list ltm rule > /tmp/ruledetails.txt
#need to put empty line at bottom of file for later use
 echo "END OF RULE FILE" >> /tmp/ruledetails.txt
getRuleArray $rulefile


echo "********************"
echo "**SORTING VIP FILE**"
echo "****PLEASE WAIT*****"
echo "********************"
echo ""

newvip=()
count=${#viparr[@]}

i=0
z=1
while [ $i -le $count ];
do
echo -ne "$((100*$z/$count))% Complete\r"
if [[ ${viparr[$i]} == *"ltm virtual"* ]];then
newvip+=("${viparr[$i]}")
t=$i+1
until [[ ${viparr[$t]} == *"ltm virtual"* ]] || [[ ${viparr[$t]} == " " ]];
do
newvip+=("${viparr[$t]}")
let t=$t+1
done

newvip+=(" ")
fi
let i=$i+1
let z=$z+1
done

echo "**********************"
echo "**SORTING iRULE FILE**"
echo "*****PLEASE WAIT******"
echo "**********************"
echo ""

newrule=()
count=${#rulearr[@]}
i=0
z=1
while [ $i -le $count ];
do
echo -ne "$((100*$z/$count))% Complete\r"
if [[ ${rulearr[$i]} == *"ltm rule"* ]];then
newrule+=("${rulearr[$i]}")
t=$i+1
until [[ ${rulearr[$t]} == *"ltm rule"* ]] || [[ ${rulearr[$t]} == " " ]];
do
newrule+=("${rulearr[$t]}")
let t=$t+1
done

newrule+=(" ")
fi
let i=$i+1
let z=$z+1
done


rulecount=${#newrule[@]}

echo "********************************"
echo "FINDING OFFLINE AND UNKNOWN VIPS"
echo "***********PLEASE WAIT**********"
echo "********************************"
echo ""

count=${#newvip[@]}

i=0
z=1
offline=()
unknown=()
while [ $i -le $count ];
do
echo -ne "$((100*$z/$count))% Complete\r"
#find offline VIPs and put them into offline array
if [[ ${newvip[$i]} == *"ltm virtual"* ]];then
if [[ ${newvip[$i+1]} == *"availability-state offline"* ]] || [[ ${newvip[$i+2]} == *"availability-state offline"* ]] || [[ ${newvip[$i+3]} == *"availability-state offline"* ]];then
t=$i
until [[ ${newvip[$t]} == " " ]];
do
offline+=("${newvip[$t]}")
let t=$t+1
done
offline+=(" ")
fi
fi 
#find unknown VIPs and put them into unknown array
if [[ ${newvip[$i]} == *"ltm virtual"* ]];then
if [[ ${newvip[$i+1]} == *"availability-state unknown"* ]] || [[ ${newvip[$i+2]} == *"availability-state unknown"* ]] || [[ ${newvip[$i+3]} == *"availability-state unknown"* ]];then
t=$i
until [[ ${newvip[$t]} == " " ]];
do
unknown+=("${newvip[$t]}")
let t=$t+1
done
unknown+=(" ")
fi
fi 
let i=$i+1
let z=$z+1
done


echo "**********************"
echo "SEARCHING OFFLINE VIPS"
echo "*****PLEASE WAIT******"
echo "**********************"
echo ""

count=${#offline[@]}
i=0
z=1
while [ $i -le $count ];
do
echo -ne "$((100*$z/$count))% Complete\r"
if [[ ${offline[$i]} == *"ltm virtual"* ]];then

#find vip name
vip=$(echo ${offline[$i]} | awk 'BEGIN{FS="{"}{print $1}' | awk 'BEGIN{FS="ltm virtual"}{print $2}')
#find reason
t=$i
until [[ ${offline[$t]} == *"-reason"* ]];
do
let t=$t+1
done
reason=$(echo ${offline[$t]} | awk 'BEGIN{FS="-reason"}{print $2}')
#write out vip down and reason
state=$(echo ${offline[$t-1]} | awk 'BEGIN{FS="-state"}{print $2}')
#get VIP ip address and port 
vipcommand=$(tmsh list ltm virtual $vip | grep destination | awk 'BEGIN{}{print $2}')
vipip=$(echo $vipcommand | awk 'BEGIN{FS=":"}{print $1}')
vipport=$(echo $vipcommand | awk 'BEGIN{FS=":"}{print $2}')
#search etc/services for port name - port number
let vipport=$(getent services $vipport | awk 'BEGIN{FS="/"}{print $1}' | awk '{print $NF}')

echo "$vip|$vipip|$vipport||||OFFLINE|$state|$reason" >> $outfile

#find if vip has rule and pool
t=$i
hasrule=0
haspool=0
until [[ ${offline[$t]} == " " ]];
do
if [[ ${offline[$t]} == *"ltm virtual"* ]];then
if [[ ${offline[$t+1]} != *":"* ]] && [[ ${offline[$t+1]} != *"-state"* ]];then
haspool=1
fi
elif [[ ${offline[$t]} == *":"* ]];then
hasrule=1
else
:

fi

let t=$t+1
done

#if VIP has both pool and rule
if [[ $haspool == 1 ]] && [[ $hasrule == 1 ]];then
### POOL SECTION ###
pool=$(echo ${offline[$i+1]} | awk 'BEGIN{FS="{"}{print $1}')
#strip spaces
pool=$(echo $pool | sed -e 's/^[ \t]*//')
#search issue tmsh command for pool and find pool stats
commandout=()
while IFS= read -r line # Read a line
do
commandout+=("$line") # Append line to the array
done < <(tmsh show ltm pool $pool detail | grep -A5 "Ltm::Pool")
commandout+=(" ")
commandcount=0
hasmembers="0"
until [[ ${commandout[$commandcount]} == " " ]];
do
if [[ ${commandout[$commandcount]} == *"Ltm::Pool:"* ]];then
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
echo "||||$pool||$state|$reason" >> $outfile
fi
if [[ ${commandout[$commandcount]} == *"Ltm::Pool Member:"* ]];then
hasmembers="1"
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
ipport=$(echo ${commandout[$commandcount]} | awk 'BEGIN{FS=" "}{print $NF}')
echo "|||||$ipport||$state|$reason" >> $outfile
fi
let commandcount=$commandcount+1
done
if [[ $hasmembers == "0" ]];then
echo "|||||NO POOL MEMBERS" >> $outfile
fi
### END POOL SECTION ###
### RULE SECTION ###
if [[ ${offline[$i+1]} == *":"* ]] || [[ ${offline[$i+2]} == *":"* ]];then
if [[ ${offline[$i+1]} == *":"* ]];then
rule=$(echo ${offline[$i+1]} | awk 'BEGIN{FS=":"}{print $1}')
fi
if [[ ${offline[$i+2]} == *":"* ]];then
rule=$(echo ${offline[$i+2]} | awk 'BEGIN{FS=":"}{print $1}')
fi
#strip spaces
rule=$(echo $rule | sed -e 's/^[ \t]*//')
echo "|||$rule|" >> $outfile
#search newrule array for iRule config
a=0
while [ $a -le $rulecount ];
do
if contains "${newrule[$a]}" "$rule";then
t=$a+1
#find all unique pool names in rule
rulepool=()
until [[ ${newrule[$t]} == *"ltm rule"* ]] || [[ ${newrule[$t]} == *"END OF RULE FILE"* ]];
do
if [[ ${newrule[$t]} == *"pool "* ]];then
#ignore commented lines
if [[ ${newrule[$t]} == *"# "* ]];then
:
else
#extract pool name from line
pool=$(echo ${newrule[$t]} | awk 'BEGIN{FS="pool "}{print $2}' | awk '{print $1}' )
if [[ $pool == *"}"* ]];then
pool=$(echo $pool | awk 'BEGIN{FS="}"}{print $1}')
fi
#strip spaces
rulepool+=($(echo $pool | sed -e 's/^[ \t]*//'))
fi
fi
let t=$t+1
done

#find unique pool names

uniqpools=($(for p in  "${rulepool[@]}" ; do  echo "$p" ; done | sort -u))
rulepoolcount=${#uniqpools[@]}
echo "|||RULE HAS $rulepoolcount UNIQUE POOLS" >> $outfile
for helper in "${uniqpools[@]}";
do
#search issue tmsh command for pool and find pool stats
commandout=()
while IFS= read -r line # Read a line
do
commandout+=("$line") # Append line to the array
done < <(nice tmsh -q show ltm pool $helper detail | grep -A5 "Ltm::Pool")
commandout+=(" ")
commandcount=0
hasmembers="0"
until [[ ${commandout[$commandcount]} == " " ]];
do
if [[ ${commandout[$commandcount]} == *"Ltm::Pool:"* ]];then
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
echo "||||$helper||$state|$reason" >> $outfile
fi
if [[ ${commandout[$commandcount]} == *"Ltm::Pool Member:"* ]];then
hasmembers="1"
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
ipport=$(echo ${commandout[$commandcount]} | awk 'BEGIN{FS=" "}{print $NF}')
echo "|||||$ipport||$state|$reason" >> $outfile
fi
let commandcount=$commandcount+1
done
if [[ $hasmembers == "0" ]];then
echo "|||||NO POOL MEMBERS" >> $outfile
fi
done
fi
let a=$a+1
done
fi
### END RULE SECTION ###

elif [[ $haspool == 0 ]] && [[ $hasrule == 1 ]];then
### RULE SECTION ###
if [[ ${offline[$i+1]} == *":"* ]] || [[ ${offline[$i+2]} == *":"* ]];then
if [[ ${offline[$i+1]} == *":"* ]];then
rule=$(echo ${offline[$i+1]} | awk 'BEGIN{FS=":"}{print $1}')
fi
if [[ ${offline[$i+2]} == *":"* ]];then
rule=$(echo ${offline[$i+2]} | awk 'BEGIN{FS=":"}{print $1}')
fi
#strip spaces
rule=$(echo $rule | sed -e 's/^[ \t]*//')
echo "|||$rule" >> $outfile
#search newrule array for iRule config
a=0
while [ $a -le $rulecount ];
do
if contains "${newrule[$a]}" "$rule";then
t=$a+1
#find all unique pool names in rule
rulepool=()
until [[ ${newrule[$t]} == *"ltm rule"* ]] || [[ ${newrule[$t]} == *"END OF RULE FILE"* ]];
do
if [[ ${newrule[$t]} == *"pool "* ]];then
#ignore commented lines
if [[ ${newrule[$t]} == *"# "* ]];then
:
else
#extract pool name from line
pool=$(echo ${newrule[$t]} | awk 'BEGIN{FS="pool "}{print $2}' | awk '{print $1}' )
if [[ $pool == *"}"* ]];then
pool=$(echo $pool | awk 'BEGIN{FS="}"}{print $1}')
fi
#strip spaces
rulepool+=($(echo $pool | sed -e 's/^[ \t]*//'))
fi
fi
let t=$t+1
done

#find unique pool names

uniqpools=($(for p in  "${rulepool[@]}" ; do  echo "$p" ; done | sort -u))
rulepoolcount=${#uniqpools[@]}
echo "|||RULE HAS $rulepoolcount UNIQUE POOLS" >> $outfile
for helper in "${uniqpools[@]}";
do
#search issue tmsh command for pool and find pool stats
commandout=()
while IFS= read -r line # Read a line
do
commandout+=("$line") # Append line to the array
done < <(nice tmsh -q show ltm pool $helper detail | grep -A5 "Ltm::Pool")
commandout+=(" ")
commandcount=0
hasmembers="0"
until [[ ${commandout[$commandcount]} == " " ]];
do
if [[ ${commandout[$commandcount]} == *"Ltm::Pool:"* ]];then
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
echo "||||$helper|||$state|$reason" >> $outfile
fi
if [[ ${commandout[$commandcount]} == *"Ltm::Pool Member:"* ]];then
hasmembers="1"
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
ipport=$(echo ${commandout[$commandcount]} | awk 'BEGIN{FS=" "}{print $NF}')
echo "|||||$ipport||$state|$reason" >> $outfile
fi
let commandcount=$commandcount+1
done
if [[ $hasmembers == "0" ]];then
echo "|||||NO POOL MEMBERS" >> $outfile
fi
done
fi
let a=$a+1
done
fi
### END RULE SECTION ###

elif [[ $haspool == 1 ]];then
### POOL SECTION ###
pool=$(echo ${offline[$i+1]} | awk 'BEGIN{FS="{"}{print $1}')
#strip spaces
pool=$(echo $pool | sed -e 's/^[ \t]*//')
#search issue tmsh command for pool and find pool stats
commandout=()
while IFS= read -r line # Read a line
do
commandout+=("$line") # Append line to the array
done < <(nice tmsh -q  show ltm pool $pool detail | grep -A5 "Ltm::Pool")
commandout+=(" ")
commandcount=0
hasmembers="0"
until [[ ${commandout[$commandcount]} == " " ]];
do
if [[ ${commandout[$commandcount]} == *"Ltm::Pool:"* ]];then
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
echo "||||$pool|||$state|$reason" >> $outfile
fi
if [[ ${commandout[$commandcount]} == *"Ltm::Pool Member:"* ]];then
hasmembers="1"
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
ipport=$(echo ${commandout[$commandcount]} | awk 'BEGIN{FS=" "}{print $NF}')
echo "|||||$ipport||$state|$reason" >> $outfile
fi
let commandcount=$commandcount+1
done
if [[ $hasmembers == "0" ]];then
echo "|||||NO POOL MEMBERS" >> $outfile
fi
### END POOL SECTION ###

else
echo "||||HAS NO POOL DEFINED" >> $outfile
fi
fi
let i=$i+1
let z=$z+1
done


echo "**********************"
echo "SEARCHING UNKNOWN VIPS"
echo "*****PLEASE WAIT******"
echo "**********************"
echo ""

count=${#unknown[@]}
i=0
z=1
while [ $i -le $count ];
do
echo -ne "$((100*$z/$count))% Complete\r"
if [[ ${unknown[$i]} == *"ltm virtual"* ]];then

#find vip name
vip=$(echo ${unknown[$i]} | awk 'BEGIN{FS="{"}{print $1}' | awk 'BEGIN{FS="ltm virtual"}{print $2}')
#find reason
t=$i
until [[ ${unknown[$t]} == *"-reason"* ]];
do
let t=$t+1
done
reason=$(echo ${unknown[$t]} | awk 'BEGIN{FS="-reason"}{print $2}')
#write out vip down and reason
state=$(echo ${unknown[$t-1]} | awk 'BEGIN{FS="-state"}{print $2}')
#get VIP ip address and port 
vipcommand=$(tmsh list ltm virtual $vip | grep destination | awk 'BEGIN{}{print $2}')
vipip=$(echo $vipcommand | awk 'BEGIN{FS=":"}{print $1}')
vipport=$(echo $vipcommand | awk 'BEGIN{FS=":"}{print $2}')
#search etc/services for port name - port number
let vipport=$(getent services $vipport | awk 'BEGIN{FS="/"}{print $1}' | awk '{print $NF}')

echo "$vip|$vipip|$vipport||||UNKNOWN|$state|$reason" >> $outfile

#find if vip has rule and pool
t=$i
hasrule=0
haspool=0
until [[ ${unknown[$t]} == " " ]];
do
if [[ ${unknown[$t]} == *"ltm virtual"* ]];then
if [[ ${unknown[$t+1]} != *":"* ]] && [[ ${unknown[$t+1]} != *"-state"* ]];then
haspool=1
fi
elif [[ ${unknown[$t]} == *":"* ]];then
hasrule=1
else
:

fi

let t=$t+1
done

#if VIP has both pool and rule
if [[ $haspool == 1 ]] && [[ $hasrule == 1 ]];then
### POOL SECTION ###
pool=$(echo ${unknown[$i+1]} | awk 'BEGIN{FS="{"}{print $1}')
#strip spaces
pool=$(echo $pool | sed -e 's/^[ \t]*//')
#search issue tmsh command for pool and find pool stats
commandout=()
while IFS= read -r line # Read a line
do
commandout+=("$line") # Append line to the array
done < <(nice tmsh -q show ltm pool $pool detail | grep -A5 "Ltm::Pool")
commandout+=(" ")
commandcount=0
hasmembers="0"
until [[ ${commandout[$commandcount]} == " " ]];
do
if [[ ${commandout[$commandcount]} == *"Ltm::Pool:"* ]];then
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
echo "||||$pool|$state|||$reason" >> $outfile
fi
if [[ ${commandout[$commandcount]} == *"Ltm::Pool Member:"* ]];then
hasmembers="1"
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
ipport=$(echo ${commandout[$commandcount]} | awk 'BEGIN{FS=" "}{print $NF}')
echo "||||||$ipport|$state||$reason" >> $outfile
fi
let commandcount=$commandcount+1
done
if [[ $hasmembers == "0" ]];then
echo "|||||NO POOL MEMBERS" >> $outfile
fi
### END POOL SECTION ###
### RULE SECTION ###
if [[ ${unknown[$i+1]} == *":"* ]] || [[ ${unknown[$i+2]} == *":"* ]];then
if [[ ${unknown[$i+1]} == *":"* ]];then
rule=$(echo ${unknown[$i+1]} | awk 'BEGIN{FS=":"}{print $1}')
fi
if [[ ${unknown[$i+2]} == *":"* ]];then
rule=$(echo ${unknown[$i+2]} | awk 'BEGIN{FS=":"}{print $1}')
fi
#strip spaces
rule=$(echo $rule | sed -e 's/^[ \t]*//')
echo "|||$rule|"  >> $outfile
#search newrule array for iRule config
a=0
while [ $a -le $rulecount ];
do
if contains "${newrule[$a]}" "$rule";then
t=$a+1
#find all unique pool names in rule
rulepool=()
until [[ ${newrule[$t]} == *"ltm rule"* ]] || [[ ${newrule[$t]} == *"END OF RULE FILE"* ]];
do
if [[ ${newrule[$t]} == *"pool "* ]];then
#ignore commented lines
if [[ ${newrule[$t]} == *"#"* ]];then
:
else
#extract pool name from line
pool=$(echo ${newrule[$t]} | awk 'BEGIN{FS="pool "}{print $2}' | awk '{print $1}' )
if [[ $pool == *"}"* ]];then
pool=$(echo $pool | awk 'BEGIN{FS="}"}{print $1}')
fi
#strip spaces
rulepool+=($(echo $pool | sed -e 's/^[ \t]*//'))
fi
fi
let t=$t+1
done

#find unique pool names

uniqpools=($(for p in  "${rulepool[@]}" ; do  echo "$p" ; done | sort -u))
rulepoolcount=${#uniqpools[@]}
echo "|||RULE HAS $rulepoolcount UNIQUE POOLS" >> $outfile
for helper in "${uniqpools[@]}";
do
#search issue tmsh command for pool and find pool stats
commandout=()
while IFS= read -r line # Read a line
do
commandout+=("$line") # Append line to the array
done < <(tnice tmsh -q show ltm pool $helper detail | grep -A5 "Ltm::Pool")
commandout+=(" ")
commandcount=0
hasmembers="0"
until [[ ${commandout[$commandcount]} == " " ]];
do
if [[ ${commandout[$commandcount]} == *"Ltm::Pool:"* ]];then
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
echo "||||$helper|||$state|$reason" >> $outfile
fi
if [[ ${commandout[$commandcount]} == *"Ltm::Pool Member:"* ]];then
hasmembers="1"
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
ipport=$(echo ${commandout[$commandcount]} | awk 'BEGIN{FS=" "}{print $NF}')
echo "|||||$ipport||$state|$reason" >> $outfile
fi
let commandcount=$commandcount+1
done
if [[ $hasmembers == "0" ]];then
echo "|||||NO POOL MEMBERS" >> $outfile
fi
done
fi
let a=$a+1
done
fi
### END RULE SECTION ###

elif [[ $haspool == 0 ]] && [[ $hasrule == 1 ]];then
### RULE SECTION ###
if [[ ${unknown[$i+1]} == *":"* ]] || [[ ${unknown[$i+2]} == *":"* ]];then
if [[ ${unknown[$i+1]} == *":"* ]];then
rule=$(echo ${unknown[$i+1]} | awk 'BEGIN{FS=":"}{print $1}')
fi
if [[ ${unknown[$i+2]} == *":"* ]];then
rule=$(echo ${unknown[$i+2]} | awk 'BEGIN{FS=":"}{print $1}')
fi
#strip spaces
rule=$(echo $rule | sed -e 's/^[ \t]*//')
echo "|||$rule" >> $outfile
#search newrule array for iRule config
a=0
while [ $a -le $rulecount ];
do
if contains "${newrule[$a]}" "$rule";then
t=$a+1
#find all unique pool names in rule
rulepool=()
until [[ ${newrule[$t]} == *"ltm rule"* ]] || [[ ${newrule[$t]} == *"END OF RULE FILE"* ]];
do
if [[ ${newrule[$t]} == *"pool "* ]];then
#ignore commented lines
if [[ ${newrule[$t]} == *"# "* ]];then
:
else
#extract pool name from line
pool=$(echo ${newrule[$t]} | awk 'BEGIN{FS="pool "}{print $2}' | awk '{print $1}' )
if [[ $pool == *"}"* ]];then
pool=$(echo $pool | awk 'BEGIN{FS="}"}{print $1}')
fi
#strip spaces
rulepool+=($(echo $pool | sed -e 's/^[ \t]*//'))
fi
fi
let t=$t+1
done

#find unique pool names

uniqpools=($(for p in  "${rulepool[@]}" ; do  echo "$p" ; done | sort -u))
rulepoolcount=${#uniqpools[@]}
echo "|||RULE HAS $rulepoolcount UNIQUE POOLS" >> $outfile
for helper in "${uniqpools[@]}";
do
#search issue tmsh command for pool and find pool stats
commandout=()
while IFS= read -r line # Read a line
do
commandout+=("$line") # Append line to the array
done < <(nice tmsh -q show ltm pool $helper detail | grep -A5 "Ltm::Pool")
commandout+=(" ")
commandcount=0
hasmembers="0"
until [[ ${commandout[$commandcount]} == " " ]];
do
if [[ ${commandout[$commandcount]} == *"Ltm::Pool:"* ]];then
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
echo "||||$helper|||$state|$reason" >> $outfile
fi
if [[ ${commandout[$commandcount]} == *"Ltm::Pool Member:"* ]];then
hasmembers="1"
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
ipport=$(echo ${commandout[$commandcount]} | awk 'BEGIN{FS=" "}{print $NF}')
echo "|||||$ipport||$state|$reason" >> $outfile
fi
let commandcount=$commandcount+1
done
if [[ $hasmembers == "0" ]];then
echo "|||||NO POOL MEMBERS" >> $outfile
fi
done
fi
let a=$a+1
done
fi
### END RULE SECTION ###

elif [[ $haspool == 1 ]];then
### POOL SECTION ###
pool=$(echo ${unknown[$i+1]} | awk 'BEGIN{FS="{"}{print $1}')
#strip spaces
pool=$(echo $pool | sed -e 's/^[ \t]*//')
#search issue tmsh command for pool and find pool stats
commandout=()
while IFS= read -r line # Read a line
do
commandout+=("$line") # Append line to the array
done < <(nice tmsh -q show ltm pool $pool detail | grep -A5 "Ltm::Pool")
commandout+=(" ")
commandcount=0
hasmembers="0"
until [[ ${commandout[$commandcount]} == " " ]];
do
if [[ ${commandout[$commandcount]} == *"Ltm::Pool:"* ]];then
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
echo "||||$pool|||$state|$reason" >> $outfile
fi
if [[ ${commandout[$commandcount]} == *"Ltm::Pool Member:"* ]];then
hasmembers="1"
state=$(echo ${commandout[$commandcount+4]} | awk 'BEGIN{FS=":"}{print $2}' )
reason=$(echo ${commandout[$commandcount+5]} | awk 'BEGIN{FS=":"}{print $2}' )
ipport=$(echo ${commandout[$commandcount]} | awk 'BEGIN{FS=" "}{print $NF}')
echo "|||||$ipport||$state|$reason" >> $outfile
fi
let commandcount=$commandcount+1
done
if [[ $hasmembers == "0" ]];then
echo "|||||NO POOL MEMBERS" >> $outfile
fi
### END POOL SECTION ###

else
echo "||||HAS NO POOL DEFINED" >> $outfile
fi
fi
let i=$i+1
let z=$z+1
done

echo "**********************"
echo "CLEANING UP TEMP FILES"
echo "*****PLEASE WAIT******"
echo "**********************"
echo ""

rm -f /tmp/vipdetails.txt
rm -f /tmp/ruledetails.txt


echo "************************************"
echo "*******   SCRIPT COMPLETE    *******"
echo "*****  OUTPUT FILE IS LOCATED ******"
echo "***** /tmp/vipdetails-csv.txt ******"
echo "************************************"
echo ""
Published Aug 21, 2017
Version 1.0
No CommentsBe the first to comment