Brad_Baker
Aug 11, 2016Cirrus
Persist based on query string
Our QA team needs a way to specify a backend node via a query string and have all subsequent queries persist to that node for testing purposes.
I have written the following irule which send the request to a specified node - the problem is that associated requests to things like images, javascript, style sheets don't match the irule and thus get sent to a random backend web server:
DESCRIPTION:
This if the URI contains a query parameter named server this irule attempts
to match the server name to a datagroup named servername2ip_datagroup and
use that to send the user to the appropriate back end server.
1) This rule relies on the servername2ip_datagroup datagroup. Which is a
server name to IP datagroup on the load balancer. This needs to be maintained
/ updated as server IPs or names change.
when HTTP_REQUEST {
If the uri contains a query parameter named server
if { [HTTP::uri] contains "server" } {
Define a lowercase variable to store the server name
set webserver [URI::query [string tolower [HTTP::uri]] server]
Define a variable to store the port to make this rule https/http agnostic
set prt [TCP::local_port]
If the server query parameter matches an entry in the datagroup
if { [class match $webserver equals servername2ip_datagroup] } {
Direct traffic to that node.
node [class lookup $webserver servername2ip_datagroup] $prt
}
}
}
I think perhaps I need to add persistence after: node [class lookup $webserver servername2ip_datagroup] $prt
I tried adding persist source_addr 1800
But that's not working. Can any irule guru's out there help me get this working. Is persistence what I need - if so what's wrong with how I'm using it?
Thanks Brad