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
Let me tackle the easy part - mapping the virtual name into a pool name;
Choose pool base on virtual name, checking for an error if {[catch {pool [string map {"www." "pool-" "HTTPS" "HTTP"} [virtual]]}]} { log local0. "pool [string map {"www." "pool-" "HTTPS" "HTTP"} [virtual]] not configured" }
Unfortunately I cannot quite understand what it is you want to do with the data-group. They are simple but I am somewhat confused by the explanation above.
- Parveez_70209Nimbostratus
Hi,
Please allow me to explain this again:
- Basically idea is to apply a single Irule into all the 120 Virtual-servers(60 HTTP+ 60 HTTPS), Which will intelligently identify whether it should go to Static page("/iss_static") or if thats not matching , it will go to /SEUILibrary/ which is for Dynamic Page content. : sample HTTP Irule which is currently attached to all HTTP Virtual-servers is pasted below again:
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
}
}
-
So, as per the requirement the new Irule not only identifies the static and dynamic content of the page but also it will identify which pool it should go when it hit the Virtual-server by seeing its name) by using Data-groups or Class groups.
-
Ist part:will remain constant
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 "http:www.lenovo.com pool lenovo.com
log local0. "redirected from /"
return
2nd part: trying to get assistance :
a) if we can use Data-groups here which will easily identify the "/iss_static" for static page requirement or else dynamic page requirement(/SEUILibrary/) which is shown by else statement when it is marked to some pool: b) In 2nd part manual pool selection will go off and wanted assistance to replace the same with some kind of class-maps or Data-groups. c) The idea is to easy Management.
} elseif { $https_uri starts_with "/iss_static" } {
log local0. "matched /iss_static"
pool pool_confarmct.leni2.com_http
log local0. "pool_confarmct.leni2.com_http defined, [LB::server pool] selected" return
} else {
log local0. "no match for rev. close connection" pool pool_apbuild.leni2.com_http
}
}
Thanks and Regards Parveez
- IheartF5_45022Nacreous
Explanation still confusing to me but here's one more go - I hope it helps!
switch -glob [HTTP::uri] { "/" { Do something - but don't do a redirect followed by a pool selection!! Will break!! HTTP::redirect "https://parveez.com" pool parveez.com } "/iss_static*" { Choose a static pool matching to this virtual pool [class match -element [string tolower [virtual]] starts_with dg_static_pools] return } default { Choose a dynamic pool matching to this virtual pool [class match -element [string tolower [virtual]] starts_with dg_dynamic_pools] return } }
Where both dg_dynamic_pools and dg_static_pools are datagroups containing key/value pairs of /.
NB1. The iRule will need some modification for v11 - should work v10
NB2. As comment says, you shouldn't do an HTTP::redirect followed by a pool selection
- Parveez_70209Nimbostratus
Lets take 3 examples of the Virtual-servers and with Pool"
a) apuat.leni2.com-VS-HTTP : pool_apuat_leni2.com_http b) apbuild.leni2.com-VS-HTTP : pool_apbuild.leni2.com_http c) apctdev.leni2.com-VS-HTTP : pool_apctdev.leni2.com_http
In every setup we have the respective Irules:
a) apuat.leni2.com-VS-HTTP : pool_apuat_leni2.com_http
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 http_uri [string tolower [HTTP::uri]] log local0. "requested [HTTP::uri]" if {$https_uri equals "/" } { HTTP::redirect "http://www.parveez.com" pool pool_parveez.com-http log local0. "redirected from /"
return } elseif { $http_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 { $http_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}
}
=======================
b) apbuild.leni2.com-VS-HTTP : pool_apbuild.leni2.com_http
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://www.parveez.com" pool pool_www.parveez.com-http
log local0. "redirected from /"
return } elseif { $https_uri starts_with "/iss_static" } {
log local0. "matched /iss_static"
pool pool_confarmct.leni2.com_http
log local0. "pool_confarmct.leni2.com_http defined, [LB::server pool] selected" return
} else {
log local0. "no match for rev. close connection" pool pool_apbuild.leni2.com_http
}
}
c) apctdev.leni2.com-VS-HTTP : pool_apctdev.leni2.com_http
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 http_uri [string tolower [HTTP::uri]] log local0. "requested [HTTP::uri]" if {$http_uri equals "/" } { HTTP::redirect "http://www.parveez.com" pool pool_parveez.com_http log local0. "redirected from /"
return } elseif { $http_uri starts_with "/iss_static" } {
log local0. "matched /iss_static"
pool pool_confarmct.leni2.com_http
log local0. "pool_confarmct.leni2.com_http defined, [LB::server pool] selected" return
} elseif { $http_uri starts_with "/" } { pool pool_apctdev.leni2.com_http return
} }
Yes you are close, but wanted to mention the below points:
- If you review the HTTP Profile Irules, we have much in common and we have different pools mentioned into the irule with respect to Virtual-server too, so in place of that we wanted to have a class-group/Data-group.
- So, when a user hit the Virtual-server, the request will check whether it need the static page mentioned by "/iss_static" or to the dynamic page content mentioned in else statement and than to respective pools, but this time not with manual pool we need to specify, we need to specify with the Data-group.
- We want to keep constant the pool marked against iss_static , only we wanted to keep Data-group for the pools mapped against the Else statement( the pool where the traafic will go when it dont match iss_static)
- And for future if any new request comes,apart from Virtual-server creation, we just attach the irule which contains the Data-group which contains all the pool information into that,and in that Data-group we will just add the new pool, so this is to eliminate maximum ofhuman error and operationally also this will be great.
- Can you please assist into this by taking the example of the Three Virtual-Servers:
Example:
a) Virtual-server : apuat.leni2.com-VS-HTTP , Pool : pool_apuat_leni2.com_http b) Virtual-server : apbuild.leni2.com-VS-HTTP , Pool : pool_apbuild.leni2.com_http c) Virtual-server : apctdev.leni2.com-VS-HTTP , Pool : pool_apctdev.leni2.com_http
Thanks and Regards Parveez
- IheartF5_45022Nacreous
Parveez,
I'm still confused as the poolnames chosen for the /iss_static path are all different and you say "3.We want to keep constant the pool marked against iss_static", however as far as the a/b/c examples immediately above, if your naming standard is consistent and as you show above, then I don't think you need a data-group at all to map from your virtual name to your pool name. You can just use the following;-
if {[catch {pool "pool_[string map {"-VS-HTTP" "_http" } [virtual]]}]} { log local0. "pool [string map {"www." "pool-" } [virtual]] not configured" }
By the way;-
elseif { $http_uri starts_with "/" }
is ALWAYS going to evaluate to 1 as all paths start with "/".
- Parveez_70209Nimbostratus
Hi Sir,
Thank you for your reply, was waiting for your suggestion.
-
Ok for /iss_static content, as thats for static page content, thats why we planned to keep that as it is. So, we have only 3 pools which is serving these static content pages, so as an alternative, we will write some additional irule and attach with the Virtual-servers.
-
For dynamic part , yes Sir client is always wanted to have a data-group, so thats pools will go inside that group, and next time when a new Virtual-server request come, we just need to add the new pool into that Data-group, and wanted the Virtual-Server to recognize its pool from the Data-Group.(by name as naming convention is same in Virtual-server and in Pool).
-
Sir, do you need to create String Data-group, where we need to add all those Pools together there ?
-
And please assist in guiding the full example Irule including Data-group part as I was getting syntax error while using switch -glob command suggested by you earlier.
Thanks and Regards Parveez
-
- Parveez_70209Nimbostratus
A. And secondly yes Sir, even for /iss_static page, there are different pools( 2-3 pools only) but problem is the naming convention is not matching with the Virtual-server, so don't know how to send the traffic to the right pool. So, that's why don't why how can we put that in Data-group.
B. So, lets say we have 3 pools for /iss_static page : a) pool_confarmct.leni2.com_http b) pool_confarmsp.leni2.com_http c) pool_confarmap.leni2.com_http
C. So, plan is to make a manual list against all the Virtual-servers created and to note the current static pool mapped, and based on that we will create 3 Irules which will contain Data-Groups containing pools for Dynamic pages also.
Means Ist Irule with pool_confarmct.leni2.com_http for /Iss_static and with Data-Group for Dynamic Pages.
2nd Irule with pool_confarmsp.leni2.com_http for /Iss_static and with Data-Group for Dynamic Pages.
3rd Irule with pool_confarmap.leni2.com_http for /Iss_static and with Data-Group for Dynamic Pages.
So, that next time any new Virtual-server we need to create, we just add the new pool name into the Data-Group for Dynamic content and keeping in mind the specific pool for /iss_static, we would call that particular Irule.
with these inputs, kindly assist me in writing or adjusting the full irule as per our requirement:
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 http_uri [string tolower [HTTP::uri]] log local0. "requested [HTTP::uri]" if {$https_uri equals "/" } { HTTP::redirect "http://www.parveez.com" pool pool_parveez.com-http log local0. "redirected from /"
return } elseif { $http_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 { $http_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
Syntax should be correct - I saved it on my F5 OK, however to create your datagroup before you try to save the iRule - I am assuming you are using v10?
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" } } } save
Then here is the iRule - you will need to update the line "pool $static_pool" yourself;
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 /" HTTP::redirect "http://www.parveez.com" return pool pool_parveez.com-http } "/iss_static*" { pool $static_pool return } default { pool [class match -element [string tolower [virtual]] starts_with dg_parveez_dynamic_pools ] return } } }
Good luck and have a nice weekend - I am off now!!
- Parveez_70209Nimbostratus
Sir, thank you so much.. very greatful to you.
And one last query :: I am using String Data-Groip correct for dg_parveez_dynamic_pools ?
And we need to add all the exact pool names into the Data-group right Sir ?
Thanks and Regards Parveez
- Parveez_70209Nimbostratus
HI Sir,
I am getting error and response back is not coming: In the below Irule, I gave static pool name inplace of command $static_pool
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 /" HTTP::redirect "http://www.parveez.com" return pool pool_parveez.com-http } "/iss_static*" { pool $static_pool return } default { pool [class match virtual]] starts_with dg_parveez_dynamic_pools ] return } }
}
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