The code below can be added to ~/.bashrc
to calculate the ClusterXL status of the local appliance and display it live in the prompt.
This was the result of too much wasted time troubleshooting why traffic is not showing up in captures only to find I assumed wrong, and was working on the standby member. This gives easy visibility into the status of the member while working.
Will show all cluster states, including
- Active
- Standby
- Down
- Active(!)
The script will update each time it is displayed, so the prompt will display any change in the ClusterXL status immediately following a failover event, with no need to log out / log in of the shell. This will work on clusters with any number of members in the cluster since the script just checks the local appliance's state. Just insert this code into each member's ~/.bashrc
function ha_prompt() {
# Only run if in HA mode
if cphaprob stat | grep -q 'High Availability'; then
# Get local member cphaprob status
cluster_member=$(cphaprob stat | grep \(local\));
# Grab the info in the state column and format
cluster_state=$(echo $cluster_member | awk '{print $(NF-1)}' | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}');
# Return value
echo $cluster_state
fi
}
# Allows for live prompt updating
PROMPT_COMMAND='calculate_prompt'
# Rebuild prompt
function calculate_prompt {
PS1="($(ha_prompt))"; # Add ClusterXL state calculated from function
PS1+="[Expert@\h:";
PS1+=$(cat /proc/self/nsid); # VSX VS ID
PS1+="]# "
}
Below is a demo of the new prompt in action
.