Forum Discussion

Martin_Kaiser_1's avatar
Martin_Kaiser_1
Icon for Nimbostratus rankNimbostratus
Oct 20, 2005

Dynamic redirect to fallback host

Hi Everybody,

 

 

I'm new to BigIP V9 and iRules, so I need your assistance with writing an iRule for a BigIP Loadbalancer that balances several webserver pools.

 

I have to build a rule that allows redirection of incoming http requests to a maintenance page in case a certain pool is not available. Because the redirection must be dynamic (dependent on the requested URI), we cannot use the standard fallback host function. There is already an iRule that is bound to the virtual server. This one checks for the requested URI and chooses the appropriate pool of webservers.

 

The rule looks like that:

 

 

---BEGIN---

 

when HTTP_REQUEST {

 

if { [HTTP::uri] starts_with "/abc/" } {

 

pool pool1

 

}

 

elseif { [HTTP::uri] starts_with "/def/" } {

 

pool pool2

 

}

 

else {

 

pool default_pool

 

}

 

}

 

---END---

 

 

This is so far the only rule that is bound to the VIP.

 

I thought about adding a statement like that:

 

 

---BEGIN---

 

when LB_FAILED {

 

if { [HTTP::uri] contains "/abc/" } {

 

HTTP::redirect https://some.maintenancesite.com/abc

 

}

 

elseif { [HTTP::uri] contains "/def/" } {

 

HTTP::redirect https://some.maintenancesite.com/def

 

}

 

else {

 

HTTP::redirect https://some.maintenancesite.com/

 

}

 

}

 

---END---

 

 

Will this work if it is appended to the end of the original rule or will I have to build another rule and bind it to the same VS as second one?

 

Or maybe, is there any other way to achieve the wanted result?

 

 

Any help is greatly appreciated!

 

Thanks in advance!

 

 

Regards,

 

Martin

4 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    You should be able to tac that code to the end of the existing rule without a problem.

     

     

    And as far as the code you're using, there isn't really another way of achieving the same thing, really. In BIG-IP v9.2 the LB::reselect command was introduced, which allows you to attempt a different server with the original (or re-written) request, but if you're simply looking to forward to a default maintenance page, it would function basically the same as a redirect, except it would look like only one request to the client.

     

     

    -Colin
  • Thanks!

    Is it possible to refer to pool that has "failed", for example by passing it to the function LB_FAILED like that:

    when LB_FAILED pool1 {
    HTTP::redirect http://some.maintenancesite.com/

    Or will I have to query the selected pool in an if-statement within the LB_FAILED block?

    Which function would be appropriate for that? I couldn't find any POOL:: functions in the manual? Do they exist?

    Rgds,

    Martin

  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    You'll want to look at the LB::server command. It will return information about the load-balancing decision (eg: the pool and member of the pick). You can specifically get just the pool with: [LB::server pool].