cancel
Showing results for 
Search instead for 
Did you mean: 
Create a Post
Highlighted

Add cluster state to gaia prompt - clish and bash

Jump to solution

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 

0 Kudos
1 Solution

Accepted Solutions
Highlighted

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

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.

View solution in original post

Tags (1)
0 Kudos
15 Replies
Highlighted

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

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 ?

0 Kudos
Highlighted

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

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
Highlighted

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution
Maybe you find a solution here: sk65923 How to configure the cluster to send SNMP Trap upon failover
0 Kudos
Highlighted

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

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
Highlighted

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

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

0 Kudos
Admin
Admin

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution
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
Highlighted
Gold

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

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
Highlighted

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

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
Highlighted

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

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.

View solution in original post

Tags (1)
0 Kudos
Highlighted

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

Hi @Adrian_Pillo,

I have added your article to the One Liner collection:

One-liner collection 

0 Kudos
Highlighted
Pearl

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

@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

Highlighted
Silver

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

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
Highlighted
Pearl

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

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

Highlighted
Silver

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

Can't wait seeing it! 🤗

0 Kudos
Highlighted
Iron

Re: Add cluster state to gaia prompt - clish and bash

Jump to solution

Hi!

@boxis-green just posted

 

which might be interesting regarding this topic.

 

That's all. Have a good day.

0 Kudos