Forum Discussion
MK_62657
Nimbostratus
Feb 13, 2008Using F5 as a fall back host
Hello:
Is any using the F5 device itself as a fall back host? I would like to host the maintenance page on the device itself if possible instead of having another server as the fallback host?
Thanks
MK
23 Replies
- JRahm
Admin
At its most basic:when RULE_INIT { set sorry "All Servers Down" } when HTTP_REQUEST { if {[active_members myPool] == 0} { HTTP::respond 200 content $::sorry } }
If you do a little searching, I believe Hoolio posted an example with images... - hoolio
Cirrostratus
Sounds like a good feature request. To make it officially, you could open a case with F5 support.
Aaron - dennypayne
Employee
You can accomplish the same thing as a backup pool by using priority within the pool. Just set the primary members (let's say there are three) with a higher priority than the backup nodes. Then set Minimum Active Members to 1, and if all 3 of the first priority group fail, the LTM will begin to use the backup node(s).
Denny - Geoff_31301
Nimbostratus
Hoolio,
Do you have the example with images handy? Guessing there is a specific Directory to put the image in and reference it in the html page string "All Servers Down
" from the example from citizen_elah
Thanks,
Geoff - hoolio
Cirrostratus
- JRahm
Admin
Actually, I don't even use the RULE_INIT event. The entire response is an image:class sorrypage { type string filename "/var/class/unavailable.class" } rule sorrypage-rule { when HTTP_REQUEST { if {[active_members http-pool] == 0} { HTTP::respond 200 content [b64decode [lindex $::sorrypage 0]] "Content-Type" "image/png" } } } - Geoff_31301
Nimbostratus
It's starting to - however the /error directory (and the if statement for the error_condition) is now confusing me - where does that /error supposed to exist?
I think I'm getting there following all your steps:when RULE_INIT { set ::polr_html {All Servers Down} } when HTTP_REQUEST { if {[active_members myPool] == 0} if {$error_condition==1} { The error condition was true, so respond back to client from the iRule switch [string tolower [HTTP::path]] { /error/image.png { HTTP::respond 200 content [b64decode [lindex $::logo_png_class 0]] "Content-Type" "image/png"} default { HTTP::respond 200 content $::polr_html } } } - hoolio
Cirrostratus
That's close. The /error/image.png only exists in the HTML you're sending to the client from the iRule. Can you give this a try?
I added some logging so you can check the /var/log/ltm log file for debug info if it doesn't work. You can check the file on the CLI using tail -f /var/log/ltm, (ctrl+c to stop tailing the file), or in the GUI under System >> Logs >> Local Traffic. Make sure to comment out the debug statements once you're done testing.when RULE_INIT { set ::polr_html {All Servers Down} } when HTTP_REQUEST { log local0. "Received request from [IP::client_addr] to [HTTP::host][HTTP::uri], with [active_members myPool]" Check if the pool has any active members if {[active_members myPool] == 0}{ log local0. "No active members" The error condition was true, so respond back to client from the iRule switch [string tolower [HTTP::path]] { /error/image.png { log local0. "Request was for /error/image.png" HTTP::respond 200 content [b64decode [lindex $::logo_png_class 0]] "Content-Type" "image/png" } default { log local0. "Request was not for the image, so we're sending the HTML" HTTP::respond 200 content $::polr_html } } } }
Aaron - Geoff_31301
Nimbostratus
This works great! Thanks for all your help!
Geoff - Geoff_31301
Nimbostratus
One more question... can you run multiple iRules that reference "when HTTP_REQUEST" on the same Virtual Server or would you have to combine them into one iRule? I will need to have an iRule like the following example on the same VS:when HTTP_REQUEST { if {[HTTP::cookie exists "cookieName"]} { HTTP::cookie decrypt "cookieName" "passphrase" } } when HTTP_RESPONSE { if {[HTTP::cookie exists "cookieName"]} { HTTP::cookie encrypt "cookieName" "passphrase" } }
My guess is I would have to add in an elseif branch to the "if {[active_members myPool] == 0}{" to incorporate decrypting existing cookies within an HTTP Request.
Geoff
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
