Forum Discussion
Chris_Chaloux_1
Nimbostratus
Dec 03, 2008LTM Maint. Page issue
All -
I am trying to set up the LTM Maintenace Page example and I'm running into an issue. I have set up the rule exactly as described in the document (http://devcentral.f5.com/Wiki/default.aspx/iRules/LTMMaintenancePage.html).
The issue I am having is that instead of the lindex html stream being returned, it is returning the location of the class file to the browser. When I invoke the rule by going after the VIP from my browser, the only display I get is:
/var/class/maint.index.html.class
Thats it! It seems like either a variable isnt being invoked correctly, or for some reason it is interpreting the call to the class file as a literal.
My iRule reads like this:
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 maint_prefix "/maintenancepage"
set maint_len [string length $maint_prefix]
set uri [HTTP::uri]
log local0. "redirect: [HTTP::uri]"
if { $uri equals ${::maint_prefix} } {
HTTP::respond 301 "Location" "${::maint_prefix}/"
return
}
if { $uri starts_with "${::maint_prefix}/" } {
trim off the maintenance prefix
set uri [string range $uri $::maint_len end]
Return the requested page
log local0. "respond: [lindex $::maint_index_html 0]"
switch $uri {
"/" -
"/index.html" { HTTP::respond 200 content [lindex $::maint_index_html 0] "Content-Type" "text/html" }
"/logo.png" { HTTP::respond 200 content [b64decode [lindex $::maint_logo_png 0]] "Content-Type" "image/png" }
default { HTTP::respond 404 }
}
return
}
If the all members in the default pool are down, redirect to the maintenance page
if { [active_members [LB::server pool]] < 1 } {
HTTP::redirect "${::maint_prefix}/index.html"
return
}
}
Does anyone see whats going on? This is driving me nuts!!
Thanks,
Chris
- hoolio
Cirrostratus
Hi Chris,set maint_prefix "/maintenancepage" set maint_len [string length $maint_prefix] set uri [HTTP::uri] ... set uri [string range $uri $::maint_len end]
set maint_prefix "/maintenancepage" set uri [HTTP::uri] ... set uri [string map [list $maint_prefix ""] $uri]
- Chris_Chaloux_1
Nimbostratus
Hi Aaron! Thanks again for the reply. You've always been extremely helpful. - hoolio
Cirrostratus
What is your class name that contains the HTML? Is it named exactly maint_index_html? If so you can reference it using $::maint_index_html. Can you try this rule and see if it works for you?when HTTP_REQUEST { Test the maint_index_html class if {[info exists ::maint_index_html]}{ log local0. "\[lindex \$::maint_index_html 0\]: [lindex $::maint_index_html 0]" } else { log local0. "\$::maint_index_html doesn't exist!" } Service requests for files (URIs) from the maintenance page Note that we always service these pages, even if the http_pool is up set maint_prefix "/maintenancepage" set maint_len [string length $maint_prefix] set uri [HTTP::uri] log local0. "redirect: [HTTP::uri]" if { $uri equals $maint_prefix } { HTTP::respond 301 "Location" "$maint_prefix/" } elseif { $uri starts_with "$maint_prefix/" } { Return the requested page switch $uri { "$maint_prefix/" - "$maint_prefix/index.html" { HTTP::respond 200 content [lindex $::maint_index_html 0] "Content-Type" "text/html" } "$maint_prefix/logo.png" { HTTP::respond 200 content [b64decode [lindex $::maint_logo_png 0]] "Content-Type" "image/png" } default { HTTP::respond 404 } } return } If the all members in the default pool are down, redirect to the maintenance page if { [active_members [LB::server pool]] < 1 } { HTTP::redirect "$maint_prefix/index.html" } }
- Chris_Chaloux_1
Nimbostratus
Well! Closer...I added your updated code and now get the following in the LTM log: - hoolio
Cirrostratus
Here is a tested version which uses local variables. I changed the class names to end with _class so it's a bit more clear that they're not standard global variables. I also changed the logic so that only one test would be done if the request isn't for a maintenance page. This should make the rule slightly more efficient for the majority of requests.class maint_index_html_class { type string filename "/var/class/maint.index.html.class" }
class maint_index_logo_class { type string filename "/var/class/maint.logo.png.class" }
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 maint_prefix "/maintenancepage" log local0. "New request to: [HTTP::uri]" if { [HTTP::uri] starts_with "$maint_prefix" } { Strip off the $maint_prefix from the URI as you can't easily do variable expansion within a switch statement. Note that requests for the exact maintenance URI will be set to a null string, so handle null in the first switch case. set uri [string map [list $maint_prefix ""] [HTTP::uri]] Return the requested page switch -- $uri { "" { log local0. "Request for $maint_prefix. Redirecting to $maint_prefix/" HTTP::redirect "$maint_prefix/index.html" } "/" - "/index.html" { log local0. "Request for index. Responding with content: [lindex $::maint_index_html_class 0]" HTTP::respond 200 content [lindex $::maint_index_html_class 0] "Content-Type" "text/html" } "/logo.png" { log local0. "Request for logo.png. Responding with binary content" HTTP::respond 200 content [b64decode [lindex $::maint_logo_png_class 0]] "Content-Type" "image/png" } default { log local0. "Unrecognized request to URI: [HTTP::uri]" HTTP::respond 404 content "Unrecognized request to [HTTP::uri]" "Content-Type" "text/html" } } return } If the all members in the default pool are down, redirect to the maintenance page if { [active_members [LB::server pool]] < 1 } { HTTP::redirect "$maint_prefix/index.html" } }
- Chris_Chaloux_1
Nimbostratus
Interesting!! - hoolio
Cirrostratus
I'd guess that your class isn't defined correctly or the external file actually contains /var/class/maint.index.html.class. If you list the class definition you should see something like this:b class maint_index_html_class list all class maint_index_html_class { type string filename "/var/class/maint.index.html.class" mode rw partition Common "Maintenance pageSorry! This site is down for maintenance." none none }
- Nit_67494
Nimbostratus
Hi All,
Any body can help me to create the i-rules via GUI, I have tried to create it by my self, but looks like the maintenance page is not working.
Thanks
- JRahm
Admin
Have you checked out Kirk's sorry page generator? Does all the work for you: - hoolio
Cirrostratus
Hi Nit,
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