Simon_83666
Jan 12, 2009Nimbostratus
LB::reselect based on HTTP response code
Hi,
I've created the following irule in trying to direct the http traffic from one node to another if a 5xx http response is encountered, however, it seems the request wuold always go back to the original node agaian. There are only 2 nodes in the pool and I'm using a cook-insert profile to persist the connection.
I'm sure there's a simple explanation to the issue but since I don't have much experience with iRule, any help is appreciated.
Thanks
when CLIENT_ACCEPTED {
set retries 0
}
when HTTP_REQUEST {
set client_ip [IP::client_addr]
set http_method [HTTP::method]
set http_host [HTTP::host]
set http_uri [HTTP::uri]
set http_request [HTTP::request]
}
when HTTP_RESPONSE {
set http_status [HTTP::status]
if { [matchclass $http_status equals $::ebus_dg_http_error_code] } {
incr retries
log local0. "$http_status error caught: retry $retries out of 10, Client IP - $client_ip , $http_method $http_host$http_uri"
if { $retries < 10 } {
HTTP::retry $http_request
}
}
}
when LB_FAILED {
set current_server [LB::server name]
log local0. "$current_server seems to be having a problem..."
log local0. "HTTP request is $http_request"
}
when LB_SELECTED {
if { $retries >= 1 } {
set current_pool [LB::server pool]
LB::mode rr
LB::reselect pool $current_pool
log local0. "Reselected: LB_server is [LB::server name]"
}
}