14-Oct-2023 21:32 - edited 28-Oct-2023 21:13
Collect all types of wideips and its pools members status(support AS3 wideip) using tmsh script,You can use it to save the final data as CSV
When using icontrolrest api to collect all pool members ip and port and status from WideIPs, if there are over 2000 wideIPs, there will often be issues with timeout or high control level CPU. Using tmsh script results in low performance loss and decent speed, with 1800+ wideIPs taking 3 minutes to generate CSV
Utilized tcl compile_json function converts the format of the array in pools into JSON string format, and also performs special processing on the characters in JSON in the CSV file
In the future, using Python, import csv,json, and json. loads() can easily convert the pools in CSV files into list dictionary format, making it convenient for you to convert CSV format into the format you want to store, such as JSON
load sys config merge from-terminal
Copy and paste the code, then Press CTRL-D to submit
tmsh run cli script wideip-networkmap.tcl > /var/tmp/gtm-wideip.csv
Tmsh script code in txt of zip compressed package
cli script wideip-networkmap.tcl {
proc script::init {} {
}
proc compile_json {spec data} {
while {[llength $spec]} {
set type [lindex $spec 0]
set spec [lrange $spec 1 end]
switch -- $type {
dict {
lappend spec * string
set json {}
foreach {key val} $data {
foreach {keymatch valtype} $spec {
if {[string match $keymatch $key]} {
lappend json [subst {"$key":[
compile_json $valtype $val]}]
break
}
}
}
return "{[join $json ,]}"
}
list {
if {![llength $spec]} {
set spec string
} else {
set spec [lindex $spec 0]
}
set json {}
foreach {val} $data {
lappend json [compile_json $spec $val]
}
return "\[[join $json ,]\]"
}
string {
if {[string is double -strict $data]} {
return $data
} else {
return "\"$data\""
}
}
default {error "Invalid type"}
}
}
}
proc script::run {} {
#detail tmsh script code in wideip-tmsh-script.txt
}
proc script::help {} {
}
proc script::tabc {} {
}
}