Capture Status BEFORE a Change

7 min read

I run this shell script to capture the status of virtual servers, pool, members before the change and after the change and then open the output in VSCode and do a diff/compare and it shows me anything with a different status or new or removed.

This helps me know my change didn’t bring anything down

CREATE ltmchgverify.sh and paste the following

ShellScript
#!/bin/bash
## Author: Cowboy Denny
## Last Modified: 2023.07.10
## LTM: Change Verify BEFORE & AFTER change deployment
## RUN with: bash ltmchgverify.sh
unset TSTtype;
unset DIFFchoice;
unset totalvips;
unset availvips;
unset unavailvips;
unset offlinevips;
unset unknownvips;
unset disabledvips;
unset totalpools;
unset availpools;
unset unavailpools;
unset offlinepools;
unset unknownpools;
unset disabledpools;
unset totalnodes;
unset availnodes;
unset unavailnodes;
unset offlinenodes;
unset unknownnodes;
unset disablednodes;
unset chgfilename;
clear

echo "Is this running BEFORE change or AFTER change?"
echo "Please type: BEFORE or AFTER"
read TSTtype
#echo "TSTtype="$TSTtype
if [ $TSTtype == 'BEFORE' ]
then
echo ""
echo "BEFORE was selected"
find /var/tmp/ -name "*BEFORE.txt" -type f -mtime +1 -delete
echo "...checking if the file already exists... (if it does exist you'll receive a prompt to overwrite file)"
export chgfilename=/var/tmp/$(echo $HOSTNAME | cut -d'.' -f1)-$(date +%Y%m%d)-LTM$TSTtype.txt;
if test -f "$chgfilename"; then
echo "File exists: $chgfilename Do you want to replace it?"
echo "Please type: YES or NO"
read "replacefile"
if [ $replacefile == 'NO' ]; then
echo "You chose to NOT replace the file.. exiting script"
unset TSTtype;
unset DIFFchoice;
unset totalvips;
unset availvips;
unset unavailvips;
unset offlinevips;
unset unknownvips;
unset disabledvips;
unset totalpools;
unset availpools;
unset unavailpools;
unset offlinepools;
unset unknownpools;
unset disabledpools;
unset totalnodes;
unset availnodes;
unset unavailnodes;
unset offlinenodes;
unset unknownnodes;
unset disablednodes;
unset chgfilename;
exit
elif [ $replacefile == 'YES' ]; then
echo "You chose to REPLACE the file.."
echo " .. script will continue to replace existing file with output of this script"
echo ""
fi
fi
elif [ $TSTtype == 'AFTER' ]; then
echo "AFTER was selected"
echo "...does the file already exist before we overwrite it?"
find /var/tmp/ -name "*AFTER.txt" -type f -mtime +1 -delete
export chgfilename=/var/tmp/$(echo $HOSTNAME | cut -d'.' -f1)-$(date +%Y%m%d)-LTM$TSTtype.txt;
if test -f "$chgfilename"; then
echo "File exists: $chgfilename Do you want to replace it?"
echo "Please type: YES or NO"
read "replacefile"
if [ $replacefile == 'NO' ]; then
echo "You chose to NOT replace the file.. exiting script"
unset TSTtype;
unset DIFFchoice;
unset totalvips;
unset availvips;
unset unavailvips;
unset offlinevips;
unset unknownvips;
unset disabledvips;
unset totalpools;
unset availpools;
unset unavailpools;
unset offlinepools;
unset unknownpools;
unset disabledpools;
unset totalnodes;
unset availnodes;
unset unavailnodes;
unset offlinenodes;
unset unknownnodes;
unset disablednodes;
unset chgfilename;
exit
elif [ $replacefile == 'YES' ]; then
echo "You chose to REPLACE the file.."
echo " .. script will continue to replace existing file with output of this script"
echo ""
fi
fi
else
echo "ERROR: $TSTtype does not match one of the two choices: BEFORE or AFTER. EXITING SCRIPT"
unset TSTtype;
exit
fi

echo "Output of this Data Gathering will be stored in file:"$chgfilename
echo "...."
echo "LTM: Data Gathering has started... this takes about 60-90 seconds"
echo "1/3 PATIENCE while gather all Virtual Servers...."
export totalvips=$(tmsh -q -c 'cd / ; show ltm virtual recursive' | egrep 'Ltm::Virtual|Availability' | grep -c "Ltm::Virtual");
echo " Total Virtual Servers:"$totalvips;
export availvips=$(tmsh -q -c 'cd / ; show ltm virtual recursive' | egrep 'Ltm::Virtual|Availability' | grep -c ": available");
echo " Total Available Virtual Servers:"$availvips;
export unavailvips=$(tmsh -q -c 'cd / ; show ltm virtual recursive' | egrep 'Ltm::Virtual|Availability' | grep -c ": unavailable");
echo " Total Unavailable Virtual Servers:"$unavailvips;
export offlinevips=$(tmsh -q -c 'cd / ; show ltm virtual recursive' | egrep 'Ltm::Virtual|Availability' | grep -c ": offline");
echo " Total Offline Virtual Servers:"$offlinevips;
export unknownvips=$(tmsh -q -c 'cd / ; show ltm virtual recursive' | egrep 'Ltm::Virtual|Availability' | grep -c ": unknown");
echo " Total Unknown Virtual Servers:"$unknownvips;
export disabledvips=$(tmsh -q -c 'cd / ; show ltm virtual recursive' | egrep 'Ltm::Virtual|Availability' | grep -c ": disabled");
echo " Total Disabled Virtual Servers:"$disabledvips;
echo ""
echo "2/3 PATIENCE while gather all Pools...."
export totalpools=$(tmsh -q -c 'cd / ; show ltm pool recursive' | egrep 'Ltm::|Availability' | grep -c "Ltm::");
echo " Total Pools:"$totalpools;
export availpools=$(tmsh -q -c 'cd / ; show ltm pool recursive' | egrep 'Ltm::|Availability' | grep -c ": available");
echo " Total Available Pools:"$availpools;
export unavailpools=$(tmsh -q -c 'cd / ; show ltm pool recursive' | egrep 'Ltm::|Availability' | grep -c ": unavailable");
echo " Total Unavailable Nodes:"$unavailpools;
export offlinepools=$(tmsh -q -c 'cd / ; show ltm pool recursive' | egrep 'Ltm::|Availability' | grep -c ": offline");
echo " Total Offline Nodes:"$offlinepools;
export unknownpools=$(tmsh -q -c 'cd / ; show ltm pool recursive' | egrep 'Ltm::|Availability' | grep -c ": unknown");
echo " Total Unknown Nodes:"$unknownpools;
export disabledpools=$(tmsh -q -c 'cd / ; show ltm pool recursive' | egrep 'Ltm::|Availability' | grep -c ": disabled");
echo " Total Disabled Nodes:"$disabledpools;
echo ""
echo "3/3 PATIENCE while gather all Nodes...."
export totalnodes=$(tmsh -q -c 'cd / ; show ltm node recursive' | egrep 'Ltm::|Availability' | grep -c "Ltm::");
echo " Total Nodes:"$totalnodes;
export availnodes=$(tmsh -q -c 'cd / ; show ltm node recursive' | egrep 'Ltm::|Availability' | grep -c ": available");
echo " Total Available Nodes:"$availnodes;
export unavailnodes=$(tmsh -q -c 'cd / ; show ltm node recursive' | egrep 'Ltm::|Availability' | grep -c ": unavailable");
echo " Total Unavailable Nodes:"$unavailnodes;
export offlinenodes=$(tmsh -q -c 'cd / ; show ltm node recursive' | egrep 'Ltm::|Availability' | grep -c ": offline");
echo " Total Offline Nodes:"$offlinenodes;
export unknownnodes=$(tmsh -q -c 'cd / ; show ltm node recursive' | egrep 'Ltm::|Availability' | grep -c ": unknown");
echo " Total Unknown Nodes:"$unknownnodes;
export disablednodes=$(tmsh -q -c 'cd / ; show ltm node recursive' | egrep 'Ltm::|Availability' | grep -c ": disabled");
echo " Total Disabled Nodes:"$disablednodes;
echo ""
date > $chgfilename;
echo "Info for hostname...." >> $chgfilename;
tmsh list sys global-settings hostname | grep hostname >> $chgfilename;
echo "F5 running version...." >> $chgfilename;
tmsh -q show sys software status | grep "yes complete" >> $chgfilename;
echo "Master Key is..." >> $chgfilename;
f5mku -K >> $chgfilename;
echo "now exporting all Virtual Servers to file"
echo "***VS-IPs***" >> $chgfilename;
tmsh -q -c 'cd / ; show ltm virtual recursive' | egrep 'Ltm::Virtual|Availability|State|Reason|Destination' >> $chgfilename;
echo "now exporting all Pools to file"
echo "***POOLs***" >> $chgfilename;
tmsh -q -c 'cd / ; show ltm pool recursive' | egrep 'Ltm::|Availability|State|Reason' >> $chgfilename;
echo "now exporting all Nodes to file"
echo "***NODES***" >> $chgfilename;
tmsh -q -c 'cd / ; show ltm node recursive' | egrep 'Ltm::|Availability|State|Reason' >> $chgfilename;
echo ""
echo "now adding the stats gathered to the file"
echo "VIPs TOTAL:"$totalvips " Avail:"$availvips " Unavailable:"$unavailvips " Offline:"$offlinevips " Unknown:"$unknownvips " Disabled:"$disabledvips >> $chgfilename;
echo "POOLS TOTAL:"$totalpools " Avail:"$availpools " Unavailable:"$unavailpools " Offline:"$offlinepools " Unknown:"$unknownpools " Disabled:"$disabledpools >> $chgfilename;
echo "NODES TOTAL:"$totalnodes " Avail:"$availnodes " Unavailable:"$unavailnodes " Offline:"$offlinenodes " Unknown:"$unknownnodes " Disabled:"$disablednodes >> $chgfilename;
date >> $chgfilename;
#cat $chgfilename;
if [ $TSTtype == 'AFTER' ]; then
echo "Would you like to compare BEFORE and AFTER?"
echo "Please type: YES or NO"
read DIFFchoice
if [ $DIFFchoice == 'YES' ]; then
# diff -c /var/tmp/$(echo $HOSTNAME | cut -d'.' -f1)-$(date +%Y%m%d)-LTMBEFORE.txt /var/tmp/$(echo $HOSTNAME | cut -d'.' -f1)-$(date +%Y%m%d)-LTMAFTER.txt
# diff -a -y --suppress-common-lines <(echo /var/tmp/$(echo $HOSTNAME | cut -d'.' -f1)-$(date +%Y%m%d)-LTMBEFORE.txt; cat /var/tmp/$(echo $HOSTNAME | cut -d'.' -f1)-$(date +%Y%m%d)-LTMBEFORE.txt) <(echo /var/tmp/$(echo $HOSTNAME | cut -d'.' -f1)-$(date +%Y%m%d)-LTMAFTER.txt; cat /var/tmp/$(echo $HOSTNAME | cut -d'.' -f1)-$(date +%Y%m%d)-LTMAFTER.txt) | sed 2i=============================================================================
diff -y -W 300 <(echo /var/tmp/$(echo $HOSTNAME | cut -d'.' -f1)-$(date +%Y%m%d)-LTMBEFORE.txt; cat /var/tmp/$(echo $HOSTNAME | cut -d'.' -f1)-$(date +%Y%m%d)-LTMBEFORE.txt) <(echo /var/tmp/$(echo $HOSTNAME |
cut -d'.' -f1)-$(date +%Y%m%d)-LTMAFTER.txt; cat /var/tmp/$(echo $HOSTNAME | cut -d'.' -f1)-$(date +%Y%m%d)-LTMAFTER.txt) | grep -v onnections | grep -v equests | grep -v essions
elif [ $DIFFchoice == 'NO' ]; then
echo "your choice was $DIFFchocie so no diff on files performed"
echo ""
else
echo "no idea what $DIFFchoice is since its not YES or NO"
fi
fi
echo "Done with $TSTtype change data gathering. NOTE for more info look at output file: $chgfilename "
unset TSTtype;
unset DIFFchoice;
unset totalvips;
unset availvips;
unset unavailvips;
unset offlinevips;
unset unknownvips;
unset disabledvips;
unset totalpools;
unset availpools;
unset unavailpools;
unset offlinepools;
unset unknownpools;
unset disabledpools;
unset totalnodes;
unset availnodes;
unset unavailnodes;
unset offlinenodes;
unset unknownnodes;
unset disablednodes;
unset chgfilename;
echo "Now exiting"
exit

Leave a Reply