DevCentral > Weblogs > Jason Rahm - Jason's Blog

posted on Tuesday, May 12, 2009 11:18 AM

It's not an uncommon problem trying to figure out where to plant that sorry page in the event your farm is down.  It's also not an uncommon solution to just use your BIG-IP to issue a text-only HTTP::respond.  It works, but it's not, how do you say, visually appealing?  You want to say sorry and mean it.  With pictures.  If you take a stroll through the iRules codeshare, you'll notice several solutions to this problem.  All of them work, with a variety of msorryethods, but user kirkbauer's entry takes it to another level.  Kirk's sorry page irule generator (written in perl) takes all the guess work out of the process for you.  Dump the perl script in /var/tmp, give execute permissions to root, and off you go.  Here's a sample configuration, just taking Google's main page:

[root@ltm01:Active] mibs # /var/tmp/sorrygen.pl

Welcome to the F5 Sorry Page iRule Generator

This script will create a sorry page iRule based on an arbitrary web page.

This script can download the sorry page from the specified URL (you may need to use an IP address instead of a hostname if you don't have DNS set up) or it can convert a page (and all includes) already in a local directory.

Enter the prefix pathname (such as 'sorrypage') for a directory that doesn't exist in your app (do not include any slashes):
sorrypage

Please provide the URL (starting with http://) or local directory with the sorry page:
http://www.google.com
Downloading http://www.google.com/
Downloading http://www.google.com//intl/en_ALL/images/logo.gif
Checking included object /index.html: is text.
Checking included object /sorrypage/intl/en_ALL/images/logo.gif: is an image.

Done.
Completed files can be found in /tmp/irulegen-18583/output/.

Do you want to deploy this iRule and associated data groups now?[Y/n]:
Y

The following partitions were found: Common ops1 ops2

Which partition do you want to install this in?:
ops2

** Backing up /config/bigip.conf as /config/bigip.conf.bak
Saving current config.
/config/bigip.conf was renamed to /config/bigip.conf.bak (492 lines).
/config/bigip_local.conf was renamed to /config/bigip_local.conf.bak (3 lines).
/config/bigip_sys.conf was renamed to /config/bigip_sys.conf.bak (32 lines).
Modified bigip.conf
Placed /var/class/sorrypage.index.html.class
Placed /var/class/sorrypage.intl.en_ALL.images.logo.gif.class
Loading new config.
Reading configuration from /defaults/config_base.conf.
Reading configuration from /config/bigip_base.conf.
Reading configuration from /config/bigip_sys.conf.
Reading configuration from /usr/bin/monitors/builtins/base_monitors.conf.
Reading configuration from /config/profile_base.conf.
Reading configuration from /config/daemon.conf.
Reading configuration from /config/bigip.conf.
Reading configuration from /config/bigip_local.conf.
Loading the configuration ...

Rule should be ready to go -- just apply the iRule 'sorry_page_sorrypage' to one or more virtual servers.

Pretty easy, right?  I allowed the script to deploy--here's the iRule:

Sorry Page iRule

 

rule sorry_page_sorrypage {
   # Auto-generated by sorry_irule.pl
  when HTTP_REQUEST {
    #
    # Service requests for files (URIs) from the maintenance page
    # Note that we always service these pages, even if the http_pool is up
    #
    set uri [HTTP::uri]
    if { $uri equals "/sorrypage" } {
       HTTP::respond 301 "Location" "/sorrypage/"
       return
    }
    if { $uri starts_with "/sorrypage/" } {
       # trim off the maintenance prefix
       set uri [string range $uri 10 end]

       # Return the requested page
       switch $uri {
         "/"              -
         "/index.html"   { HTTP::respond 200 content [lindex $::sorrypage_index_html 0] "Content-Type" "text/html" }
         "/intl/en_ALL/images/logo.gif"   { HTTP::respond 200 content \
		 [b64decode [lindex $::sorrypage_intl_en_ALL_images_logo_gif 0]] "Content-Type" "image/gif" }
         default         { HTTP::respond 404 }
       }
       return
    }

    #
    # If the http_pool is down, redirect to the maintenance page
    #
    if { [active_members [LB::server pool]] < 1 } {
      HTTP::redirect "/sorrypage/index.html"
      return
    }
  }
   partition ops2
}

 

 

Definitely the way to go if you plan on hosting your sorry page on the BIG-IPClick here for the code.

 

Follow me on Twitter Follow me on LinkedIn Follow me on Facebook Add to Technorati Favorites

 


Feedback

5/28/2009 2:50 AM
Gravatar We had some issues with the irule that was automatically generated. We are ran it on v10.

The issue we had was instead of displaying the sorry page it instead was displaying the text "sorrypage_index_html".

We resolved the issue by using the "class element 0" function instead of "lindex $::". This is discussed in the thread below.

http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=2309

chris achis
7/7/2009 3:55 AM
Gravatar Hi. This is brilliant :) I couldnt quite get it to work with images referenced in the css so one of our coders cleaned the script up a bit. email me if that is of any interest. But i was wondering something; When using multiple pools (traffic is directed based on url and/or host with httpclasses), can I configure the irule to show the maintenance page for only one of these pools? Right now it seems like the irule will only redirect if the default pool has no healthy members...

ingard
ingard
7/7/2009 7:17 AM
Gravatar @chris - The rule was originally written for v9. In v10, classes are called in a new way as you have already figured out, with the class command. So all rules with class references moving forward from v9 to v10 will need to be converted

@ingard - If you like, you can send your version to devcentral-at-f5-dot-com and I'll get it posted and linked from the wiki page. Re: the pool behavior...that is the way the iRule is configured, to only redirect to the sorry page when the pool has no active members. You can rewrite the rule to apply for other times as well, such as maintenance windows. To incorporate those concepts, you can take a look at this wiki page:

http://devcentral.f5.com/wiki/default.aspx/iRules/LTMMaintenanceWindow.html
Jason Rahm
1/4/2010 5:45 AM
Gravatar Kirk updated the script to auto-detect TMOS v10 and adjust accordingly. Links in the above post point to the new script. Thanks Kirk!
Jason

Let Me Know What You Think


Please use the form below if you have any comments, questions, or suggestions.

Title:
 
Name:
 
Email: (so we can show your gravatar)
Website:
Comment: Allowed tags: blockquote, a, strong, em, p, u, strike, super, sub, code
 
Please add 1 and 5 and type the answer here:
Blog Stats
Posts:63
Comments:62
Stories:0
Trackbacks:0