Disable Interface if Pool Member Availability Drops Below Threshold

Problem this snippet solves:

This iCall script can be used to disable an interface (int 1.3 in this case) if the member availability of a pool drops below a certain threshold (70% in this example.)

How to use this snippet:

Implementation Details

This iCall script requires v11.4 or higher. The script is called by a periodic handler, but could be converted to a triggered handler with some custom work in /config/user_alert.conf on the pool members.

Code :

## Script ##
sys icall script poolCheck.v1.0.0 {
    app-service none
    definition {
        set pn "/Common/pool4"
        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 "Not enough pool members in pool $pn, interface 1.3 disabled"
            tmsh::modify /net interface 1.3 disabled
        } else {
            tmsh::log "Enough pool members in pool $pn,  interface 1.3 enabled"
            tmsh::modify /net interface 1.3 enabled
        }
    }
    description none
    events none
}
## Handler ##
sys icall handler periodic poolCheck.v1.0.0 {
    first-occurrence 2014-09-16:11:00:00
    interval 60
    script poolCheck.v1.0.0
}
Published Mar 09, 2015
Version 1.0

Was this article helpful?

5 Comments

  • Hi Jason Can I use this example to track pool member availability and based on that I would trigger tmsh command to disable specific member of another pool? Please refer to my query on i-call script.
  • How can you add more than one pool to this script? Currently I am creating a separate script for each pool.

     

  • For multiple pools this works:

    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)  
    
  • For multiple pools, you need to add additional logic to determine which pool or how many of the pools impacted would result in the need to shut down the interface. As is, if one pool is below the threshold but the next is not, you'll just end up toggling the interface.

  • Hi JRahm,

    I want to run a script just if interface 1.2 UP.

    how can I do it?

    for example;

    exec bash -c "ssh user@192.168.1.1 'ip link set ens0 UP'"

    thanks