Forum Discussion
Maintenance page
Hi Guys,
I'm pretty new to iRules and trying to modify an existing code to do the following : 1) if pool is down, show page down 2) if pool is on high request, show high load page.. 3) both pages will have same images loaded in the ifiles
below is the code with 1) & 3) only and im not sure how to modify to include 2. any pointers will be appreciated.
when HTTP_REQUEST { if { [active_members pool_abc] < 1 } { log local0. "All pool members down: Redirecting to outage page." if { [HTTP::uri] eq "/assets/images/Company-Logo.png" } { HTTP::respond 200 content [ifile get companylogo.png] "Content-Type" "image/png" } else { HTTP::respond 200 content [ifile get maintenance.html]
} }
Thanks in advance.
10 Replies
- Stewart
Altostratus
Hi,
You need to do use something to define what heavy load is.
There's a good bit of code by Hoolio that sets a maximum number of connections which could be used as your heavy load threshold. You could modify this to suit your requirments.
https://devcentral.f5.com/wiki/iRules.virtual_server_connection_limit_with_HTTP_response.ashx
You could serve content from your iFiles instead of the static content in the example.
Stewart.
- annielee_13548
Nimbostratus
sorry for not making it clear, there is already a 'code' to define heavy load traffic..
i need some assistance on the if..then statement..
if pool < 0 then load maintenance page, elseif heavy load traffic then load heavy load page. end if
both pages will have the same images (uploaded to ifiles) but just different wordings..
thanks in advance
- nitass
Employee
if pool < 0 then load maintenance page, elseif heavy load traffic then load heavy load page. end if
isn't this if-statement already correct?
- annielee_13548
Nimbostratus
i tried the below if statemen and it doesnt work, as in the images wont load.
if { [active_members pool] < 1 } { HTTP::respond 200 content [ifile get maintenance.html] } elseif { highload > 2 } { HTTP::respond 200 content [ifile get highload.html] }
for images on the html page store in ifiles)if { [HTTP::uri] eq "/assets/images/companylogo.png" } { HTTP::respond 200 content [ifile get company.png] "Content-Type" "image/png" } elseif { [HTTP::uri] eq "/assets/images/footer.png" } { HTTP::respond 200 content [ifile get footer.png] "Content-Type" "image/png" }
- nitass
Employee
have you tried to swap order of the if-statements?
if { [HTTP::uri] eq "/assets/images/companylogo.png" } { HTTP::respond 200 content [ifile get company.png] "Content-Type" "image/png" } elseif { [HTTP::uri] eq "/assets/images/footer.png" } { HTTP::respond 200 content [ifile get footer.png] "Content-Type" "image/png" } if { [active_members pool] < 1 } { HTTP::respond 200 content [ifile get maintenance.html] } elseif { highload > 2 } { HTTP::respond 200 content [ifile get highload.html] } - annielee_13548
Nimbostratus
just noticed the log.. not sure what it meant..(with my initial code)
TCL error: /Common/ - Operation not supported. Multiple redirect/respond invocations not allowed invoked from within "HTTP::respond 200 content [ifile get companylogo.png] "Content-Type" "image/png""
- nitass
Employee
can you try something like this?
if { [HTTP::uri] eq "/assets/images/companylogo.png" } { HTTP::respond 200 content [ifile get company.png] "Content-Type" "image/png" return } elseif { [HTTP::uri] eq "/assets/images/footer.png" } { HTTP::respond 200 content [ifile get footer.png] "Content-Type" "image/png" return } if { [active_members pool] < 1 } { HTTP::respond 200 content [ifile get maintenance.html] } elseif { highload > 2 } { HTTP::respond 200 content [ifile get highload.html] } - annielee_13548
Nimbostratus
Thank you very much, it did load the images.. But do you mind to explain what does the return do ?
- nitass
Employee
do you mind to explain what does the return do ?
it does exit from current irule event.
the problem was it is not possible to have multiple response for one request (i.e. request matches two HTTP::respond commands). return helps because it would exit from irule execution after matching HTTP::respond.
return wiki
https://devcentral.f5.com/wiki/iRules.return.ashx - annielee_13548
Nimbostratus
thank you so much for your help !
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
