Have some code. Share some code.
Showing results for 
Search instead for 
Did you mean: 

Problem this snippet solves:

The below is a simple code to get a report on Virtuals present in the BigIP, with its name, state, status and the pool name associated to it.

Should be helpful in building reports for management or auditing. The output can be seen in console (if needed) or can be written to a file with csv format, so when opened in excel it would look like below snapshot.

The output file will be save in /var/tmp/virtual_stats-output.csv


How to use this snippet:

In the console,


create cli script virtual_stats

and paste the below code and save.

Code :

create script virtual_stats {
proc script::run {} {
    exec echo Virtual,State,Status,Pool, > /var/tmp/virtual_stats-output.csv
foreach { obj } [tmsh::get_status ltm virtual] {
    set l1 [tmsh::get_field_value $obj "name"]
    set l2 [tmsh::get_field_value $obj "status.enabled-state"]
    set l3 [tmsh::get_field_value $obj "status.availability-state"]
    set l4 [tmsh::get_config ltm virtual $l1 pool ]
    set poolname [lindex [split [lindex [split $l4 "\n"] 1] " "] 5]
    ###the below line can be commented to stop displaying output in console
    puts "$l1,$l2,$l3,$poolname"
    exec echo "$l1,$l2,$l3,$poolname" >> /var/tmp/virtual_stats-output.csv

Tested this on version:

Version history
Last update:
‎07-Mar-2019 07:13
Updated by: