Forum Discussion
Kai_Wilke
Aug 24, 2017MVP
Hi Wsanders,
you may take a look to the iRule below. It uses an
if { [catch { some code which may fail }] } then { error handle if code has been failed }
syntax, to check if the pool name fetched from your datagroup is valid and if the pool has any active members.
when HTTP_REQUEST {
Getting destination pool name based on HOST and Path
set HOST [ string tolower [HTTP::host] ]
set VALUE "/"
set MYPOOL [ call /Common/LIB-sac-dev::https_rule $HOST $VALUE ]
log local0.debug "HERE: Pool $MYPOOL Host $HOST Value $VALUE"
Checking if pool exists and has any active members.
if { [catch {
Lets try if the code below works (it will if $MYPOOL contains a valid pool name...)
if { [active_members $MYPOOL] == 0 } then {
The pool does exist but has no available members (aka. no TCL error but [active_members] was equal 0)
HTTP::respond 503 content "Pool \"$MYPOOL\" is unavailable" "Connection" "close"
event disable
TCP::close
} else {
The pool does exist and has available members (aka. no TCL error and [active_members] was greater than 0)
pool $MYPOOL
}
}] } then {
Something went wrong with the code above. Seems that the pool does not exist (aka. a TCL runtime error ocoured)
log local0.debug "ErrorInfo: [subst "\$::errorInfo"]"
HTTP::respond 502 content "Bad Gateway - invalid HTTP request" "Connection" "close"
event disable
TCP::close
}
}
Cheers, Kai