Forum Discussion
irule help
We have 1 irule doing the following:
when HTTP_REQUEST { if {[string tolower [HTTP::uri]] starts_with "/aboutus/careers"} {pool A} if {[string tolower [HTTP::uri]] starts_with "/aboutus"} {pool B} if {[string tolower [HTTP::uri]] starts_with "/admin/"} {pool B member 1} if {[string tolower [HTTP::uri]] starts_with "/app_themes"}{ pool B} if {[string tolower [HTTP::uri]] starts_with "/authorized_use_policy"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/cloud-overview"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/cms"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/customersuccesses"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/device-cloud-terms-of-service"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/dmca_statement"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/en"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/industries/"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/legal"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/new/prindex"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/news"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/pdf/*"}{[HTTP::uri] [string range [HTTP::uri] 4 end] pool C} if {[string tolower [HTTP::uri]] starts_with "/privacy"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/products-overview"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/scriptresource.axd"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/services-overview"}{pool B} if {[string tolower [HTTP::uri]] starts_with "/webresource.axd"}{pool B} }
I would like to direct /news* to Pool B except these subsections: /news/events* /news/graphics*
/aboutus* to Pool B except these subsections /aboutus/careers /aboutus/export /aboutus/environment
Any easy way to do this? Also should I consider breaking these into separate irules giving us more flexability?
10 Replies
- Brad_Parker
Cirrus
Try putting your pool A URIs in one datagroup(
); i.e. /news/events, /news/graphics,/aboutus/careers /aboutus/export, /aboutus/environment and all your pool B URIs in another datagroup(poolA_dg
) and try this irule. It will be more efficient and should accomplish your goal.poolB_dgwhen HTTP_REQUEST { if {class match [string tolower [HTTP::uri]] starts_with poolA_dg}{ pool A } elseif {class match [string tolower [HTTP::uri]] starts_with poolB_dg}{ pool B } elseif {[string tolower [HTTP::uri]] starts_with "/admin/"} { pool B member 1 } elseif {[string tolower [HTTP::uri]] starts_with "/pdf/*"}{ [HTTP::uri] [string range [HTTP::uri] 4 end] pool C } } - Chris_Lappi_164
Nimbostratus
Thanks Brad. So I tried it and here is some results I am finding. And I am focusing on one set just to keep things simple.
/aboutus - goes to pool A - should go to pool b /aboutus/careers goes to pool A /aboutus/export goes to pool A should go to pool b /aboutus/managementteam goes to pool A should go to pool b
- Brad_Parker
Cirrus
Can you post your datagroups that you created? Also, are you using the iRule from above exactly? If you made tweaks please post them.
- Chris_Lappi_164
Nimbostratus
I added a logging method, a set of [] to get the rule to be valid, and put in the real pool names/member ip's. Also tried with "contains" vs "starts with".
when HTTP_REQUEST { set the URL here, log it on the response set url [HTTP::header Host][HTTP::uri] set vip [IP::local_addr]:[TCP::local_port] if {[class match [string tolower [HTTP::uri]] starts_with DGI_Pool_A]}{ pool A } elseif {[class match [string tolower [HTTP::uri]] starts_with DGI_Pool_B]}{ pool B } elseif {[string tolower [HTTP::uri]] starts_with "/admin/"} { pool B member 1 } elseif {[string tolower [HTTP::uri]] starts_with "/pdf/*"}{ [HTTP::uri] [string range [HTTP::uri] 4 end] pool C } } when HTTP_RESPONSE { set client [IP::client_addr]:[TCP::client_port] set node [IP::server_addr]:[TCP::server_port] set nodeResp [HTTP::status] log connection info log local0.info "Client: $client -> VIP:$vip $url -> Node: $node with response $nodeResp" } ltm data-group internal /Common/DGI_Pool_A { records { /aboutus/careers { data /aboutus/careers } /aboutus/environment { data /aboutus/environment } /aboutus/export { data /aboutus/export } /news/events { data /news/events } /news/graphics { data /news/graphics } } type string } ltm data-group internal /Common/DGI_Pool_B { records { /app_themes { data /app_themes } /authorized_use_policy { data /authorized_use_policy } /cloud-overview { data /cloud-overview } /cms { data /cms } /customersuccesses { data /customersuccesses } /device-cloud-terms-of-service { data /device-cloud-terms-of-service } /dmca_statement { data /dmca_statement } /en { data /en } /industries/ { data /industries/ } /legal { data /legal } /new/prindex { data /new/prindex } /news { data /news } /privacy { data /privacy } /products-overview { data /products-overview } /scriptresource.axd { data /scriptresource.axd } /services-overview { data /services-overview } webresource.axd { data webresource.axd } } type string - Brad_Parker
Cirrus
and/aboutus/careers
are defined in DGI_Pool_A that's why they are going there. I would define/aboutus/export
in DGI_Pool_B so all your other /aboutus URIs go there./aboutus - Chris_Lappi_164
Nimbostratus
Thank you...adding /aboutus to DG B got us everything. Now we can have the flexibility to port sections down to specific pages of our website to a new environment and have the control we need.
- Chris_Lappi_164
Nimbostratus
So the rule is working great. Now I need to add some more logic. In the section:
elseif {[class match [string tolower [HTTP::uri]] starts_with DGI_Pool_B]}{ pool BFor the URI if it contains /en/ I would like it removed and then sent to pool B.
Tried this and in the process od debugging why its not working
elseif {[class match [string tolower [HTTP::uri]] starts_with DGI_Pool_B]} {[string map -nocase {"/en/" ""} [HTTP::uri]] {pool B}}Thoughts??
- Brad_Parker
Cirrus
your string map works but you're not setting the uri. Try : [HTTP::uri] [string map -nocase {"/en/" ""} [HTTP::uri]]
- Chris_Lappi_164
Nimbostratus
getting the following in the LTM log: invalid command name ""
between the quotes would be the uri being requested.
elseif currently looks like this:
elseif {[class match [string tolower [HTTP::uri]] starts_with DGI_Pool_B]} {[HTTP::uri] [string map -nocase {"/en/" ""} [HTTP::uri]] {pool B}}Really appreciate the help Brad!!!
- Brad_Parker
Cirrus
may have to actually be [HTTP::uri] [string map -nocase {"/en/" "/"} [HTTP::uri]]
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