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

quick list of vs-id and vs-name in cli ? bash script experts needed :)

Hi mates,

i am trying to get a list of vs (without virtual switches/router) in cli including vs id and vs name as a table.
When just running vsx stat -v the names are truncated.

So i created a script including a loop.

 

#!/bin/sh
source /opt/CPshared/5.0/tmp/.CPprofile.sh
source /etc/profile.d/vsenv.sh

VSLIST=`fw vsx stat -v 2>&1 | grep Trust | grep -v '<Not Applicable>' | grep -v 'SIC Status' | awk -F\| '{print $1}'`

for i in $VSLIST ; do
        VSNAME=$( vsx stat $i 2>&1| grep Name | awk '{print $2}' )
        echo $i";"$VSNAME";"
done


output is e.g.
1;vs bla;
2;vs blubb;

This was fine until now but at several vsx systems we now have > 30 vs and this script takes too long. And other scripts waiting for the result are running into timeouts.
Any hints to speed up this script or maybe a complete different way to get this list would be appreciated 🙂

Cheers

VInce

and now to something completely different - CCVS, CCAS, CCTE, CCCS, CCSM elite
0 Kudos
7 Replies
Danny
Champion Champion
Champion

You could try to get the data directly from SNMP via something like this:

timeout 5 stattest gettable 1.3.6.1.4.1.2620.1.16.22.1 1 2 3 4 5 6 7 8 9 10

OID: 1.3.6.1.4.1.2620.1.16.22.1
Full path: checkpoint.products.vsx.vsxStatusTable
Sequences:

  • 1: vsxStatusVSId - INTEGER
  • 2: vsxStatusVRId - INTEGER
  • 3: vsxStatusVsName - DisplayString
  • 4: vsxStatusVsType - DisplayString
  • 5: vsxStatusMainIP - DisplayString
  • 6: vsxStatusPolicyName- DisplayString
  • 7: vsxStatusvsPolicyType - DisplayString
  • 8: vsxStatusSicTrustState - DisplayString
  • 9: vsxStatusHAState - DisplayString
  • 10: vsxStatusVSWeight - Gauge32
0 Kudos
Vincent_Bacher
Advisor
Advisor

interesting approach. Did not know stattest gettable before.....thanks....
checking.....

# timeout 5 stattest gettable 1.3.6.1.4.1.2620.1.16.22.1 1 2 3 4 5 6 7
,,,,,,,

hmmmm 🙂

and now to something completely different - CCVS, CCAS, CCTE, CCCS, CCSM elite
0 Kudos
Danny
Champion Champion
Champion

I used stattest in the this tool to create a complete VPN S2S overview on VPN gateways. It should work the same for your demand but you have to figure out the correct query syntax. Maybe you have to use stattest getor similar. Just dig into it and do some investigation how to query your VSX data.

0 Kudos
Vincent_Bacher
Advisor
Advisor

It's so easy 😄


for i in `vsx stat -v | grep " S "| awk '{print $1}'| grep '^[0-9]' | sort -n -k1,1`; do vsenv $i >/dev/null; echo -n $i";"; echo $vsname";" | cut -f 2 -d "_"; done

and now to something completely different - CCVS, CCAS, CCTE, CCCS, CCSM elite
0 Kudos
Danny
Champion Champion
Champion

Glad you found a solution that you're happy with.
However, your code does still iterates through all the vsenv's just to fetch the full name of each specific VS. There should be a better way to do it as vsx stat -v already does what you want, though it truncates the names it probably reads in uncut.

0 Kudos
Vincent_Bacher
Advisor
Advisor

And truncated is not what i want.

and now to something completely different - CCVS, CCAS, CCTE, CCCS, CCSM elite
0 Kudos
Danny
Champion Champion
Champion

And that's why it's a good practice to check how vsx stat -v collects the data it is showing or just open a SR and ask TAC for it.

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events