Forum Discussion

EBS_Support_258's avatar
EBS_Support_258
Icon for Nimbostratus rankNimbostratus
Dec 25, 2008

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 application, URL for this application is

 

http://192.168.9.199/report/report.php?param=vserver

 

 

Then F5 will load balance this traffic to 4 pool members in Round Robin algorithm.

 

 

The question is : after load balancing, this HTTP request have to change it's URI depend on selected pool member

 

 

if go to pool member 192.168.9.179, the uri have to change to http://192.168.9.179/report/report.php?param=server1

 

 

if go to pool member 192.168.9.180, the uri have to change to http://192.168.9.180/report/report.php?param=server2

 

 

if go to pool member 192.168.9.181, the uri have to change to http://192.168.9.181/report/report.php?param=server3

 

 

if go to pool member 192.168.9.182, the uri have to change to http://192.168.9.182/report/report.php?param=server4

 

 

How can I use irule to match this requirement ?

 

 

Thanks,

1 Reply

  • 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