Forum Discussion
Irules Data-Group
Hi,
Need your assistance into this topic related to Irule Based on Data-Groups:
- Currently we have total 120 Virtual-Servers( 60 HTTP profiles + 60 HTTPS Profiles) created into the Load-Balancer for single customer.
- And into every profile they specified/attached the below Irule:
Let’s say For HTTP Profile Irule:
when CLIENT_ACCEPTED { set default_pool [LB::server pool] log local0. "Default pool [LB::server pool] set" log local0. "Client IP is [IP::remote_addr]" }
when HTTP_REQUEST { set https_uri [string tolower [HTTP::uri]] log local0. "requested [HTTP::uri]" if {$https_uri equals "/" } { HTTP::redirect "https://parveez.com" pool pool_parveez.com log local0. "redirected from /"
return
} elseif { $https_uri starts_with "/iss_static" } {
log local0. "matched /iss_static"
pool pool_confarmsp.leni2.com_http
log local0. "pool_confarmsp.leni2.com_http defined, [LB::server pool] selected" return
} elseif { $https_uri starts_with "/"} { log local0. "URI starts with /"
pool pool_apuat_leni2.com_http
log local0. " pool_apuat_leni2.com_http defined, [LB::server pool] selected" return
} else {
log local0. "no match for rev. close connection"
pool pool_apuat_leni2.com_http }
}
- Just to give you a brief about the Irules, the client got two kinds of pages; One is Static content which is specified by "/iss_static" , while else option is for Dynamic content which is identified by entry /SEUILibrary/ which consists of many options inside.
Now requirement is to add/edit such an irule using Data-Groups so that when the user hits the Virtual-Server, it will automatically understand based on the "/iss_static" or else going to the pool and understands it as /SEUILibrary/ for dynamic content, into the same Data-groups it automatically should understand which pool to go BY SEEING its name.
For example:
- Lets say we have three Virtual-servers:
www.abc.com-HTTP ------ Pool named as : pool-abc.com-HTTP www.def.com-HTTPS ------ Pool named as : pool-def.com-HTTP www.ghi.com-HTTPS ------ Pool named as : pool-ghi.com-HTTP
- So, these got an Irule with "/iss_static" : for static page content and if not it will go for /SEUILibrary/ for dynamic page content.
- So, basically we are looking for an Irule using Data-Group which contains "/iss_static" and /SEUILibrary/ and also when this Irule is attached to the Virtual-server it will automatically should send which pool to Go by comparing the common parameters like abc Virtual-server which is matching with abc named pool( nomenclature is same: Virtual-server: www.abc.com-HTTP and Pool: pool-abc.com-HTTP), so in the above Irule we wanted to remove the pool part and to introduce Data-Group.
So, breaking the Irule:
The below part will remain same:
when CLIENT_ACCEPTED { set default_pool [LB::server pool] log local0. "Default pool [LB::server pool] set" log local0. "Client IP is [IP::remote_addr]" }
when HTTP_REQUEST { set https_uri [string tolower [HTTP::uri]] log local0. "requested [HTTP::uri]" if {$https_uri equals "/" } { HTTP::redirect "https://parveez.com" pool pool_parveez.com log local0. "redirected from /"
return
After this part it should use the Data-group which will replace the pool part from Irule and replaced the same by Data-Group
} elseif { $https_uri starts_with "/iss_static" } {
log local0. "matched /iss_static"
pool pool_confarmsp.leni2.com_http
log local0. "pool_confarmsp.leni2.com_http defined, [LB::server pool] selected" return
} elseif { $https_uri starts_with "/"} { log local0. "URI starts with /"
pool pool_apuat_leni2.com_http
log local0. " pool_apuat_leni2.com_http defined, [LB::server pool] selected" return
} else {
log local0. "no match for rev. close connection"
pool pool_apuat_leni2.com_http }
}
Thanks and Regards Parveez
- IheartF5_45022Nacreous
Try;
default { pool [class match -value [virtual] ends_with dg_parveez_dynamic_pools ] return }
Sorry I think I gave the wrong syntax in above example. And yes, string datagroup.
- Parveez_70209Nimbostratus
Sir,
Thanks, so if we try to browse: for esample: test.parveez.com/with dynamic page extension, In fiddler /iss_static contents are dropping, is that normal.
but when we are trying test.parveez.com , yes thats redirecting to www.parveez.com/us/en and into this can see the ISS_STatic contents.
Kindly suggest.
Thanks and Regards Parveez
- IheartF5_45022Nacreous
Sounds like you may be using vHosts on your static server? And you haven't configured test.parveez.com as a vhost?
- Parveez_70209Nimbostratus
Hi Sir,
After a long-time, did many tests and finally we have the below:
==================
when CLIENT_ACCEPTED { set default_pool [LB::server pool]
========================
In the above Irule : as you are aware that we created two Data-Groups Parveez_Static104 and Parveez_Dynamic104 respectively for Static and Dynamic Pools:
Data-Group: Parveez_Static104 and Parveez_Dynamic104 consists of binding of: Virtual-Server:=Pool Name as mentioned below:
-=== b shell class dg_parveez_dynamic_pools { { "apctdev.leni2.com-VS-HTTP" { "pool_apctdev.leni2.com_http" } "apbuild.leni2.com-VS-HTTP" { "pool_apbuild.leni2.com_http" } "apctdev.leni2.com-VS-HTTP" { "pool_apctdev.leni2.com_http" } } }
Now Our idea is to add the First part of the Irule also into a 3rd Data-Group: basically link: "http://apbuild.leni2.com/SEUILibrary/controller/e/web/LenovoPortal/en_US/catalog.workflow:test-home" with the Pool name:pool_ctbuild.leni2.com_http)
when HTTP_REQUEST { switch -glob [HTTP::uri] { "/" { log local0. "redirecting from /" HTTP::redirect "http://apbuild.leni2.com/SEUILibrary/controller/e/web/LenovoPortal/en_US/catalog.workflow:test-home"
So, how my existing Irule will look like. Kindly suggest.Tring to avoid any kind of 302 redirect, inspite 301 is good and desirable.
Thanks and Regards Parveez
- IheartF5_45022Nacreous
Here;-
when CLIENT_ACCEPTED { set default_pool [LB::server pool] log local0. "Default pool [LB::server pool] set " log local0. "Client IP is [IP::remote_addr]" } when HTTP_REQUEST { switch -glob [HTTP::uri] { "/" { log local0. "redirecting from /" if { [class match [LB::server pool] equals Parveez_pools] } { HTTP::respond 301 Location "[class match -value [LB::server pool] equals Parveez_pools]" Cache-Control "no-cache" } else { log local0. "Static pool entry for [LB::server pool] not created yet" reject } return } "/iss_static*" { if { [class match [virtual] equals Parveez_Static104] } { pool [lindex [split [class match -value [virtual] equals Parveez_Static104] ","] 1] } else { log local0. "Static pool entry for [virtual] not created yet" reject } return } default { if { [class match [virtual] equals Parveez_Dynamic104] } { pool [lindex [split [class match -value [virtual] equals Parveez_Dynamic104] ","] 0] } else { log local0. "Dynamic pool entry for [virtual] not created yet" reject } return } } }
You may wonder why I add Cache-Control "no-cache" to the 302 redirect - gotta be careful of 301 redirect - if you accidentally return an invalid Location header to a browser, some of them will refuse to obey it, but cache it anyway, and you cannot get rid of cached 301s easily. Also if you just want to change it later you cannot, adding no-cache means that you get all the SEO benefits of a 301 without the headache.
- Parveez_70209Nimbostratus
Hi Sir,
Just to add one more query related to Data-Group: Parveez_pools,
Is that String Data-Group can bind whole Link with Pool, I mean:
"http://apbuild.leni2.com/SEUILibrary/controller/e/web/LenovoPortal/en_US/catalog.workflow:test-home" :=pool pool_ctbuild.leni2.com_http ??
Thanks and Regards Parveez
- IheartF5_45022Nacreous
Not quite - the pool name would be the key, so in the GUI it would look like this;-
pool_ctbuild.leni2.com_http := http://apbuild.leni2.com/SEUILibrary/controller/e/web/LenovoPortal/en_US/catalog.workflow:test-home
- Parveez_70209Nimbostratus
Hi Sir,
Seems like with your constant support, we are able to get our results, but one last obstruction:
In /ISS_Static part, some of the contents seems to be passed while some are dropping with 404 error. Need your support in editing /ISS_static part matching as case-insensitive, so that anything matching to /iss_static or /ISS_Static will definitely pass to the respective Data-Group contents. Kindly guide how to modify the below Irule:
===============================
when HTTP_REQUEST { switch -glob [HTTP::uri] { "/" { log local0. "redirecting from /" if { [class match [virtual] equals Common ] } { HTTP::respond 301 Location [lindex [split [class match -value [virtual] equals Common] ","] 2] pool [lindex [split [class match -value [virtual] equals Common ] ","] 0] log local0. "Went to root ( / ), index 0 - WEC pool after index 2 url set with 301" } else { log local0. "Static pool entry for xxxx[LB::server pool] not created yet" reject } return } "/ISS_Static*" { if { [class match [virtual] equals Common ] } { pool [lindex [split [class match -value [virtual] equals Common] ","] 1] log local0. "Went to default, index 1 - Confarm pool" } else { log local0. "Static pool entry for [virtual] not created yet" reject } return }
default { if { [class match [virtual] equals Common ] } { pool [lindex [split [class match -value [virtual] equals Common ] ","] 0] log local0. "Went to default, index 0 - WEC pool" } else { log local0. "Dynamic pool entry for [virtual] not created yet" reject } return } }
}
================
Thanks and Regards Parveez
- IheartF5_45022Nacreous
Just use
switch -glob [string tolower [HTTP::uri]] {
Then all your switch 'arms' can use lowercase only in the iRule, but will match upper/lower/mixed case.
- Parveez_70209Nimbostratus
Sir, in some forms we have /ISS_static while some seems like /iss_static, so thats the reason some are dropping while some are passing.
Incase, if we modify the Irule and only want /ISS_static( 2nd part of the Irule) part to be case-insensitive, keeping others as contant, how to modify the whole Irule in this scenario.
Thanks and Regards Parveez
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