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.
Can you update your class names to match these and give the rule below a try?
Thanks,
Aaron
Class containing the HTML:
class maint_index_html_class {
type string
filename "/var/class/maint.index.html.class"
}
Class containing the base64 encoded image:
class maint_index_logo_class {
type string
filename "/var/class/maint.logo.png.class"
}
iRule which references the HTML and logo 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"
}
}