Jeff_Giroux
Nov 01, 2014Cirrus
Reselect Pool Member Based on HTTP Response Payload
I need to check the response payload for a certain string. If the string is found, then try the next pool member. This works in the current draft. Is there anything that will make it cleaner, more efficient?
- Triggered on GET requests only
- Search response http payload for "Correlation ID for Node"
-
Reselect pool member if string is found
when CLIENT_ACCEPTED { On each new TCP connection track that we have not retried a request yet set retries 0 set default_pool [LB::server pool] } when HTTP_REQUEST { Only save the request headers if this is not a retried request set uri [HTTP::uri] if { [HTTP::method] eq "GET" && $retries == 0 }{ set request_headers [HTTP::request] } } when LB_SELECTED { Select a new pool member if we are retrying this request if { $retries > 0 } { LB::reselect } } when HTTP_RESPONSE { Inspect data log -noname local0. "[LB::server addr] -- $uri" if { [HTTP::header exists "Content-Length"] } { HTTP::collect [HTTP::header "Content-Length"] } } when HTTP_RESPONSE_DATA { do stuff with the payload if { [HTTP::payload] contains "Correlation ID for Node" } { Server error, retry with remaining pool members incr retries log -noname local0. "ID logged: retry $retries out of [active_members $default_pool]" if { $retries < [active_members $default_pool] } { Retry this request HTTP::retry $request_headers Exit this event from this iRule so we do not reset retries to 0 return } } If we are still in the rule we are not retrying this request set retries 0 HTTP::release }