Forum Discussion
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.
- nitass
Employee
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
Nimbostratus
@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.
- jaikumar_f5
Noctilucent
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
Nimbostratus
@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
Nimbostratus
@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
- nitass
Employee
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
Nimbostratus
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.
- nitass
Employee
it is awk. i do not have specific website or article.
- bsb
Nimbostratus
ok, thanks for the info.
- Jay_PL
Nimbostratus
Hi,
I tried this script. Getting the same error.
'B_Capture.txt: line 6: syntax error near unexpected token
for VS in $VIRTUALS;'B_Capture.txt: line 6:
added "!/bin/bash" on top of the script as well.
+++++++++++++++++++++ tmp cat LB_Capture.txt
!/bin/bash Making headings & intialize the fileecho Virtual-Server, Destination, Pool, Pool-Members > /var/tmp/$HOSTNAME.csv
Capture all virtuals in the LTMVIRTUALS=$(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!!
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com