CodeShare
Have some code. Share some code.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner
xuwen
MVP
MVP
Code is community submitted, community supported, and recognized as ‘Use At Your Own Risk’.

Short Description

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

Problem solved by this Code Snippet

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

How to use this Code Snippet

 

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

 

Code Snippet Meta Information

  1. Version: tested with tmos V12.1.6, V14.1.5, V16.1.2
  2. Coding Language: tcl/tmsh

Full Code Snippet

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 {} {
}
}

 

Comments
xuwen
MVP
MVP

If pool members are IP, the format is vs-name, vs-destination, status, state
If pool members are domain names, the format is server-name, status, state

xuwen_0-1697344441935.png

xuwen_1-1697344461343.png

 

Version history
Last update:
‎28-Oct-2023 21:13
Updated by:
Contributors