Forum Discussion

Kiyoshi_kobayas's avatar
Kiyoshi_kobayas
Icon for Nimbostratus rankNimbostratus
Nov 12, 2014

iRule load balancing redirect with a pool

I'd like to make an iRule that works as load balancing redirect with a pool.

This pool works fine when the virtual server without any iRule. But this iRule gets error at line 4 { arra set ...}. This pool has 2 members working fine. Its status is green. The Standard tcp monitor is attached to this pool.

Please let me know how solve this. Thanks.

when HTTP_REQUEST {

incr ::Counter1
if{$::Counter1 > 30000}{set ::Counter1 0}
array set AML [active_members -list [LB::server pool] ]
set cc [active_members [LB::server pool] ]

if{$cc < 1}{
    HTTP::respond 404 "All servers are not active."
}

set index [$::Counter1 % $cc]
HTTP::redirect "http://[$AML($index)::IP]"

}

6 Replies

  • shaggy's avatar
    shaggy
    Icon for Nimbostratus rankNimbostratus

    i'm intrigued by your LB-method logic - [$::Counter1 % $cc]

    i have a similar iRule in which i use LB::select in HTTP_REQUEST to select a member from a pool and compose my redirect with that result:

    if { [active_members [LB::server pool]] == 0 } {
        HTTP::respond 404 "No servers" noserver
    } else {
        set sel_mem [LB::select]
        HTTP::redirect "http://[getfield $sel_mem " " 4]:[getfield $sel_mem " " 5][HTTP::uri]"
    
  • i'm intrigued by your LB-method logic - [$::Counter1 % $cc]

    i have a similar iRule in which i use LB::select in HTTP_REQUEST to select a member from a pool and compose my redirect with that result:

    if { [active_members [LB::server pool]] == 0 } {
        HTTP::respond 404 "No servers" noserver
    } else {
        set sel_mem [LB::select]
        HTTP::redirect "http://[getfield $sel_mem " " 4]:[getfield $sel_mem " " 5][HTTP::uri]"