Export GTM/DNS Configuration in CSV - tmsh cli script
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