cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Problem this snippet solves:

This is a simple cli script used to collect all the WideIP, LB Method, Status, State, Pool Name, Pool LB, Pool Members, Pool Fall back, Last Resort pool info in CSV format.

A sample output would be like below,


0151T0000040MBqQAM.jpg



One can customize the code to extract other fields available too. Check out my other codeshare of LTM report.


Note: The codeshare may get multiple version, use the latest version alone. The reason to keep the other versions is for end users to understand & compare, thus helping them to modify to their own requirements. Hope it helps.


How to use this snippet:

Login to the GTM/DNS, create your script by running the below commands and paste the code provided in snippet,


tmsh
create cli script gtm-config-parser


Delete the proc blocks, so it looks something like below,

create script gtm-config-parser {
## PASTE THE CODE HERE ##
}


and paste the code provided in the snippet.


Note: When you paste it, the indentation may be realigned, it shouldn't cause any errors, but the list output would show improperly aligned.

Feel free to delete the tab spaces in the code snippet & paste it while creating, so indentation is aligned properly.



And you can run the script like below,


tmsh run cli script gtm-config-parser > /var/tmp/gtm-config-parser-output.csv


And get the output from the saved file, open it on excel. Format it & use it for audit & reporting.

cat /var/tmp/gtm-config-parser-output.csv


Feel free to add more elements as per your requirements.

For version 13.x & higher, there requires a small change in the code. Refer the comments section. Thanks to @azblaster

Code :

proc script::run {} {
    puts "WIP,LB-MODE,WIP-STATUS,WIP-STATE,POOL-NAME,POOL-LB,POOL-MEMBERS,POOL-FB,LASTRESORT-POOL"
    foreach { obj } [tmsh::get_config gtm wideip all-properties] {
        set wipname [tmsh::get_name $obj]
        set wippools [tmsh::get_field_value $obj pools]
        set lbmode [tmsh::get_field_value $obj "pool-lb-mode"]
        set lastresort [tmsh::get_field_value $obj "last-resort-pool"]
        foreach { status } [tmsh::get_status gtm wideip $wipname] {
            set wipstatus [tmsh::get_field_value $status "status.availability-state"]
            set wipstate [tmsh::get_field_value $status "status.enabled-state"]
        }
        foreach wippool $wippools {
            set pool_name [tmsh::get_name $wippool]
            set pool_configs [tmsh::get_config /gtm pool $pool_name all-properties]
            foreach pool_config $pool_configs {
				set pool_lb [tmsh::get_field_value $pool_config "load-balancing-mode"]
				set pool_fb [tmsh::get_field_value $pool_config "fallback-mode"]
                if { [catch { set member_name [tmsh::get_field_value $pool_config "members" ]} err] } {
                    set pool_member $err
                } else {
                    set pool_member ""
                    set member_name [tmsh::get_field_value $pool_config "members"]
                    foreach member $member_name {
                        append pool_member "[lindex $member 1] "
                    }
                }
                puts "$wipname,$lbmode,$wipstatus,$wipstate,$pool_name,$pool_lb,$pool_member,$pool_fb,$lastresort"
            }
        }
    }
}

Tested this on version:

11.6
Comments
azblaster
Nimbostratus
Nimbostratus

Im getting this error

(tmos)# run cli script gtm-config-parser

WIP,LB-MODE,WIP-STATUS,WIP-STATE,POOL-NAME,POOL-LB,POOL-MEMBERS,POOL-FB,LASTRESORT-POOL

gtm-config-parser: script failed to complete:

can't eval proc: "script::run"

"aais-xxxx" unexpected argument

  while executing

"tmsh::get_status gtm wideip $wipname"

  (procedure "script::run" line 😎

  invoked from within

"script::run" line:1

script did not successfully complete, status:1

 

 

 

I couldn't think of a reason why it wasn't able to pull the state & status information of your wideip "aais-xxxx". I've tested in my v13 box & its working totally fine. I could see in your error msg, its failing at line 8 which is to retrieve the state & status details of the wideip.

 

Do you mind deleting 8,9,10,11 lines which is the foreach block of state & status & in line 27, remove $wipstatus,$wipstate, & see to run. Lets see if without the state & status if it runs for you.

azblaster
Nimbostratus
Nimbostratus

Thank you for the reply. Im getting similar error after making the edits

 

root@(rggslbintl01cdc)(cfg-sync Standalone)(/S1-green-P::Active)(/Common)(tmos)# run cli script gtm-config-parser > /var/tmp/gtm-config-parser-output.csv

WIP,LB-MODE,WIP-STATUS,WIP-STATE,POOL-NAME,POOL-LB,POOL-MEMBERS,POOL-FB,LASTRESORT-POOL

gtm-config-parser: script failed to complete:

can't eval proc: "script::run"

"aais-dev-dev-scp-pool" unexpected argument

  while executing

"tmsh::get_config /gtm pool $pool_name all-properties"

  (procedure "script::run" line 10)

  invoked from within

"script::run" line:1

script did not successfully complete, status:1

 

 

==============================Modified Script==============================

cli script gtm-config-parser {

proc script::run {} {

  puts "WIP,LB-MODE,WIP-STATUS,WIP-STATE,POOL-NAME,POOL-LB,POOL-MEMBERS,POOL-FB,LASTRESORT-POOL"

  foreach { obj } [tmsh::get_config gtm wideip all-properties] {

    set wipname [tmsh::get_name $obj]

    set wippools [tmsh::get_field_value $obj pools]

    set lbmode [tmsh::get_field_value $obj "pool-lb-mode"]

    set lastresort [tmsh::get_field_value $obj "last-resort-pool"]

    foreach wippool $wippools {

      set pool_name [tmsh::get_name $wippool]

      set pool_configs [tmsh::get_config /gtm pool $pool_name all-properties]

      foreach pool_config $pool_configs {

          set pool_lb [tmsh::get_field_value $pool_config "load-balancing-mode"]

          set pool_fb [tmsh::get_field_value $pool_config "fallback-mode"]

        if { [catch { set member_name [tmsh::get_field_value $pool_config "members" ]} err] } {

          set pool_member $err

        } else {

          set pool_member ""

          set member_name [tmsh::get_field_value $pool_config "members"]

          foreach member $member_name {

            append pool_member "[lindex $member 1] "

          }

        }

        puts "$wipname,$lbmode,$pool_name,$pool_lb,$pool_member,$pool_fb,$lastresort"

      }

    }

  }

}

  total-signing-status not-all-signed

}

 

 

 

root@(rggslbintl01cdc)(cfg-sync Standalone)(/S1-green-P::Active)(/Common)(tmos)# show sys ver

 

Sys::Version

Main Package

 Product   BIG-IP

 Version   13.1.3.1

 Build    0.27.4

 

azblaster
Nimbostratus
Nimbostratus

Our F5 Support Team Determined one change needed for our environment

 

When listing a gtm pool, you must specify the type of record associated with the pool, (a ,aaaa ,cname ,mx, naptr, or srv). In my lab device, my gtm pool consists of “a” records. I changed the following line in the script and it works:

 

 

Before:

set pool_configs [tmsh::get_config /gtm pool $pool_name all-properties]

 

After:

set pool_configs [tmsh::get_config /gtm pool a $pool_name all-properties]

 ,

 

I didn't realize i had put the codeshare Tested this on version: 13.1, but my actual version is 11.6.x. I'll update it.

Its my LTM's which are on 13, I think i just copy pasted my LTM code share details here as well.

 

After your yesterday's post i thought of trying it out on v13, but missed it. Glad you found the difference.

 

lishuangqing
Nimbostratus
Nimbostratus

Thanks of all :

I tested all the scriptes ,and all failed. Then i make some changes ,it's works . below is the scripts and my version.

tmsh
create cli script gtm-config-parser

puts "WIP,LB-MODE,WIP-STATUS,WIP-STATE,POOL-NAME,POOL-LB,POOL-MEMBERS,POOL-FB,LASTRESORT-POOL"
foreach { obj } [tmsh::get_config gtm wideip a all-properties] {
set wipname [tmsh::get_name $obj]
set wippools [tmsh::get_field_value $obj pools]
set lbmode [tmsh::get_field_value $obj "pool-lb-mode"]
set lastresort [tmsh::get_field_value $obj "last-resort-pool"]
foreach { status } [tmsh::get_status gtm wideip a $wipname] {
set wipstatus [tmsh::get_field_value $status "status.availability-state"]
set wipstate [tmsh::get_field_value $status "status.enabled-state"]
}
foreach wippool $wippools {
set pool_name [tmsh::get_name $wippool]
set pool_configs [tmsh::get_config /gtm pool a $pool_name all-properties]
foreach pool_config $pool_configs {
set pool_lb [tmsh::get_field_value $pool_config "load-balancing-mode"]
set pool_fb [tmsh::get_field_value $pool_config "fallback-mode"]
if { [catch { set member_name [tmsh::get_field_value $pool_config "members" ]} err] } {
set pool_member $err
} else {
set pool_member ""
set member_name [tmsh::get_field_value $pool_config "members"]
foreach member $member_name {
append pool_member "[lindex $member 1] "
}
}
puts "$wipname,$lbmode,$wipstatus,$wipstate,$pool_name,$pool_lb,$pool_member,$pool_fb,$lastresort"
}
}
}

tmsh run cli script gtm-config-parser > /var/tmp/gtm-config-parser-output.csv

root@(Spreadtrum)(cfg-sync Standalone)(Active)(/Common)(tmos)# show sys version

Sys::Version
Main Package
Product BIG-IP
Version 13.1.3.6
Build 0.0.4
Edition Point Release 6
Date Fri Jan 29 02:32:44 PST 2021

cat /var/tmp/gtm-config-parser-output.csv

Version history
Last update:
‎15-Mar-2021 07:45
Updated by:
Contributors