Forum Discussion
peter_siman
Nimbostratus
May 29, 2011Pool selection based on URI string
Hi,
I have writtend a simple iRule to select particular pool based on what the URI string is. See below the iRule. Unfortunatelly, when applied a following messsages show up in logs.
May 27 13:04:05 local/tmm3 info tmm3[7327]: Rule erimo_pool : Erimo request received
May 27 13:04:05 local/tmm3 info tmm3[7327]: Rule erimo_pool : Erimo request for Aprimo service received. Selecting end server
May 27 13:04:05 local/tmm3 err tmm3[7327]: 01220001:3: TCL error: erimo_pool - Error: No serverside connection established (line 1) invoked from within "IP::server_addr"
iRule:
when HTTP_REQUEST {
log local0. "Erimo request received"
if { [HTTP::path] equals "/AprimoMarketing/login.aspx" } {
log local0. "Erimo request for Aprimo service received. Selecting end server"
pool Node_Web_ESESSMW1432
log local0. "Aprimo end server selected: [IP::server_addr]"
}
else {
pool wam_erimo_pool
log local0. "Aprimo end server selected: [IP::server_addr]"
log local0. "Condition not matched. No Aprimo server selected. Server IP address is: [IP::server_addr]"
}
}
when SERVER_CONNECTED {
log local0. "Connection from[IP::client_addr]:[TCP::client_port] to Aprimo server:[IP::server_addr]:[TCP::server_port] established."
}
Does anyone have any idea what / where the issue might be?
Thanks.
17 Replies
- The_Bhattman
Nimbostratus
Hi Peter,
I believe IP::server_addr only works if you have already established a connection on the serviceside. As a test, if you strip out [IP::server_addr], does it go through w/o errors?
Thanks,
Bhattman - hoolio
Cirrostratus
As Bhattman said, [IP::server_addr] only works after a serverside connection has been established. You can use [LB::server] in the LB_SELECTED event when a load balancing selection has been made to get the selected server info. Or you can use [IP::server_addr] in or after SERVER_CONNECTED.
Also, if you're using this iRule with an IIS-based application, you should set the path to lowercase before doing a comparison as IIS is case-insensitive for the paths:when HTTP_REQUEST { log local0. "Erimo request received" if { [string tolower [HTTP::path]] equals "/aprimomarketing/login.aspx" } { log local0. "Erimo request for Aprimo service received. Selecting end server" pool Node_Web_ESESSMW1432 } else { pool wam_erimo_pool log local0. "Condition not matched. No Aprimo server selected." } } when SERVER_CONNECTED { log local0. "Connection from [IP::client_addr]:[TCP::client_port] to Aprimo server: [IP::server_addr]:[TCP::server_port] established." }
Aaron - Bob_10976
Nimbostratus
I'm trying to do this same thing, however using the code above and modifiy for me doesn't seem to work. I'm running ver 10.2.0 HF1, my code is below:when HTTP_REQUEST { log local0. "McBob request received" if { [string tolower [HTTP::path]] starts_with "/mcbob" } { log local0. "McBob request for service received. Selecting end server" pool secure2.mydomain.com } else { pool secure.mydomain.com log local0. "Condition not matched. No WIN2K8 server selected." } } when SERVER_CONNECTED { log local0. "Connection from [IP::client_addr]:[TCP::client_port] to WIN2K8 server: [IP::server_addr]:[TCP::server_port] established." }
I tried a few varations, in the HTTP:: I tried
HTTP::uri starts_with "/mcbob"
HTTP::uri equals " "
HTTP::path equals "/mcbob/default.html"
HTTP::path starts_with " "
I'm totally lost on what I'm doing wrong. The LTM logs shows no match found and I'm getting a 404 in my browswer so it simply not seeing it. any thoughts on what I'm doing wrong?
Thanks,
Bob - Michael_Yates
Nimbostratus
I tested a slightly modified version of your iRule and it worked fine for me. I think that the 404 that you are getting is an indication that it is working for you as well, but it is not finding the content that you are requesting from the server.
If you are concerned about the actual functionality of the iRule I would suggest doing something like this so that you can narrow down where your issue is. If the redirect work then you know that that portion of your logic is correct and that you need to investigate the server configuration in the pools that you are directing the traffic to, or the content on the server:when HTTP_REQUEST { log local0. "McBob request received" if { [string tolower [HTTP::path]] starts_with "/mcbob" } { log local0. "McBob request for service received. Selecting end server" pool secure2.mydomain.com HTTP::redirect "http://www.google.com" } else { log local0. "Condition not matched. No WIN2K8 server selected." pool secure.mydomain.com HTTP::redirect "http://www.yahoo.com" } } when SERVER_CONNECTED { log local0. "Connection from [IP::client_addr]:[TCP::client_port] to WIN2K8 server: [IP::server_addr]:[TCP::server_port] established." } - Bob_10976
Nimbostratus
Michael...
Thanks for the reply. I tested your suggested above, well the redirect to google.com part anyway and the redirect worked as expected. If I went to secure.mydomain.com/mcbob i was redirected to google.com. So as you mentioned the logic of the rule is working, however I can't seem to figure out why the pool isn't working properly. I know the pool works, we actually have websites that utilize that pool, successfully.
Any other thoughts or suggestions?
Thanks,
Bob - The_Bhattman
Nimbostratus
Hi Bob,
So when you remove from the "pool secure2.mydomain.com" it doesn't work and put a on "HTTP::redirect http://www.google.com" you can't get traffic sent to the pool?
Bhattman - Bob_10976
Nimbostratus
Correct, but only for this Rule. I have every day traffic using the secure2.mydomain.com pool currently. I have no problem accessing websites/applications that use the secure2.mydomain.com pool on a normal day, it only appears that the rule is not working when I attempt to redirect/switch traffic to that pool using this rule.
Thanks,
Bob - The_Bhattman
Nimbostratus
Hi Bob,
What about checking for the host itself? Here is the following using the SWITCH command along with the IF statement.when HTTP_REQUEST { switch -glob [HTTP::host] { "secure2.mydomain.com" { if { [HTTP::path] starts_with "/mcbob" } { log local0. "Accessed when the URL is http://[HTTP::host]/[HTTP::uri]" pool secure2.mydomain.com } "secure.mydomain.com" { log local0. "Accessed when the URL is http://[HTTP::host]/[HTTP::uri]" pool secure.mydomain.com } } } when SERVER_CONNECTED { log local0. "Connection from [IP::client_addr]:[TCP::client_port] to WIN2K8 server: [IP::server_addr]:[TCP::server_port] established." }
Bhattman - Bob_10976
Nimbostratus
When I check the rule I recieve the following errors:
line 1: [parse error: missing close-brace] [{
line 2: [command is not valid in the current scope] [switch -glob [HTTP::host] {
Am I missing something, or could this be an issue with version I'm running?
Thanks,
Bob - The_Bhattman
Nimbostratus
Hi Bob,
Oops. My bad. YOu need an extra bracket
when HTTP_REQUEST {
switch -glob [HTTP::host] {
"secure2.mydomain.com" {
if { [HTTP::path] starts_with "/mcbob" } {
log local0. "Accessed when the URL is http://[HTTP::host]/[HTTP::uri]"
pool secure2.mydomain.com
}
}
"secure.mydomain.com" {
log local0. "Accessed when the URL is http://[HTTP::host]/[HTTP::uri]"
pool secure.mydomain.com
}
}
}
when SERVER_CONNECTED {
log local0. "Connection from [IP::client_addr]:[TCP::client_port] to WIN2K8 server: [IP::server_addr]:[TCP::server_port] established."
}
Bhattman
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects