Forum Discussion
iRule for App Offline
We currently use an iRule to display an app offline page when the connection to the server is down. I would like to some how to make this as generic as possible due to wanting to use host headers. Here's what we currently use.
when HTTP_REQUEST { if { [active_members APP-HTTPS-POOL] < 1 } { HTTP::respond 200 content [ifile get App_Offline] } }
I would like to have the irule check the host header for multiple sites and only send the App_Offline for the pool that's down.
Example: abc.123.com def.123.com & ghi.123.com. all have pools matching the host name. If abc.123.com pool members are down but the others are up I only want the App_Offline page to show for that site.
- wlopez_98779Nimbostratus
Are you using one virtual server/per pool/per site? By that I mean, does each URL(Ex. abc.123.com) has it's own virtual server and pool? If that's the case you could do that via a custom http profile or a simple iRule for each virtual server. In case of the custom http profile you just need to configure the maintenance page's URL in the 'Fallback Host' field. This will do a 302 redirect when all pool members in the pool associated with the virtual server are down. A simple iRule like the following will get you the same result: when LB_FAILED { HTTP::redirect "; } With either one of this options you need to make sure that the health monitors for the pools are intelligent enough to detect services are actually down.
Hope this helps.
- rwagner1Nimbostratus
We have a single VIP and using an irule to get to the different pools for each of the sites.
- wlopezCirrocumulus
Are you using one virtual server/per pool/per site? By that I mean, does each URL(Ex. abc.123.com) has it's own virtual server and pool? If that's the case you could do that via a custom http profile or a simple iRule for each virtual server. In case of the custom http profile you just need to configure the maintenance page's URL in the 'Fallback Host' field. This will do a 302 redirect when all pool members in the pool associated with the virtual server are down. A simple iRule like the following will get you the same result: when LB_FAILED { HTTP::redirect "; } With either one of this options you need to make sure that the health monitors for the pools are intelligent enough to detect services are actually down.
Hope this helps.
- rwagner1Nimbostratus
We have a single VIP and using an irule to get to the different pools for each of the sites.
- Irule name: Irule_XXXXX.xxxxx.org Programmed by Hector Morrell Programmed date: Programmed update: Programmed update by: type of update: Description:
when HTTP_REQUEST {
set the host name and url to lower case set Vuri [ string tolower [HTTP::uri]] set Vheader [string tolower [HTTP::host]] set the Poolname variable. set Poolname "pl_abc.123.com" set poolname2 "pl_def.123.com" set poolname3 "ghi.123.co" set the default site name variable set SiteName "XXXX.MAINTENANCEPAGE.org" set Irulename "Irule_$SiteName" set SiteRedirect "https://$SiteName" Obtain active poolmembers count and list set Poolmember [active_members $Poolname ] set Poolmemberlist [ active_members -list $Poolname] set Poolmember2 [active_members $Poolname2 ] set Poolmemberlist2 [ active_members -list $Poolname2] set Poolmember3 [active_members $Poolname3 ] set Poolmemberlist3 [ active_members -list $Poolname3] redirect to maintenance page if poolmembers count is zero switch $Vheader { abc.123.com { if {$Poolmember < 1} then { log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean $SiteName website is down. IRULE=$Irulename"; HTTP::redirect "http://www.YOURPAGE-OFFLINE.COM" } else { pool $Poolname } } def.123.com { if {$Poolmember2 < 1} then { log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean $SiteName website is down. IRULE=$Irulename"; HTTP::redirect "http://www.YOURPAGE-OFFLINE.COM" } else { pool $Poolname2 } } ghi.123.com { if {$Poolmember3 < 1} then { log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean $SiteName website is down. IRULE=$Irulename"; HTTP::redirect "http://www.YOURPAGE-OFFLINE.COM" } else { pool $Poolname3 } } default { HTTP::redirect "$SiteRedirect"} }
}
if the server sends a 500 error code log the error and redirect to maintenance page when HTTP_RESPONSE { switch [HTTP::status] { 500 { log local0.alert "The servers is sending back a 500 Error: " HTTP::redirect "http://www.benaroyaresearch.org.s3-website-us-west-2.amazonaws.com/" } 502 { log local0.alert "The servers is sending back a 502 Error: " HTTP::redirect "http://www.benaroyaresearch.org.s3-website-us-west-2.amazonaws.com/" } 503 { log local0.alert "The servers is sending back a 503 Error: " HTTP::redirect "http://www.benaroyaresearch.org.s3-website-us-west-2.amazonaws.com/" } }
}
The second part of the Irule is only if you get a 50X error from the server. you do not need that part. Hope this help
- rwagner1Nimbostratus
So there's no way to simplify this so what ever URI comes in it could call out to the pool matching that URI. I don't want to have to edit the iRule every time they add a site.
Example Site abc.123.com Pool abc.123.com down send App_Offline but if Site def.123.com Pool def.123.com is up do not send App_Offline.
- HectormNimbostratusIrule name: Irule_XXXXX.xxxxx.org Programmed by Hector Morrell Programmed date: Programmed update: Programmed update by: type of update: Description:
when HTTP_REQUEST {
set the host name and url to lower case set Vuri [ string tolower [HTTP::uri]] set Vheader [string tolower [HTTP::host]] set the Poolname variable. set Poolname "pl_abc.123.com" set poolname2 "pl_def.123.com" set poolname3 "ghi.123.co" set the default site name variable set SiteName "XXXX.MAINTENANCEPAGE.org" set Irulename "Irule_$SiteName" set SiteRedirect "https://$SiteName" Obtain active poolmembers count and list set Poolmember [active_members $Poolname ] set Poolmemberlist [ active_members -list $Poolname] set Poolmember2 [active_members $Poolname2 ] set Poolmemberlist2 [ active_members -list $Poolname2] set Poolmember3 [active_members $Poolname3 ] set Poolmemberlist3 [ active_members -list $Poolname3] redirect to maintenance page if poolmembers count is zero switch $Vheader { abc.123.com { if {$Poolmember < 1} then { log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean $SiteName website is down. IRULE=$Irulename"; HTTP::redirect "http://www.YOURPAGE-OFFLINE.COM" } else { pool $Poolname } } def.123.com { if {$Poolmember2 < 1} then { log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean $SiteName website is down. IRULE=$Irulename"; HTTP::redirect "http://www.YOURPAGE-OFFLINE.COM" } else { pool $Poolname2 } } ghi.123.com { if {$Poolmember3 < 1} then { log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean $SiteName website is down. IRULE=$Irulename"; HTTP::redirect "http://www.YOURPAGE-OFFLINE.COM" } else { pool $Poolname3 } } default { HTTP::redirect "$SiteRedirect"} }
}
if the server sends a 500 error code log the error and redirect to maintenance page when HTTP_RESPONSE { switch [HTTP::status] { 500 { log local0.alert "The servers is sending back a 500 Error: " HTTP::redirect "http://www.benaroyaresearch.org.s3-website-us-west-2.amazonaws.com/" } 502 { log local0.alert "The servers is sending back a 502 Error: " HTTP::redirect "http://www.benaroyaresearch.org.s3-website-us-west-2.amazonaws.com/" } 503 { log local0.alert "The servers is sending back a 503 Error: " HTTP::redirect "http://www.benaroyaresearch.org.s3-website-us-west-2.amazonaws.com/" } }
}
- HectormNimbostratus
The second part of the Irule is only if you get a 50X error from the server. you do not need that part. Hope this help
- rwagner1Nimbostratus
So there's no way to simplify this so what ever URI comes in it could call out to the pool matching that URI. I don't want to have to edit the iRule every time they add a site.
Example Site abc.123.com Pool abc.123.com down send App_Offline but if Site def.123.com Pool def.123.com is up do not send App_Offline.
There is a way to do it but you need to make sure you follow the config as follow The pool name have to be in lower case and equal to the domain name. This is because we are getting the Header from the request and change it to lower case In this Irule, I am adding the word pl_ but you can remove it Example Http or https://abc.123.com the pool name have to be abc.123.com
when HTTP_REQUEST {
set the host name and url to lower caseset Vuri [ string tolower [HTTP::uri]] set Vheader [string tolower [HTTP::host]]
set the Poolname variable.set Poolname "$Vheader"
set the default site name variableset SiteName "XXXX.MAINTENANCEPAGE.org"
set Irulename "Irule_$SiteName" set SiteRedirect "https://$SiteName"
Obtain active poolmembers count and listset Poolmember [active_members $Poolname ] set Poolmemberlist [ active_members -list $Poolname]
if {$Poolmember < 1} then { log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean $SiteName website is down. IRULE=$Irulename"; HTTP::redirect "http://www.YOURPAGE-OFFLINE.COM" } pool $Poolname
}
when HTTP_REQUEST { set the host name and url to lower case set Vuri [ string tolower [HTTP::uri]] set Vheader [string tolower [HTTP::host]] set the Poolname variable. set Poolname "$Vheader" set the default site name variable set SiteName "XXXX.MAINTENANCEPAGE.org" set Irulename "Irule_$SiteName" set SiteRedirect "https://$SiteName" Obtain active poolmembers count and list set Poolmember [active_members $Poolname ] set Poolmemberlist [ active_members -list $Poolname] if {$Poolmember < 1} then { log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean $SiteName website is down. IRULE=$Irulename"; HTTP::redirect "http://www.YOURPAGE-OFFLINE.COM" } pool $Poolname }
Let me know if this works for you
- rwagner1Nimbostratus
Can I replace the HTTP::redirect "; with HTTP::respond 200 content [ifile get App_Offline]
- HectormNimbostratus
There is a way to do it but you need to make sure you follow the config as follow The pool name have to be in lower case and equal to the domain name. This is because we are getting the Header from the request and change it to lower case In this Irule, I am adding the word pl_ but you can remove it Example Http or https://abc.123.com the pool name have to be abc.123.com
when HTTP_REQUEST {
set the host name and url to lower caseset Vuri [ string tolower [HTTP::uri]] set Vheader [string tolower [HTTP::host]]
set the Poolname variable.set Poolname "$Vheader"
set the default site name variableset SiteName "XXXX.MAINTENANCEPAGE.org"
set Irulename "Irule_$SiteName" set SiteRedirect "https://$SiteName"
Obtain active poolmembers count and listset Poolmember [active_members $Poolname ] set Poolmemberlist [ active_members -list $Poolname]
if {$Poolmember < 1} then { log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean $SiteName website is down. IRULE=$Irulename"; HTTP::redirect "http://www.YOURPAGE-OFFLINE.COM" } pool $Poolname
}
- HectormNimbostratus
when HTTP_REQUEST { set the host name and url to lower case set Vuri [ string tolower [HTTP::uri]] set Vheader [string tolower [HTTP::host]] set the Poolname variable. set Poolname "$Vheader" set the default site name variable set SiteName "XXXX.MAINTENANCEPAGE.org" set Irulename "Irule_$SiteName" set SiteRedirect "https://$SiteName" Obtain active poolmembers count and list set Poolmember [active_members $Poolname ] set Poolmemberlist [ active_members -list $Poolname] if {$Poolmember < 1} then { log local0.alert "ALERT-TEAM Pool $Poolname is down. This mean $SiteName website is down. IRULE=$Irulename"; HTTP::redirect "http://www.YOURPAGE-OFFLINE.COM" } pool $Poolname }
- HectormNimbostratus
Let me know if this works for you
- rwagner1Nimbostratus
Can I replace the HTTP::redirect "; with HTTP::respond 200 content [ifile get App_Offline]
- Stanislas_Piro2Cumulonimbus
Hi,
I use following irule to manage maintenance page per pool.
with this rule, pool can be assigned by a irule executed before or by an LTM Policy.
when HTTP_REQUEST { switch [HTTP::path] { "/maintenance/logo.png" { HTTP::respond 200 content [ifile get "logo.png"] "Content-Type" "image/png" return } "/maintenance/maintenance.html" { HTTP::respond 200 content [ifile get "maintenance.html"] "Content-Type" "text/html" return } "/maintenance/error.html" { HTTP::respond 200 content [ifile get "error.html"] "Content-Type" "text/html" return } default { set dpool [LB::server pool] if { $dpool equals "" } { HTTP::redirect "/maintenance/error.html" ; unset dpool; return} if { [active_members $dpool] == 0 } { HTTP::redirect "/maintenance/maintenance.html"; unset dpool; return} unset dpool } } } when HTTP_RESPONSE { if { [HTTP::status] eq "404" } { HTTP::redirect "/maintenance/error.html" } }
- rwagner1Nimbostratus
Maybe I haven't described this properly. We want all sites no matter the top level domain to come into the same VIP. That VIP uses an iRule for the host header to send the connection to the proper pool. I need a generic iRule that will look at the host header and if the pool that corresponds to that host header is down I would like to send the iFile app offline.
Example (abc.123.com, 111.ZZZ.com & 222.BBB.com) all have the same public IP and come into the same F5 VIP, however the VIP uses an iRule for host headers to send the connection to the correct pool. When that pool just happens to be down I would like an iRule to send an app offline page.
- Stanislas_Piro2Cumulonimbus
The irule I provided does exactly that! it must run after irule assigning pool.
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