Forum Discussion
VS with Wildcard Pool set path to specific port
Good Day -
Today we have a Virtual Server listening on port 443, and an irule with 300+ lines to switch pool based on the path. Example of current irule is below:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::path]] {
"/site1/score/sap/wbse/search" { pool pool_site1.test.com_34561 }
"/site1/score/sap/companycodes" { pool pool_site1.test.com_34561 }
"/site2/score/timekeeper/unionmasterdata/contract" { pool pool_site2.test.com_34562 }
"/site2/score/timekeeper/unionmasterdata/jobcode" { pool pool_site2.test.com_34562 }
"/site3/score/sap/chartofaccounts/glaccount*" { pool pool_site3.test.com_34563 }
"/site3/score/timekeeper/timecard/gettimecard" { pool pool_site3.test.com_34563 }
default {
pool pool_site0.test.com_33333
}
}
}
So the above irule goes on for over 300+ more lines.
Here is the problem with this:
Above setup we are creating over 200+ individual pools of servers with the same 5 servers but just on different ports.
Original reason for all the pools is not every port would be up all the time so in the beginning it was simple just to create a pool, but now this is getting un-managable.
What I would like to do is the following:
Since all the servers in the over 200+ pools are exactly the same but only on a different port I would like to create a wildcard pool instead with just the 5 servers in them.
pool pool_site0.test.com
member server0.test.com:0
member server1.test.com:0
member server2.test.com:0
member server3.test.com:0
member server4.test.com:0
Move the path / destination port into a Data group and create an iRule that will match the path then check if the server in the wildcard pool responds to the port and if so then send the request to that server.
So requesting assistance on creating an irule that:
- Read the path on the incoming request
- Match path in datagroup and map destination port based on path matched in datagroup
- Check if the servers in the wildcard server pool responds on the port matched
- if port responds on server, then send request to server that responds.
Any assistance would be appreciated.
Thx
Rich
- spalandeNacreous
Create datagroup (uri_to_port) for uri to port mapping
ltm data-group internal /Common/uri_to_port { records { "/service1" { data "7070" } "/service2" { data "8080" } "/service3" { data "9090" } } type string }
create app_pool with pool members with wildcard port and then use below iRule
when HTTP_REQUEST { # Default port if not found in data group set port_number 443 # Get the URI path set uri_path [HTTP::path] # Lookup the port number in the data group set port_number [class lookup $uri_path /Common/uri_to_port] # optional logging log local0. "Routing to port $port_number based on URI $uri_path" # Get the list of pool members set pool_members [members -list app_pool] # Initialize a flag to indicate if a node is selected set node_selected 0 # Iterate through pool members to find an active one on the specific port foreach member $pool_members { # Extract the IP address from the member string set ip [lindex [split $member ":"] 0] # Check if the node is active on the specified port if {[active_members -node "$ip:$port_number"] > 0} { # Node is active set selected_member "$ip:$port_number" set node_selected 1 break } } # Check if a node was selected if {$node_selected} { #optional logging log local0. "Selected member: $selected_member" # Use the node command to forward traffic to the specific server and port node $selected_member } else { # No active members found, respond 503 HTTP::respond 503 content "Service Unavailable" } }
PS - This isn't tested iRule. Please test in non-prod environment before proceeding to PROD.
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