Forum Discussion

Kraig_52305's avatar
Kraig_52305
Icon for Nimbostratus rankNimbostratus
Nov 14, 2012

Simple Nested iRule

I want to combine two actions in this iRule. First I want to see if any members are up and if they are then load balance to pools depending on source IP. If all pool members are down I want to redirect to a sorry page.

 

I don't do a lot of iRules so I am wondering if what I have written makes sense or if there is a better way to accomplish what I have done.

 

when CLIENT_ACCEPTED {

 

log local0. "[IP::client_addr]:[TCP::client_port]: Received connection with active members: [active_members [LB::server pool]]"

 

if {[active_members [LB::server pool]]}{

 

SSL::disable

 

HTTP::disable

 

 

if {[class match [IP::client_addr] equals crawl_ip]} {

 

pool pool1_crawl

 

} else {

 

pool pool2_non_crawl

 

}

 

 

log local0. "[IP::client_addr]:[TCP::client_port]: Members available"

 

}

 

}

 

when HTTP_REQUEST {

 

HTTP::redirect "http://mysite.com/sorry_page.html"

 

TCP::close

 

log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting request"

 

}

 

 

Thanks!

 

Kraig

 

 

 

  • uni's avatar
    uni
    Icon for Altostratus rankAltostratus
    I would do it like this (untested). I would not bother with the CLIENT_ACCEPT event:

    when HTTP_REQUEST {
    
          if { [active_members [LB::server pool]] < 1 } {
              HTTP::redirect "http://mysite.com/sorry_page.html"
              return
          }
    
          if {[class match [IP::client_addr] equals crawl_ip]} {
              pool pool1_crawl
          } else {
              pool pool2_non_crawl
          }
    }