Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Adrian_Pillo
Participant
Jump to solution

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 

2 Solutions

Accepted Solutions
HeikoAnkenbrand
Champion Champion
Champion

Hi @Adrian_Pillo,

this works:-)

 

cmd_ak.JPG

 

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.

➜ CCSM Elite, CCME, CCTE

View solution in original post

Bob_Zimmerman
Authority
Authority

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.

View solution in original post

0 Kudos
16 Replies
G_W_Albrecht
Legend
Legend

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 ?

CCSE CCTE CCSM SMB Specialist
0 Kudos
Adrian_Pillo
Participant

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

 

 

0 Kudos
G_W_Albrecht
Legend
Legend
Maybe you find a solution here: sk65923 How to configure the cluster to send SNMP Trap upon failover
CCSE CCTE CCSM SMB Specialist
0 Kudos
Adrian_Pillo
Participant

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  

0 Kudos
G_W_Albrecht
Legend
Legend

You did not read the sk - you can also trigger a trap on GW...

CCSE CCTE CCSM SMB Specialist
0 Kudos
PhoneBoy
Admin
Admin
Let's assume you find a way to do this.
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.
0 Kudos
Wolfgang
Authority
Authority

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.

0 Kudos
Pedro_Boavida
Contributor
Contributor

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

 

0 Kudos
HeikoAnkenbrand
Champion Champion
Champion

Hi @Adrian_Pillo,

this works:-)

 

cmd_ak.JPG

 

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.

➜ CCSM Elite, CCME, CCTE
HeikoAnkenbrand
Champion Champion
Champion

Hi @Adrian_Pillo,

I have added your article to the One Liner collection:

One-liner collection 

➜ CCSM Elite, CCME, CCTE
0 Kudos
Danny
Champion Champion
Champion

@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

cli_prompt.png

Sven_Glock
Advisor

I would be a dream when switching to a different VS this check would be done again for the VS I am switching to

0 Kudos
Danny
Champion Champion
Champion

I'm working on this. I'll publish a bigger solution for all Check Point systems after CPX.

Sven_Glock
Advisor

Can't wait seeing it! 🤗

0 Kudos
Bob_Zimmerman
Authority
Authority

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.

0 Kudos
Joshua
Contributor

Hi!

@Ziegelsambach just posted

 

which might be interesting regarding this topic.

 

That's all. Have a good day.

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events