Forum Discussion
active members check on multiple pools
I have an iRule that redirects traffic to another pool by uri. I want to be able to mark the site offline with a placeholder if the default pool is unavailable. I have a seperate pool for my placeholder server. It works fine for the default pool offline but not if I try teh redirected pool. Any suggestions?
iRule: when HTTP_REQUEST { set DEBUG 0 if { $DEBUG } { log local0. "Request: [HTTP::uri]" } if {[active_members QA-HC-HTTP] < 1} { pool QA-PH return } if { $DEBUG } { log local0. "Request: [HTTP::uri]" } switch -glob [string tolower [HTTP::uri]] { "/portals/" - "/js/" - "/controls/" - "/uk/" - "/us/" - "/ca/" - "/admin/controlpanel/" - "/webresource" - "/scriptresource" - "/resources/" - "/providers/" - "/linkclick" - "/documentation/" - "/desktopmodule/" - "/config/" - "/components/" - "/bin/" - "/app_themes/" - "/app_globalResources/" - "/app_data/" - "/app_code/" - "/app_browser/" - "/dnnaadmin/" - "/contactus/" - "/resourcecenter/i" - "/resourcecenter/r" - "/resourcecenter/j" - "/resourcecenter/e" { if { $DEBUG }{log local0. "Sending request to QA-HC-HTTPDNN"} if {[active_members QA-HC-HTTP] < 1} { pool QA-PH return } pool QA-HC-HTTPDNN } default { pool QA-HC-HTTP} } }
21 Replies
- nitass
Employee
It works fine for the default pool offline but not if I try the redirected pool.
can you give an example which does not work?
by the way, did you forget to put special sequences (e.g. asterisk question mark), in the switch glob case?
iRules 101 - 04 - Switch by Joe Pruitt
https://devcentral.f5.com/articles/irules-101-04-switch.U1FXpledGCQwhen HTTP_REQUEST { set DEBUG 0 if { $DEBUG } { log local0. "Request: [HTTP::uri]" } if { [active_members QA-HC-HTTP] < 1} { pool QA-PH return } if { $DEBUG } { log local0. "Request: [HTTP::uri]" } switch -glob [string tolower [HTTP::uri]] { "/portals/" - "/js/" - "/controls/" - "/uk/" - "/us/" - "/ca/" - "/admin/controlpanel/" - "/webresource" - "/scriptresource" - "/resources/" - "/providers/" - "/linkclick" - "/documentation/" - "/desktopmodule/" - "/config/" - "/components/" - "/bin/" - "/app_themes/" - "/app_globalResources/" - "/app_data/" - "/app_code/" - "/app_browser/" - "/dnnaadmin/" - "/contactus/" - "/resourcecenter/i" - "/resourcecenter/r" - "/resourcecenter/j" - "/resourcecenter/e" { if { $DEBUG } {log local0. "Sending request to QA-HC-HTTPDNN" } if { [active_members QA-HC-HTTP] < 1} { pool QA-PH return } pool QA-HC-HTTPDNN } default { pool QA-HC-HTTP } } } - ryan_rockwell_1
Nimbostratus
Basically when the pool is unavailable if I go to qa.website.com the site maintenance page comes up. If I go to qa.website.com/us/blah blah blah I get a page not found. Where as if the pool is available the qa.website.com/us/blah blah blah page loads fine. My end goal is to have the maintenance page appear for both pools whenever the default pool is unavailable.
- Kevin_Stewart
Employee
Your life will be a lot easier if you use a data group for this large list of URIs.
when RULE_INIT { set static::DEBUG 1 } when HTTP_REQUEST { if { [active_members QA-HC-HTTP] < 1 } { if { $static::DEBUG } { log local0. "Primary pool offline" } pool QA-PH } elseif { [class match [string tolower [HTTP::uri]] starts_with uri_list] } { pool QA-HC-HTTPDNN } else { pool QA-HC-HTTP } }** where "uri_list" is a string-based data group. Example:
/portals/" := "" "/js/" := "" "/controls/" := "" "/uk/" := "" "/us/" := "" "/ca/" := "" "/admin/controlpanel/" := "" "/webresource" := "" "/scriptresource" := "" "/resources/" := "" "/providers/" := "" "/linkclick" := "" "/documentation/" := "" "/desktopmodule/" := "" "/config/" := "" "/components/" := "" "/bin/" := "" "/app_themes/" := "" "/app_globalResources/" := "" "/app_data/" := "" "/app_code/" := "" "/app_browser/" := "" "/dnnaadmin/" := "" "/contactus/" := "" "/resourcecenter/i" := "" "/resourcecenter/r" := "" "/resourcecenter/j" := "" "/resourcecenter/e" := "" - nitass
Employee
If I go to qa.website.com/us/blah blah blah I get a page not found.
can you try to add "HTTP::uri /" into the irule?
if { [active_members QA-HC-HTTP] < 1} { HTTP::uri / pool QA-PH return } - ryan_rockwell_1
Nimbostratus
So I took Kevin and nitass's advice. I created a new rule: when RULE_INIT {
set static::DEBUG 1}
when HTTP_REQUEST {
if { [active_members INF-HC-HTTP] < 1 } { if { $static::DEBUG } { log local0. "Primary pool offline" } HTTP::uri / pool QA-PH } elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HC-URI] } { pool INF-HC-HTTPDNN } else { pool INF-HC-HTTP }}}
with a string data group called QA-HC-URI and everything works like a charm except for one piece. When the maintenance page comes up it loads the text but the CSS and the images are missing. When I wireshark it, it says everything is fine and the logs on the server say it's being delivered but they don't show up. If I host file to the server directly it comes up perfectly. I'm clueless. Thanks.
- nitass
Employee
When the maintenance page comes up it loads the text but the CSS and the images are missing.
it is because we change all request uri to root (/) in HTTP::uri / command. this has to be done for fixing the problem below.
If I go to qa.website.com/us/blah blah blah I get a page not found.so, what we can do is to not change request uri for css and image. can you try something like this?
e.g.
when HTTP_REQUEST { if { [active_members INF-HC-HTTP] < 1 } { if { $static::DEBUG } { log local0. "Primary pool offline" } switch -glob [string tolower [HTTP::path]] { "*css" - "*jpg" - "*gif" - "*png" { do nothing } default { HTTP::uri / } } pool QA-PH } elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HC-URI] } { pool INF-HC-HTTPDNN } else { pool INF-HC-HTTP } } - ryan_rockwell_1
Nimbostratus
No luck. I added a section for css and gif because that's all we have and it made no difference.
- nitass
Employee
No luck. I added a section for css and gif because that's all we have and it made no difference.
do you know url of css and image which are missing? have you used http analyzer tool such as httpfox? it may be helpful.
HttpFox
https://addons.mozilla.org/en-US/firefox/addon/httpfox/ - ryan_rockwell_1
Nimbostratus
So I ran a wireshark after setting the rule and I understand why it's not getting the file.... GET /us/resource/images/logo.gif shouldn't work, it's not being redirected to the QA-PH pool. /images/logo.gif is the right path but /us/resource/ is the original source. So I have to figure out how to get it to GET /images/logo.gif without the /us/resource/
- nitass
Employee
GET /us/resource/images/logo.gif shouldn't work, it's not being redirected to the QA-PH pool. /images/logo.gif is the right path but /us/resource/ is the original source.
why is the path not correct? isn't it (maintenance html page) generated by GET / to pool QA-PH?
anyway, if you want to remove /us/resource/ in request for css and image file, you can use string map command similar to this.
e.g.
when HTTP_REQUEST { if { [active_members INF-HC-HTTP] < 1 } { if { $static::DEBUG } { log local0. "Primary pool offline" } switch -glob [string tolower [HTTP::path]] { "*css" - "*jpg" - "*gif" - "*png" { HTTP::uri [string map {/us/resource/ /} [HTTP::uri]] } default { HTTP::uri / } } pool QA-PH } elseif { [class match [string tolower [HTTP::uri]] starts_with QA-HC-URI] } { pool INF-HC-HTTPDNN } else { pool INF-HC-HTTP } }
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