TMSH Cli Script - Virtual Server, State, Status, Pool Name Report in CSV

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,

tmsh

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:

13.0
Updated Jun 06, 2023
Version 2.0

Was this article helpful?

2 Comments

  • Hi jaikumar_f5 - thanks for this! 🙂

    Can this be adapted to give how long a server has been down, or to show servers which have been down for longer than N days?

  • Leslie_Hubertus - Sorry i couldn't get back sooner.

    Blessed with a new born, been busy. 

    Certainly we can add little bit logic to get those details as well. I'll try and update here back. Thanks.