Forum Discussion
iRule for setting pool based on URI path
Hello,
I know it's possible to set a pool based on the URI path. But what I need to do past that is a bit more complex, and I'm not sure where to begin.
I have two pools I'm testing with:
preprod.domain.com preprodtr.domain.com
I want to direct a request to the proper pool based on the /path
So if preprod.domain.com/tr is requested the request is routed to the pool preprodtr.domain.com
So this I think would be pretty easy if hardcoded. However, I cannot hardcode it since *tr.domain.com is dynamic. That is, I have many pools that could be *tr.domain.com not just the example preprodtr.domain.com
So what I need to be able to do is if the F5 sees the request *.domain.com/tr requested, it finds {host}tr.domain.com
Anyone have any ideas?
Thank you!
10 Replies
- Brad_Parker_139
Nacreous
Try this, it will check to see if you have a pool created that matches the http hostname_pool and if not go to your default pool. If it does it will go to the corresponding pool.
when HTTP_REQUEST { if { [getfield [HTTP::host] "." 1] ends_with "tr"}{ if { [catch {pool [string tolower "[HTTP::host]_pool"]}] }{ pool "default_pool" } else { pool [string tolower "[HTTP::host]_pool"] } } }Updated.
- Brad_Parker_139
Nacreous
probably throw a string to lower in there in case someone requests with caps, when HTTP_REQUEST { if { [catch {pool [string tolower "[HTTP::host]_pool"]}] }{ pool "default_pool" } else { pool [string tolower "[HTTP::host]_pool"] } } - Brad_Parker_139
Nacreous
This will not satisfy the problem posed.
- Brad_Parker
Cirrus
Try this, it will check to see if you have a pool created that matches the http hostname_pool and if not go to your default pool. If it does it will go to the corresponding pool.
when HTTP_REQUEST { if { [getfield [HTTP::host] "." 1] ends_with "tr"}{ if { [catch {pool [string tolower "[HTTP::host]_pool"]}] }{ pool "default_pool" } else { pool [string tolower "[HTTP::host]_pool"] } } }Updated.
- Brad_Parker
Cirrus
probably throw a string to lower in there in case someone requests with caps, when HTTP_REQUEST { if { [catch {pool [string tolower "[HTTP::host]_pool"]}] }{ pool "default_pool" } else { pool [string tolower "[HTTP::host]_pool"] } } - Brad_Parker
Cirrus
This will not satisfy the problem posed.
- dr_tamfr_dhp_19
Nimbostratus
Hmmm, I'm not using default pools which I assume is why I got the error that it doesn't know what the default_pool is.
Also however, I don't see any thing in that logic that is looking for the "tr" delineation.
- Brad_Parker
Cirrus
you will have to define what you default pool is or if you want to just reject traffic that doesn't match a pool you've created. I will update the rule above to account for tr.
- arpydays
Nimbostratus
I'm may have the misunderstood but this will to route to pool prepended with hostname if the uri starts with /tr
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/tr" } { scan [HTTP::host] {%[^.]} host_pool pool ${host_pool}tr.domain.com } } - arpydays
Nimbostratus
You have the getfield string and split round the wrong way 🙂 but the getfield option looks good;
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/tr" } { pool [getfield [HTTP::host] "." 1 ]tr.example.com } }
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