LTM Pool Status

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"
     }
  }
  }
}
Published Mar 10, 2015
Version 1.0
  • i get below error: /Common/pool-status.tcl:15: error: [undefined procedure: tmsh::get''field''value][tmsh::get''field''value $obj members]
  • On BIGIP v.11.5.3, script registers this error: There were warnings: /Common/pool-status.tcl:20: warning: [use curly braces to avoid double substitution][$usable]. After adding curly braces and executing script, I get this error: run cli script pool-status.tcl enter one or more pool names script did not successfully complete, status:1
  • 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"

  • Jorgle's avatar
    Jorgle
    Icon for Nimbostratus rankNimbostratus

    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