tmsh::get_field_value

Description

Retrieves the value of the field name. The $obj argument must be an object that was returned by either of the following Tcl commands:

The behavior of this command depends on whether field name is present in $obj and a Tcl variable is present in the command.
  • If field name is present in $obj, and a Tcl variable is present, the Tcl variable is set to the value of field name and the command returns 1.

  • If field name is not present in $obj, and a Tcl variable is present, the command returns 0 (zero).

  • If field name is present in $obj, and a Tcl variable is not present, the command returns the field value.

  • If field name is not present in $obj, and a Tcl variable is not present, the command raises an error that causes the script to stop. You can use the Tcl ‘

    catch
    
    ‘ command to recognize the error and continue to run the script.

Syntax

tmsh::get_field_value $obj [field name] [Tcl variable]

If the field is a set of nested objects, the Tcl object that the system returns is a list of objects, where each of the objects can contain fields. Each of the objects can be passed to the Tcl command tmsh::get_field_value. If the field is not a nested object the system returns a single Tcl string object.

Examples

proc get_stats { resultsArray } {

   upvar $resultsArray results

   set idx 0
   set objs [tmsh::get_status ltm pool $::pool_ids raw]
   set count [llength $objs]

   while { $idx < $count } {

       set obj [lindex $objs $idx]
       set pool [tmsh::get_name $obj]

       lappend results($pool) bps-in
       lappend results($pool) \
           [tmsh::get_field_value $obj "serverside.bits-in"]

       lappend results($pool) bps-out
       lappend results($pool) \
           [tmsh::get_field_value $obj "serverside.bits-out"]

       lappend results($pool) cps
       lappend results($pool) \
           [tmsh::get_field_value $obj "serverside.tot-conns"]

       incr idx
   }
}

Or same as the above, slightly more compact
proc get_stats { resultsArray } {
    upvar $resultsArray results

    foreach { obj } [tmsh::get_status /ltm pool $::pool_ids raw] {
        set pool [tmsh::get_name $obj]
        lappend results($pool) \
            bps-in [tmsh::get_field_value $obj "serverside.bits-in"] \
            bps-out [tmsh::get_field_value $obj "serverside.bits-out"] \
            cps [tmsh::get_field_value $obj "serverside.tot-conns"]
    }
}