Forum Discussion

RiverFish's avatar
RiverFish
Icon for Altostratus rankAltostratus
Jan 06, 2017

Modify script to allow more than one variable (pool).

This iCall script works great, but you can only add one variable (one pool name). Therefore, I have to create a separate script for each pool I want to check, which is not desirable. I need help finding the best way to modify the script so that multiple pool names can be added. That way I can have just the one script that checks multiple pools.

admin@(f5-device-001)(cfg-sync Standalone)(/S1-green-P:Active)(/Common)(tmos) list sys icall script check-members-script 
sys icall script check-members-script {
    app-service none
    definition {
        set pn "/Common/pool-fooapp.example.com"
        set total 0
        set usable 0
                foreach obj [tmsh::get_status /ltm pool $pn detail] {
                    puts $obj
                    foreach member [tmsh::get_field_value $obj members] {
                        puts $member
                        incr total
                        if { [tmsh::get_field_value $member status.availability-state] == "available" && \
                            [tmsh::get_field_value $member status.enabled-state] == "enabled" } {
                                incr usable
                       }
                 }
            }
            if { [expr $usable.0 / $total] < 0.7 } {
                tmsh::log "Available pool member threshold reached for $pn"
       }
    }
    description none
    events none
}
admin@(f5-device-001)(cfg-sync Standalone)(/S1-green-P:Active)(/Common)(tmos)  
  • This appears to be working well:

    admin@(f5-device-001)(cfg-sync Standalone)(/S1-green-P:Active)(/Common)(tmos) list sys icall script check-members-script 
    sys icall script check-members-script {
        app-service none
        definition {
            set pool_names "/Common/pool-fooapp1.example.com /Common/pool-fooapp2.example.com /Common/pool-fooapp3.example.com"
            foreach pn $pool_names {
            set total 0
            set usable 0
                    foreach obj [tmsh::get_status /ltm pool $pn detail] {
                        puts $obj
                        foreach member [tmsh::get_field_value $obj members] {
                            puts $member
                            incr total
                            if { [tmsh::get_field_value $member status.availability-state] == "available" && \
                                [tmsh::get_field_value $member status.enabled-state] == "enabled" } {
                                    incr usable
                           }
                     }
                }
                if { [expr $usable.0 / $total] < 0.7 } {
                    tmsh::log "Available pool member threshold reached for $pn"
            }
          }  
        }
        description none
        events none
    }
    admin@(f5-device-001)(cfg-sync Standalone)(/S1-green-P:Active)(/Common)(tmos)