- CheckMates
- :
- Products
- :
- Quantum
- :
- Security Gateways
- :
- Re: Add cluster state to gaia prompt - clish and ...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Are you a member of CheckMates?
×- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Add cluster state to gaia prompt - clish and bash
Bash prompt can be changed by setting env var PS1 to whatever you want. Same with clish executing clish -c "set clienv prompt <text>". But how can I trigger cluster failover in order to place ACTIVE or STANDBY in my prompt? Yes management get's a log, we can have eMail, snmp oder script alerts on that event, but all just on management, not on gateway. Is there a way to execute scripts on gateway triggered by a cluster failover event? Thanks
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Adrian_Pillo,
this works:-)
export PS1="\h $(cphaprob stat |grep local |awk '{print $5}') # "
If you copy this to the following file ".bashrc" in your home directory, it is permanent.
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
PS1="\h $(cphaprob stat |grep local |awk '{print $5}') # "
It's an interesting idea of you. I built the script into my cluster.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This has a limitation which is important to note: it runs the command substitution one time at the beginning when PS1 is set. This is undesirable, as the cluster status in the prompt stays the same even if you fail over. To confirm this, run 'echo "$PS1"'. It will show the cluster status in the prompt rather than the command. I posted a set of prompt improvements over on CPUG:
https://www.cpug.org/forums/showthread.php/22738-Command-prompt-improvements
In short, you need to escape the dollar sign to cause the shell not to evaluate it when setting PS1, but to store it to PS1 as a dollar sign instead. Each time the prompt is printed, PS1 is evaluated. Since it contains the $(...) construct, the command substitution is run and the current cluster state at the time of prompt printing is printed.
I also prefer to index from the end, like so:
awk '{print \$NF}'
$NF is set to the number of fields awk detected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why would one want to trigger cluster failover except for testing purposes ? Who is working on GW CLI constantly and has to be reminded of the node he currently is on ? Or is the question purely academic and not meant for production ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
no when we are doing updates on more systems simustaneously and many ssh-terems are on your screen it would be very important, that you know any time who is the master.
I wrote this script:
!/bin/bash
CLUSTER_STATE=$(cphaprob state | grep local | awk '{ print $5 }')
echo Cluster state is: $CLUSTER_STATE
export PS1="\e[41;1;33m [$CLUSTER_STATE] \e[40;0;37m [Expert@$HOSTNAME]#"
echo Prompt is: $PS1
#
## clish -c "set clienv prompt %M"
The final question is, how ca I trigger this script every time a failover occurs. Obiously it is not enaugh to execute script on logon or perodically.
I need a event (member goes up or down) which can execute somethig like a customized action, as alert on management is able to do.
Thanks and kind regards
Adrian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
GW sends log/event to logserver/management and management sends snmp. I want to be management independent and get the cluster state direct form gateway. I should request for enhancement on this. One of the most important info on cluster member is active or standby ... cphaprob stat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You did not read the sk - you can also trigger a trap on GW...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My suggestion: a periodic cron job.
Regardless, if you're in the management UI/CLI when a failover occurs for whatever reason and this script triggers, the clish command will fail since it won't have exclusive lock.
Further, it won't update the prompt of existing expert mode sessions, only new ones that start.
To get exactly what you want is an RFE.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adrian,
„when we are doing updates on more systems simustaneously and many ssh-terems are on your screen it would be very important, that you know any time who is the master.“
I understand you and I did such configurations more then once’s. But now after 20 years doing an IT job it‘s time to say goodby to more then 4 terminal session at the same time. That‘s lessons learned, doing to much things at the same time brings more errors and problems then good results.
You can call me an old boy not able to do multitasking, but if you have requirements todo a lot of updates at the same time you should find another solution then tagging your screen full with terminals.
Wolfgang
PS: But it would be nice to see the cluster, state in the prompt. Interesting requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I had some similiar challenge in the past and wrote a very tiny shell script that periodically look for a string "Local machine state changed to ACTIVE" in /var/log/messages, and that would trigger a specific action.
Not sure if the string remains the same in R80.x versions.
Regards
PB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Adrian_Pillo,
this works:-)
export PS1="\h $(cphaprob stat |grep local |awk '{print $5}') # "
If you copy this to the following file ".bashrc" in your home directory, it is permanent.
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
PS1="\h $(cphaprob stat |grep local |awk '{print $5}') # "
It's an interesting idea of you. I built the script into my cluster.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Adrian_Pillo,
I have added your article to the One Liner collection:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Adrian_Pillo wants to change the CLI prompt immediately when the cluster state changes.
.bashrc is only executed once at user login. Therefore @PhoneBoy suggested a cronjob.
I suggest coloring the ClusterXL status at the CLI prompt like this example for ~/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then . /etc/bashrc; fi
# User specific aliases and functions
a=`cphaprob stat|grep local|awk '{print $5}'`; case $a in *CTIVE*|*ctive*) a=`tput setaf 2; echo $a`;; *TANDBY*|*tandby*) a=`tput setaf 5; echo $a`;; *) a=`tput setaf 1; echo $a`; esac; PS1="[Expert@\h:$INSTANCE_VSID:$a\e[0m]# "; unset a
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would be a dream when switching to a different VS this check would be done again for the VS I am switching to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm working on this. I'll publish a bigger solution for all Check Point systems after CPX.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can't wait seeing it! 🤗
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This has a limitation which is important to note: it runs the command substitution one time at the beginning when PS1 is set. This is undesirable, as the cluster status in the prompt stays the same even if you fail over. To confirm this, run 'echo "$PS1"'. It will show the cluster status in the prompt rather than the command. I posted a set of prompt improvements over on CPUG:
https://www.cpug.org/forums/showthread.php/22738-Command-prompt-improvements
In short, you need to escape the dollar sign to cause the shell not to evaluate it when setting PS1, but to store it to PS1 as a dollar sign instead. Each time the prompt is printed, PS1 is evaluated. Since it contains the $(...) construct, the command substitution is run and the current cluster state at the time of prompt printing is printed.
I also prefer to index from the end, like so:
awk '{print \$NF}'
$NF is set to the number of fields awk detected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
@Ziegelsambach just posted
which might be interesting regarding this topic.
That's all. Have a good day.
