Forum Discussion

bsb's avatar
bsb
Icon for Nimbostratus rankNimbostratus
Dec 29, 2017

Fetch all details about VS, POOLS, Nodes, etc.

@jaikumar_f5

 

Hi Jay, was going through your post.

 

command echo Virtual-Server, Destination, Pool, Pool-Members > /var/tmp/$HOSTNAME.csv creates an CSV file, i tested this and it creates a csv file.

 

how do i call below code.

 

Capture all virtuals in the LTM

VIRTUALS=$(tmsh list ltm virtual | grep "ltm virtual" | cut -d" " -f3) for VS in $VIRTUALS; do DEST=$(tmsh list ltm virtual $VS | grep destination | cut -d" " -f6) POOL=$(tmsh list ltm virtual $VS | grep pool | cut -d" " -f6) if [ -n "$POOL" ]; then MBRS=$(tmsh list ltm pool "$POOL" | grep address | cut -d" " -f14) fi echo $VS,$DEST,$POOL,$MBRS >> /var/tmp/$HOSTNAME.csv done

 

do i need to paste in a file and store it inside a specific folder to call it, what would be the format, could you please let me know.

 

10 Replies

  • just another example using awk

    [root@ve13a:Active:In Sync] config  tmsh list ltm virtual one-line |awk '{for(i=0;i<=NF;i++)if($i=="pool"){p=$(i+1)}; print $3,$6,p}' |awk '{cmd="tmsh list ltm pool " $3 " one-line"; cmd|getline r; print $1,$2,$3,r}' |awk '{printf "%s,%s,%s",$1,$2,$3} {for(j=3;j<=NF;j++)if($j~/:/){printf ",%s",$j} {print ""}}'
    bar,172.28.24.10:80,poola,200.200.200.101:80
    baz,1.2.3.4:80,poolb,200.200.200.111:80,200.200.200.201:80
    
  • bsb's avatar
    bsb
    Icon for Nimbostratus rankNimbostratus

    @nitass, yes really its worked well, copied it to notepad and did necessary formatting in excel. thanks. trying our Jai code as well, that directly moves it to excel as well, let me try that as well.

     

  • You can also save this command in excel,,

    Just append it the output to an .csv file, like below,

    tmsh list ltm virtual one-line |awk '{for(i=0;i<=NF;i++)if($i=="pool"){p=$(i+1)}; print $3,$6,p}' |awk '{cmd="tmsh list ltm pool " $3 " one-line"; cmd|getline r; print $1,$2,$3,r}' |awk '{printf "%s,%s,%s",$1,$2,$3} {for(j=3;j<=NF;j++)if($j~/:/){printf ",%s",$j} {print ""}}' >> /var/tmp/collecting-nitas-method.csv

  • bsb's avatar
    bsb
    Icon for Nimbostratus rankNimbostratus

    @nitass : i have one issue with this case, LB without SNAT configuration works perfectly, whereas when i try to use the command where i have configured ASM and SNAT, i get the below output VS_www.test.com,10.10.10.10:http,SNAT_POOL

     

    when i change the pool in the below script to POOL (caps), i get below output

     

    VS_www.test.com,10.10.10.10:http,ltm,Server_10.20.20.1:80,Server_10.20.20.2:80,Server_10.20.20.3:80 here POOL name is missing.

     

    trying to figure out by modifying the script. to be frank, i dont understand the script, trying to decode it.can you throw some light on it.

     

  • bsb's avatar
    bsb
    Icon for Nimbostratus rankNimbostratus

    @Jai, thanks for the same, its gets into csv output. but as mentioned when i run it, as i have configured SNAT, i get below issue 01020036:3: The requested Pool (/Common/SNAT_POOL) was not found. output is VS_Test10.10.10.10:http SNAT_POOL when i change ($i=="pool") to ($i=="POOL") and tmsh list ltm pool to tmsh list ltm POOL (caps) i get below outout

     

    VS_Test10.10.10.10:httpltm10.10.20.1:8010.10.20.2:80 where Pool name doesn't display

     

  • when i try to use the command where i have configured ASM and SNAT, i get the below output VS_www.test.com,10.10.10.10:http,SNAT_POOL

    can you try this?

    i think the problem is the script grabs pool using "pool" keyword. unfortunately, snatpool also uses "pool" keyword. so, what i added is to assume the 1st "pool" keyword is pool configuration.

    [root@ve13a:Active:In Sync] config  tmsh list ltm virtual one-line |awk '{for(i=0;i<=NF;i++)if($i=="pool"){p=$(i+1);break}; print $3,$6,p}' |awk '{cmd="tmsh list ltm pool " $3 " one-line"; cmd|getline r; print $1,$2,$3,r}' |awk '{printf "%s,%s,%s",$1,$2,$3} {for(j=3;j<=NF;j++)if($j~/:/){printf ",%s",$j} {print ""}}'
    bar,172.28.24.10:80,poola,200.200.200.101:80
    baz,1.2.3.4:80,poolb,200.200.200.111:80,200.200.200.201:80
    
  • bsb's avatar
    bsb
    Icon for Nimbostratus rankNimbostratus

    excellent, it worked.

     

    I could see below difference

     

    if($i=="pool"){p=$(i+1);break} - not working

     

    if($i=="pool"){p=$(i+1)} - working

     

    just by removing break keyword, it works. can you please share any specific link or article which gives out info about these kind of scripts, i am unable to understand it.

     

  • it is awk. i do not have specific website or article.

     

  • Jay_PL's avatar
    Jay_PL
    Icon for Nimbostratus rankNimbostratus

    Hi,

    I tried this script. Getting the same error.

    'B_Capture.txt: line 6: syntax error near unexpected token

    'B_Capture.txt: line 6:
    for VS in $VIRTUALS;

    added "!/bin/bash" on top of the script as well.

    +++++++++++++++++++++ tmp cat LB_Capture.txt

    !/bin/bash Making headings & intialize the file

    echo Virtual-Server, Destination, Pool, Pool-Members > /var/tmp/$HOSTNAME.csv

    Capture all virtuals in the LTM

    VIRTUALS=$(tmsh list ltm virtual | grep "ltm virtual" | cut -d" " -f3) for VS in $VIRTUALS; do DEST=$(tmsh list ltm virtual $VS | grep destination | cut -d" " -f6) POOL=$(tmsh list ltm virtual $VS | grep pool | cut -d" " -f6) if [ -n "$POOL" ]; then MBRS=$(tmsh list ltm pool "$POOL" | grep address | cut -d" " -f14) fi echo $VS,$DEST,$POOL,$MBRS >> /var/tmp/$HOSTNAME.csv done +++++++++++++++++++++++

    Do suggest!!