Forum Discussion
Michaelyang
Mar 17, 2023Cirrostratus
Problem about Export imformation to Excel
Hello, I have made some changes by referring to the following URL: https://community.f5.com/t5/codeshare/export-virtual-server-configuration-in-csv-tmsh-cli-script/ta-p/281983 This is my script : ...
- Mar 21, 2023
i modify and optimize the tmsh script, it reports pool_name, pool_members_list(members is addr:port or addr.port), the disadvantage is when use [tmsh::get_status /ltm virtual $VS_name], it will lose the route domain-id, such as %1,%2 and so on.
script support AS3 and Common or other partition
cli script virtual-details { proc script::init {} { } proc check_vs {partition {partition_folder ""}} { if { $partition_folder eq "" } { tmsh::cd /$partition } else { tmsh::cd /${partition}/${partition_folder} } foreach { obj } [tmsh::get_config ltm virtual all-properties] { set VS_name [tmsh::get_name $obj] set VSname "" foreach { VSip } [tmsh::get_status /ltm virtual $VS_name] { set VSIIP [tmsh::get_field_value $VSip "destination"] } set poolname [tmsh::get_field_value $obj "pool"] set profiles [tmsh::get_field_value $obj "ip-protocol"] set persist [lindex [lindex [tmsh::get_field_value $obj "persist"] 0] 1] if { $poolname != "none" } { set poolconfig [tmsh::get_config /ltm pool $poolname all-properties] foreach { poolinfo } $poolconfig { set pool_lb [tmsh::get_field_value $poolinfo "load-balancing-mode"] set pool_monitor [tmsh::get_field_value $poolinfo "monitor"] if { [catch { set member_name [tmsh::get_field_value $poolinfo "members" ]} err] } { set pool_member $err puts "$VS_name,$VSIIP,$profiles,$pool_lb,$persist,$poolname,$addr,$port,$pool_monitor" } else { set pool_member {} foreach mem [tmsh::get_status /ltm pool $poolname members] { foreach poolmember [tmsh::get_field_value $mem "members"] { set addr [tmsh::get_field_value $poolmember "addr"] set port [tmsh::get_field_value $poolmember "port"] if { $addr contains "." } { lappend pool_member "$addr:$port" } else { lappend pool_member "$addr.$port" } } } # puts "--------" # puts "$pool_member" # puts "$VS_name,$VSIIP,$profiles,$pool_lb,$persist,$poolname,$pool_member,$pool_monitor" } } puts "$VS_name,$VSIIP,$profiles,$pool_lb,$persist,$poolname,$pool_member,$pool_monitor" } else { puts "$VS_name,$VSIIP,$profiles,none,$persist,$poolname,none,none" } } } proc script::run {} { puts "VServer_name,VServer_IP:Port,Protocol,Load_Balance,Persist_Method,PooL_Name,PooL_Members,Monitor_Protocol" foreach all_partitions [tmsh::get_config auth partition] { # set partition "[lindex [split $all_partitions " "] 2]" set partition "[tmsh::get_name ${all_partitions}]" tmsh::cd /$partition if { [tmsh::get_config /sys folder] eq "" } { check_vs $partition } else { foreach { partition_folder_config } [tmsh::get_config /sys folder] { set partition_folder_name [tmsh::get_name ${partition_folder_config}] if { $partition eq "Common" } { check_vs $partition break } else { check_vs ${partition} ${partition_folder_name} } } } } } proc script::help {} { } proc script::tabc {} { } }
Michaelyang
Mar 22, 2023Cirrostratus
Hi xuwen ,
Thanks for your help.
I have since tried again and the following script runs the way I want it to.
modify script virtual-details {
proc script::run {} {
puts "VServer_name,VServer_IP:Port,Protocol,Load_Balance,Sticky_Method,AP_Server_Name,AP_Server_IP:Port,Monitor_Protocol"
foreach all_partitions [tmsh::get_config auth partition] {
set partition "[lindex [split $all_partitions " "] 2]"
tmsh::cd /$partition
foreach { obj } [tmsh::get_config ltm virtual all-properties] {
set VS_name [tmsh::get_name $obj]
set VSname ""
foreach { VSip } [tmsh::get_status /ltm virtual $VS_name] {
set VSIIP [tmsh::get_field_value $VSip "destination"]
}
set poolname [tmsh::get_field_value $obj "pool"]
set profiles [tmsh::get_field_value $obj "ip-protocol"]
set persist [lindex [lindex [tmsh::get_field_value $obj "persist"] 0] 1]
if { $poolname != "none" }{
set poolconfig [tmsh::get_config /ltm pool $poolname all-properties]
set poolconfig3 [tmsh::get_config /ltm pool $poolname]
set poolconfig2 [tmsh::get_status /ltm pool $poolname members]
foreach poolinfo $poolconfig poolinfo2 $poolconfig2 {
set pool_lb [tmsh::get_field_value $poolinfo "load-balancing-mode"]
set pool_monitor [tmsh::get_field_value $poolinfo "monitor"]
if { [catch { set member_name [tmsh::get_field_value $poolinfo "members" ]} err] } {
set pool_member $err
puts "$VS_name,$VSIIP,$profiles,$pool_lb,$persist,$poolname,$pool_member,$pool_monitor"
} else {
set pool_member ""
set member_name [tmsh::get_field_value $poolinfo2 "members" ]
foreach member $member_name {
append pool_member " ([lindex [lindex $member 2] 1]:[lindex [lindex $member 2] 39]) "
}
puts "$VS_name,$VSIIP,$profiles,$pool_lb,$persist,$poolname,$pool_member,$pool_monitor"
}
}
} else {
puts "$VS_name,$VSIIP,$profiles,none,$persist,$poolname,none,none,none,none"
}
}
}
}
}
Thanks for letting me learn a few things
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects