Forum Discussion

EBL_27513's avatar
EBL_27513
Icon for Nimbostratus rankNimbostratus
Apr 13, 2015

iRule - Is it possible to select a different pool and do an http redirect without infinite loop?

Hi all,

 

I'm a relative amateur when it comes to crafting iRules, so thought I'd come to the experts and plead for any suggestions you'd be kind enough to offer!

 

I've been asked to create an iRule to redirect traffic to a maintenance page when all the servers in a virtual's normal pool are down (redirecting to the same virtual, but using a different pool). Because this virtual is used for different purposes (using subfolders), I also need to check whether the URI contains a specific path, and then redirect the traffic to a specific page within a subfolder in the maintenance page pool:

 

Basically: - Set up a check to detect whether all servers in a pool are down, and whether the incoming uri request contains a specific path - If all servers are down, use a different pool (which contains the maintenance page) - Because the maintenance page is not at the root of the servers, redirect all traffic to a page within a subfolder in the new pool

 

What I've come up with that doesn't quite work has been the following:

 

when LB_FAILED {
      persist none
      LB::reselect

if { [URI::decode [string tolower [HTTP::uri]]] starts_with "/ohrcc/pages/client" } {
    log local0. "iRule:client-maintenance - routing to maintenance pool"
    use pool client-maint

    HTTP::redirect "https://client.accenture.com/test/maintenance-page.htm" - Doesn't work
    HTTP::fallback "https://client.accenture.com/test/maintenance-page.htm" - Doesn't work
     HTTP::respond 302 Location "https://client.foo.com/test/LMBuyerPortalfallbackEn.htm"
  } 
    elseif { [URI::decode [string tolower [HTTP::uri]]] starts_with "/placeholder-check-for-future-maintenance-pages"  } {
    use pool future-maint
  } 
    else {
    use pool normal-pool
    log local0. "iRule:client-maintenance - routing to normal pool"
  }

}

From the logging, I do see that my conditional statement works (to detect the specific URI), but I can't seem to get the redirect to work at all. I tried http::redirect, http::fallback and http::respond302, with no luck. I believe the http::redirect results in an infinite loop (Browser hits the virtual, all servers are down, iRule re-selects maintenance pool, and then redirects to another page under the same virtual - which hits the iRule condition again...)

 

My problem is this redirect. If the maintenance page was at the root of the maintenance pool, this code works: when LB_FAILED { persist none LB::reselect pool client-maint }

 

Any suggestions? Thanks very much in advance!

 

1 Reply

  • Hi, you might be using an improper event for this purpose.

    I made some changes and it might work.

    Hope it helps you. []
      when HTTP_REQUEST {
        if { [active_members [LB::server pool]] < 1 } {
            if { [string tolower [URI::decode [HTTP::uri]]] starts_with "/ohrcc/pages/client" } {
                log local0. "iRule:client-maintenance - routing to maintenance pool"
                Use this
                use pool client-maint
                Or
                HTTP::respond 302 Location "https://client.accenture.com/test/maintenance-page.htm"
            }
            elseif { [string tolower [URI::decode [HTTP::uri]]] starts_with "/placeholder-check-for-future-maintenance-pages" } {
                log local0. "iRule:future-maintenance - routing to maintenance pool"
                use pool future-maint
            } else {
                log local0. "iRule:Lantmannen-maintenance - routing to normal pool"
                use pool normal-pool
            }
        }
    }
    
    when LB_FAILED {
        persist none
        LB::reselect
    }