Problem this snippet solves:
This example shows how to display a list of virtual servers that are currently marked as down.
Code :
modify script virtual_stat.tcl {
proc script::init { } {
}
proc getPartition { partition } {
puts $partition
flush stdout
return [gets stdin]
#Choose the partition you want to be tested
}
proc script::run { } {
set up ""
set down ""
set total 0
set out 0
set part [getPartition "Enter the partition you want to be tested"]
tmsh::cd \/$part
foreach { virtual } [tmsh::get_status /ltm virtual] {
set total [expr { $total + 1 }]
if { "available" ne [tmsh::get_field_value \
$virtual ".status.availability-state"] } {
set out [expr { $out + 1 }]
append down " " [tmsh::get_name $virtual] "\n"
}
}
set result "\n\n"
append result $out " pools are down among " $total "\n Inactive Virtuals:\n\n"
if { [string length $down] == 0 } {
append result " none\n"
} else {
append result $down
}
tmsh::display $result
}
proc script::help { } {
tmsh::add_help "display the list of virtual servers that are down"
}
proc script::tabc { } {
# if this function does nothing then tmsh will (visual) beep
}
}