Forum Discussion
David_X_20743
Nimbostratus
May 09, 2008LB method setup and post redirect
Hi
I am new to the F5 iRules. I am currently setting up a set of of iRules for a customer and get really lost. So any suggestion will be really appreciated.
The customer wish to setup the F5 to look at the Host HTTP header and if it is
test.test4u.com to balance it round robin style between the two web servers 192.168.1.168 and 192.168.1.132
They also wish the F5 to look at the sysid HTTP Post variable and if this is set to 1, send the traffic to 192.168.1.168, if set to 2 send the traffic to .132 if it is not set then balance in the normal way. This is set when a user pages inside the results, and it uses the web server memory cache so it needs to go the same server that produced the result set.
I wrote the following iRules, but it does not seem to be working
when HTTP_REQUEST {
if { [HTTP::header "HOST"] contains "test.test4u.com" } {
LB::mode roundrobin
}
if { [HTTP::method] eq "POST" } {
if {[HTTP::header names] contains "sysid=1" } {
node 192.168.1.168 80
}
if {[HTTP::header names] contains "sysid=2" } {
node 192.168.1.132 80
}
}
}
Thank you
2 Replies
- hoolio
Cirrostratus
The post data parameter and parameter value wouldn't be accessible in an HTTP header. You'd need to collect the HTTP payload and then see if there is a sysid parameter. I think this will do what you're looking for. To use it, add a default pool to the VIP containing both nodes. If you run into issues, check the debug logging in /var/log/ltm. When you're done testing, you can comment out the log statements to save CPU/disk resources.when HTTP_REQUEST { Check if the request is a POST if {[HTTP::method] eq "POST"}{ log local0. "[IP::client_addr]:[TCP::client_port]: POST request to [HTTP::uri]" Collect the request data if { [HTTP::header exists "Content-Length"] } { Collect the content length as specified in the C-L header set content_length [HTTP::header "Content-Length"] } else { Collect up to 1 Mib set content_length 1000000000 } log local0. "[IP::client_addr]:[TCP::client_port]: collecting $content_length bytes" Trigger the collection of the request data if the content length isn't 0 if {$content_length}{ HTTP::collect $content_length } } } when HTTP_REQUEST_DATA { log local0. "[IP::client_addr]:[TCP::client_port]: payload: [HTTP::payload]" switch -glob [HTTP::payload] { *sysid=1* { Send the request to node 1 node 192.168.1.168 80 log local0. "[IP::client_addr]:[TCP::client_port]: found sysid=1, using node 1" } *sysid=2* { Send the request to node 2 node 192.168.1.132 80 log local0. "[IP::client_addr]:[TCP::client_port]: found sysid=2, using node 2" } default { Didn't find an expected sysid, do nothing. Use the default pool on the VIP. log local0. "[IP::client_addr]:[TCP::client_port]: didn't find sysid" } } }
- Randy_Johnson_1
Nimbostratus
Aaron -http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&postid=57319&view=topic
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