on 10-Mar-2015 12:09
Problem this snippet solves:
Here's a way to display the status of your pool members using a custom tmsh script.
Code :
create script pool-status.tcl { proc script::run {} { set pool_names "" if { $tmsh::argc == 1} { puts "enter one or more pool names" exit 1 } set pool_names [lrange $tmsh::argv 1 end] foreach pn $pool_names { set total 0 set usable 0 foreach obj [tmsh::get_status /ltm pool $pn detail] { foreach member [tmsh::get''field''value $obj members] { incr total if { [tmsh::get''field''value $member pool-member.status.availability-state] == "available" && [tmsh::get''field''value $member pool-member.status.enabled-state] == "enabled" } { incr usable } } } if { $usable > 0 && [expr 2 * $usable] >= $total } { puts "up: $pn" } else { puts "dn: $pn" } } } }
I finally got this working.
In addition to replacing the '' with underscore (i.e.
get''field''value
becomes get_field_value
), delete "pool-member" on lines 15 and 16 and enclose in quotes.
(i.e.) Change
pool-member.status.availability-state
to "status.availability-state"
and
pool-member.status.enabled-state
to "status.enabled-state"
can not find the field name of "pool-member.status.availability-state"
# run cli script pool-status pool-100-208
pool-status: script failed to complete:
can't eval proc: "script::run"
field not present: "pool-member.status.availability-state"
while executing
"tmsh::get_field_value $member pool-member.status.availability-state"
(procedure "script::run" line 14)
invoked from within
"script::run" line:1
script did not successfully complete, status:1