Forum Discussion
EBS_Support_258
Dec 25, 2008Nimbostratus
Can I use irule to change uri based on selected pool member ?
Hello,
I have 4 nodes as pool members
192.168.9.179,192.168.9.180,192.168.9.181,192.168.9.182
and 1 Virtual Server 192.168.9.199
When client use the...
hooleylist
Dec 29, 2008Cirrostratus
Hi,
By default, the pool member is selected in the LB_SELECTED event. You can modify the URI from the HTTP_REQUEST_SEND event using the clientside command (Click here) to call HTTP::uri. HTTP_REQUEST_SEND is a serverside event triggered after the TCP connection to the node is established just before the HTTP request is sent to the pool member. You have to use the clientside command to force evaluation of the HTTP::uri command in the clientside context.
Is the param value the virtual server IP address or a name? Will that value always be the same? If it will always be the same, you could hardcode $my_param_value_orig to it instead of getting the value from the request.
Here is an example which gets the my_param value from every request and rewrites the URI based on the selected server.
when HTTP_REQUEST_SEND {
Parse the parameter value for my_param
set my_param_value_orig [URI::query [clientside {HTTP::uri}] "my_param"]
Check if the requested URI contains the parameter (called my_param in this example) to replace
if {[string length $my_param_value_orig]}{
Get the alias based on the selected server
switch [IP::server_addr] {
"192.168.9.179" { set my_param_value_new "server1"}
"192.168.9.180" { set my_param_value_new "server2"}
"192.168.9.181" { set my_param_value_new "server3"}
"192.168.9.182" { set my_param_value_new "server4"}
default {
Take some default action?
}
}
Replace the my_param value with the selected node alias
clientside {HTTP::uri [string map "$my_param_value_orig $my_param_value_new" [clientside {HTTP::uri}]]}
}
}
The switch statement does a string comparison of the server IP address against the list of IP's. It might be more efficient to replace the switch statement with multiple IP::addr checks:
if {[IP::addr [IP::server_addr] equals 192.168.9.179]}{
set my_param_value_new "server1"
} elseif {[IP::addr [IP::server_addr] equals 192.168.9.180]}{
set my_param_value_new "server2"
...
Or you could create a string class containing the server IP address and the alias and then use findclass (Click here) to get the alias:
class my_server_aliases {
"192.168.9.179 server1",
"192.168.9.180 server2",
"192.168.9.181 server3",
"192.168.9.182 server4",
}
Aaron
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