Forum Discussion
Maintenance Page using V11
Hi guys
Ive read the brilliant article by https://devcentral.f5.com/articles/v111-ndashexternal-file-access-from-irules-via-ifiles which has been most useful and im actually about to attempt this in our live environment. So I have a HTML file which I have imported into the Ifile management list. The iRule I want to use is quite basic and doesnt have any fancy features. I simply want to write an iRule that if pool members are no longer available, then to simply redirect to the maintenance page via the iFile
I saw this example, but i dont understand the jpg files its pulling
when HTTP_REQUEST { if {[active_members [LB::server pool]] < 1} { switch [HTTP::uri] { "/guardian_header.jpg" { HTTP::respond 200 content [ifile get "guardian_header_jpg"] } "/guardian_logo.jpg" { HTTP::respond 200 content [ifile get "guardian_logo_jpg"] } default { HTTP::respond 200 content [ifile get "maint_index_html"] } } } }
This is what I think my iRule should look like and I want your help in tweaking it to suit..
when HTTP_REQUEST { if {[active_members [LB::server pool]] < 1} { switch [HTTP::uri] { " { HTTP::respond 200 content [ifile get "My_ifile"] } default { HTTP::respond 200 content [ifile get "maint_index_html"] } } } }
Can you guys have a look and let me know if this is ok??
9 Replies
- Kevin_Stewart
Employee
In its simplest form:
when HTTP_REQUEST { if { [active_members [LB::server pool]] < 1 } { switch [HTTP::uri] { "/maintenance_page_logo.jpg" { HTTP::respond 200 content [ifile get "maintenance_page_logo_jpg"] } default { HTTP::respond 200 content [ifile get "maint_index_html"] } } } }So basically what's happening is that if there are no pool members, the iRule will look at the request URI. The first request will most certainly fall through to the default condition and render the maintenance page HTML file. Inside that html you may have other linked content (images, scripts, stylesheets). Example:
So the browser will make subsequent requests for this linked content to finish rendering the page. Since the pool still has no active members, the browser's request for /maintenance_page_logo.jpg will get pulled from an ifile.
- Kevin_Stewart
Employee
So two things:
-
If you were using images in your maintenance page, the image ifiles would be in whatever image format, and the html page ifile would be a text file. In most cases you also want to include the "Content-Type" header in the response so the browser knows how to handle the object.
-
Since you don't have any images in your maintenance page, the iRule is considerably simpler:
when HTTP_REQUEST { if { [active_members [LB::server pool]] < 1 } { HTTP::respond 200 content [ifile get "maint_index_html"] } }
-
- avnishvyas_1974
Nimbostratus
Hi Kevin when HTTP_REQUEST { if { [active_members [LB::Customer_pool] == 0 } { switch [HTTP::uri] { " { HTTP::respond 200 content [ifile get Maintenance_Page"] } } }
It seems the F5 is not taking the above and its complaining of errors. Can you see anything wrong with this iRule?
- Kevin_Stewart
Employee
First thing, "[LB::Customer_pool]" isn't a thing. Use "[LB::server pool]" as described in the previous iRule example. This will expand to the currently configured pool when the event is triggered. You can optionally specify a literal pool name:
if { [active_members "Customer_pool"] == 0 }Second thing, you're still trying to switch on the HTTP::uri, but you don't need this since you're not presenting anything more than a single HTML page. Did you try the previous iRule example?
- avnishvyas_1974
Nimbostratus
Hi Kevin I went by your example and simply modified the name of the pool this is the rule I have done exactly which is throwing a PARSE error Missing bracket 33 (missing a closing bracket) Ive also removed the [HTTP::uri]
when HTTP_REQUEST { if { [active_members [LB::Customer_5013_5014_pool] == 0 } { " { HTTP::respond 200 content [ifile get "Maintenance_Page"] } } }
- Kevin_Stewart
Employee
So again, "[LB::Customer_5013_5014_pool]" isn't a valid command. You can either use "[LB::server pool]" to expand the configured pool automatically when the HTTP_REQUEST event is triggered, or you can put in the literal string name of the pool:
if { [active_members "Customer_5013_5014_pool"] == 0 }So the following should be exactly what you need:
when HTTP_REQUEST { if { [active_members [LB::server pool]] < 1 } { HTTP::respond 200 content [ifile get "Maintenance_Page"] } } - avnishvyas_1974
Nimbostratus
ive been playing with the Brackets its complaining of this now and im getting confused with what I should be using here if { [active_members [LB::server pool Pool Name?] ==0 } { http::respond 200 content [ifile get "maintenance_page] } }
Still the F5 rejects! the above
- avnishvyas_1974
Nimbostratus
Hi Kevin That worked!! I actually thought you had to specify the pool name. which is what i did hence it wasnt taking the iRule I have removed that now and the F5 accepted the iRule
Thanks for your help on this
- Kevin_Stewart
Employee
At the very least you're missing an ending bracket:
if { [active_members [LB::server pool]] ==0 }But more important, your LB::server syntax is incorrect. There is no option to add a pool name after "LB::server pool". It's just:
[active_members [LB::server pool]]If you want to specify the pool statically instead of letting it expand the value dynamically, then
[active_members my-test-pool]
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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