Forum Discussion

Jamesy_105825's avatar
Jamesy_105825
Icon for Nimbostratus rankNimbostratus
Dec 23, 2010

redirect and sorry server, new to irules

I am trying to write an iRule to redirect to a sorry server where another redirect rule exists. I'm new to irules and I can't seem to wrap my head around the logical flow.

 

 

Essentially, I want it to perform the initial redirect, but then redirect to a sorry pool if none are available in that pool. Can I do a nested if statement inside the first one?

 

 

 

 

Here are some examples of the current redirects (these are both separate iRules):

 

 

 

-=-=-=-=-=-=-=-=-=-=-=-

 

when HTTP_REQUEST {

 

if { [HTTP::uri] starts_with "/login-test" } {

 

pool Pool1

 

}

 

}

 

-=-=-=-=-=-=-=-=-=-=-=-

 

-=-=-=-=-=-=-=-=-=-=-=-

 

when HTTP_REQUEST {

 

if { ( [HTTP::host] contains "hostname.domain1" ) or ( [HTTP::host] contains "hostname.domain2" ) } {

 

pool Pool2

 

}

 

}

 

-=-=-=-=-=-=-=-=-=-=-=-

 

 

Can someone help me understand what I need to do?

2 Replies

  • Hi Jamesy,

     

    The examples you presented are not redirects, because redirects, specifically HTTP redirects is forcing the client's browser to go to a new link or URL. I think what you are refering to is send then the HTTP request to a specific pool based on certain conditions.

     

     

    So let's start with following pseudo code

     

     

    IF POOL A is unavailable {

     

    then go to Pool B

     

    ELSE

     

    Go to POOL A

     

     

    Now there is a command called active_members (http://devcentral.f5.com/wiki/default.aspx/iRules/active_members.html)

     

    When executed this command returns the number of members in a pool So if all the servers in a pool is unavailable then it should return a zero.

     

     

    Using one of your examples

     

     

    
    when HTTP_REQUEST {
      if { [active_members pool1] > 0 } {
          if { [HTTP::uri] starts_with "/login-test" } {
             pool Pool1
              }
      } else {
            pool sorry_page_pool
      }
    }
    

     

     

    I hope this helps

     

     

    Bhattman

     

  • If you're switching pools or pool members based on URI, make sure to add a OneConnect profile to the virtual server. If you're using SNAT set the OneConnect source mask to 0.0.0.0. If you're not using SNAT, set the source mask to 255.255.255.255. For more info check this wiki page:

    http://devcentral.f5.com/wiki/default.aspx/AdvDesignConfig/oneconnect.html

    You could also adapt Bhattman's example to cover the edge cases more clearly:

    when HTTP_REQUEST {
       if { [active_members pool1] == 0 && [HTTP::uri] starts_with "/login-test"} {
          pool sorry_page_pool
       } else {
          pool Pool1
       }
    }
    

    Aaron