Forum Discussion
tmsh scripting pool member status
Guys,
(I should have posted this here originally & not Design & Config, apologies)
The customer has two sites A and B, a gtm pool, with a member at each site. For reasons of their own the customer wants only site A active, with a manual failover to B if required (no discussion here please, it's what the customeer wants, so that's what they're getting).
To assist I thought I'd provide a 'simple' tmsh script (V11.2.1) which toggled the Active/Passive members - and then place in a bash wrapper
e.g. Run the script, if Site A gtm pool member is enabled, disable it and Activate Site B gtm pool member, if Site B is Active when run, disable it and enable Site A.
I've read the tmsh wikki (get_status, get_config, get_field_names etc), viewed and tried the LTM poool status example code, replaced code such as:
foreach member [tmsh::get''field''value $obj members] (which balked the interpreter)
with
foreach member [tmsh::get_field_value $obj members]
and /ltm with /gtm
resulting in:
proc script::run {} {
set pool_names "sp.test.lan.pool"
foreach pn $pool_names {
set total 0
set usable 0
foreach obj [tmsh::get_status /gtm 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"
}
}
}
but results in:
pool-status.tcl: 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 11)
invoked from within
"script::run" line:1
script did not successfully complete, status:1
Given the time this has cost me so far just trying to get the status, I not even thinking about /modify script :(
Whilst I'm no Dennis Ritchie, I've used a few languages and script engines but this is killing me ... am I missing something?
Could anyone tell me if what I'm trying to do is viable or am I just wasting my time?
Any assistance would be greatly appreciated.
1 Reply
- rstanback
Nimbostratus
I have not tested this script with gtm changes but it should work. This scrip will list the ltm pools and member status. If you change the first in the script::run to
set objs [tmsh::get_status /gtm pool members] it should work.
modify script show-pools.tcl {
proc script::init { } {
set ::field_fmt "%-25s %s"
}
proc script::run { } {
set objs [tmsh::get_status /ltm pool members]
set idx 0
set total [llength $objs]
while { $idx < $total } {
set obj [lindex $objs $idx]
print_object obj
puts ""
incr idx;
}
}
proc print_fields { objVar } {
upvar $objVar obj
set fdx 0
set fields [tmsh::get_field_names value $obj]
set field_count [llength $fields]
while { $fdx < $field_count } {
set field [lindex $fields $fdx]
switch $field {
"pool.status.availability-state" -
"pool.status.enabled-state" -
"pool-member.status.availability-state" -
"members" { puts -nonewline "[tmsh::get_field_value $obj $field] " }
default {}
}
incr fdx
}
}
proc print_object { objVar } {
upvar $objVar obj
puts -nonewline "[tmsh::get_type $obj] [tmsh::get_name $obj] "
name/value pairs
print_fields obj
nested objects
set fdx 0
set fields [tmsh::get_field_names nested $obj]
set count [llength $fields]
while { $fdx < $count } {
set field [lindex $fields $fdx]
set nested_objects [tmsh::get_field_value $obj $field]
set ndx 0
set n_count [llength $nested_objects]
while { $ndx < $n_count } {
set nobj [lindex $nested_objects $ndx]
print_object nobj
incr ndx
}
if {$n_count == 0 } {
puts -nonewline [format $::field_fmt $field "none"]
}
incr fdx
}
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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