How find offline and unknown VIPs, Pools, and Pools in iRules
Problem this snippet solves:
I needed a way to search our F5s for offline and unknown VIPs. If a VIP was offline or unknown. I needed to list out the VIP, it's pool, and it's members.
Also if a VIP has an iRule configured, it will search the iRule and gather any pools defined in it and give you stats on them as well.
How to use this snippet:
simply put this script on the LTM in any directory and run it.
Open with Excel, change Excel to delimit the file on a PIPE "|" and it will format correctly.
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" #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 " " >> /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}') echo "$vip|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|iRULE" >> $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|iRULE" >> $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}') echo "$vip|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|iRULE" >> $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|iRULE" >> $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 19, 2017
Version 1.0thaynes2016_297
Nimbostratus
Joined May 05, 2019
thaynes2016_297
Nimbostratus
Joined May 05, 2019
Works like charm, you can use the sed to replace PIPE with comma and save the file directly in csv format.
sed 's/|/,/g' /tmp/vipdetails-csv.txt > /tmp/vipdetails-new.csv