Forum Discussion
irule not being executed
Hi,
I have an HTTP_REQUEST irule which if a hostname contains a certain URL, it will go to a specified pool. We have it set for 2 hostnames at the moment:
when HTTP_REQUEST { set hostname [string tolower [HTTP::host]] set requestURI [string tolower [HTTP::uri]] if {$hostname contains "xxx.xxx.xxx/xxx" } { pool POOL-XXX } if {$hostname contains "yyy.yyy.yyy/yyy" } {pool POOL-YYY } }
The default pool on the virtual server is set to POOL-XXX however when I run the hostname containing yyy.yyy.yyy/yyy, it still sends it to POOL-XXX. It appears to be ignoring the contents of the irule and using the default pool specified in the virtual server. This irule has worked for a similar application so I'm not sure why it's not working at the moment unless it's an issue with the actual hostname being specified?
Any ideas why this might be happening? Is there anyway to view how the irule is processing? I can see from the statistics that the irule is being executed.
Thanks in advance.
6 Replies
Unfortunately I cannot help you with pools (it looks good by itself). Maybe a little help from another side: log data during development phase, use e.g.
log local0.err "This is the host uri: [HTTP::uri] or ${my_variable}"you could see the log output in the admin console, but fastest way is to log into the console nad tail
tail -F /var/log/ltmstill - I assume your issue may be in the evaluating (comparing) the values, so no condition is met and default pool is used.
Good luck g.
- ucirl_161922
Nimbostratus
Thanks Gabriel. I will try the log. I did suspect it might be an issue that the values arent being met so hopefully I will see something in the log.
- ucirl_161922
Nimbostratus
Hi, I added the log local.err to the irule and am getting the following output when I browse to : https://xxx.xxx.xxx/xxx
Jul 24 10:43:33 lkds-bigip-1 err tmm3[11524]: Rule /Common/PROJ-SS-Selection : This is the host uri: /xxx
From this it doesnt appear to meet the condition. It is seeing /xxx rather than xxx.xxx.xxx/xxx. I have changed the rule to if {$hostname contains "/xxx" } { pool POOL-XXX } but it still doesnt work. I'm not very familiar with irule logging so I'm not really sure what that actually means? Any help would be much appreciated.
Thanks in advance.
- Kevin_Stewart
Employee
The biggest issue I see is the conditional matching. The [HTTP::host] command returns the Host header value in the request URL (ex. www.domain.com), while the [HTTP::uri] command returns the URI portion of the URL (ex. /xxx). Your evaluation is trying to match the host name to both the host and the URI, which would never work. An example workaround might look like this:
when HTTP_REQUEST { if { ( [string tolower [HTTP::host]] equals "xxx.xxx.xxx" ) and ( [string tolower [HTTP::uri]] starts_with "/xxx" ) } { pool POOL-XXX } elseif { ( [string tolower [HTTP::host]] equals "yyy.yyy.yyy" ) and ( [string tolower [HTTP::uri]] starts_with "/yyy" ) } { pool POOL-YYY } }The above should work, but it also does present a problem. What if the host is xxx.xxx.xxx and the URI is not /xxx? You should attempt to account for all of the possible ways that a client can make a request. Example:
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "xxx.xxx.xxx" { if { [string tolower [HTTP::uri]] starts_with "/xxx" } { pool POOL-XXX } else { ...what to do if the URI isn't /xxx? } } "yyy.yyy.yyy" { if { [string tolower [HTTP::uri]] starts_with "/yyy" } { pool POOL-YYY } else { ...what to do if the URI isn't /yyy? } } default { ...what to do if the Host is neither of the above? drop? } } } - ucirl_161922
Nimbostratus
Hi, Just to update. I'm only new to irules and irule logging so I'm learning as I go so forgive me for above misunderstanding. I think I misunderstood what a URI actually meant. I have since modified the irule to check the requestURI rather than the hostname and it now works. I added in a log to check what the actual hostname was. It was xxx.xxx.xxx therefore I deduced it wasnt meeting the condition so changed it to requestURI. It is now working as expected. Thanks so much Gabriel V. You pointed me in the right direction.
- ucirl_161922
Nimbostratus
Hi Kevin,
Only seeing your message after I posted above. I actually changed it to
if {requestURI contains '/xxx' } {pool POOL-xxx }
and it now appears to work. The hostname would always be the same but the URI could be different.
Thanks for your response.
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