Forum Discussion
Help with iRule to route by host header to pool
Hello, I am trying to save public IPs with an iRule by using the hostname and mapping it to the pool. The rule came from here but I can't find the original thread but it seems to work but I wanted to make sure it is the most efficient way to do it.
- DannyG
Nimbostratus
Thanks for the help in advance!
The datagroup will be string and be formated like hostname:poolname
when HTTP_REQUEST { test_dg is a string data-group where the entries are name:value pairs name is the requested HTTP host header, value is the associated pool-name check the requested HTTP host header against entries in data-group if { [class match [string tolower [HTTP::host]] equals test_dg ] } { if the HTTP host header is in datagroup send the request to the pool associated with the datagroup entry pool [class match -value [string tolower [HTTP::host]] equals test_dg ] } else { drop the request if the host header is not in datagroup drop } }
- Leonardo_Souza
Cirrocumulus
Looks good to me, there is very little to optimize here.
Reading directly from a variable like [HTTP::host] is faster than setting the value in a variable and read that variable after. However, in this case, you are also using the string tolower twice, so not sure if there will be any improvement.
when HTTP_REQUEST { test_dg is a string data-group where the entries are name:value pairs name is the requested HTTP host header, value is the associated pool-name check the requested HTTP host header against entries in data-group set host [string tolower [HTTP::host]] if { [class match $host equals test_dg ] } { if the HTTP host header is in datagroup send the request to the pool associated with the datagroup entry pool [class match -value $host equals test_dg ] } else { drop the request if the host header is not in datagroup drop } }
Have a look in this link about testing the speed of the iRule.
https://devcentral.f5.com/articles/irules-optimization-101-05-evaluating-irule-performance
If you want to read the full article:
https://devcentral.f5.com/articles/irules-optimization-101-01-if-elseif-and-switch
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