Forum Discussion
Problem about Export imformation to Excel
- 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 {} { } }
tmsh::get_config ltm pool equals tmsh command "list ltm pool xxx", so some special protocol ports will become http, https, and so on.
"show ltm pool xxx field-fmt members" will return poolmember addr and port
tmsh script command is
proc script::run {} {
set poolname "pool_test"
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"]
puts "poolmember name is [lindex $poolmember 1]"
puts "poolmember addr is $addr"
puts "poolmember port is $port"
puts "---------"
}
}
}
run cli script output is:
root@(f5)(cfg-sync Standalone)(Active)(/Common)(tmos)# run cli script extract_poolmembers
poolmember name is 192.168.200.3:80
poolmember addr is 192.168.200.3
poolmember port is 80
---------
poolmember name is app_server1:80
poolmember addr is 192.168.200.1
poolmember port is 80
---------
poolmember name is app_server2:80
poolmember addr is 192.168.200.2
poolmember port is 80
---------
There are limitations to using tmsh script:
1. if your ltm pool is create by AS3, you need to cd /partition/foldername cause not easy to extract information
2. use python api is easy to extract information
so the best easy way is to use python f5 api to extract ltm pool members ip and port attribute
Hi xuwen ,
Thanks for your help.
I have modified the script as you suggested and it shows :80 :443 without any problems, but it only shows the last setting, my script is below.
modify script virtual-details {
proc script::run {} {
puts "VServer_name,VServer_IP:Port,Protocol,Load_Balance,Sticky_Method,AP_Server_Name,AP_Server_IP,AP_Server_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 poolconfig2 [tmsh::get_config /ltm pool $poolname]
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,$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"]
}
}
puts "$VS_name,$VSIIP,$profiles,$pool_lb,$persist,$poolname,$addr,$port,$pool_monitor"
}
}
} else {
puts "$VS_name,$VSIIP,$profiles,none,$persist,$poolname,none,none,none,none"
}
}
}
}
Any help is appreciate.
Recent Discussions
Related Content
* 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