Forum Discussion
Edgar_Palamarch
Nimbostratus
Nov 06, 2015Dynamic Pools and 'CATCH'
We are trying to implement a CATCH statement in an iRule that directs traffic to different pools depending on URI. The names of the pools are taken from the URI. If no such pool exists, requests are ...
cjunior
Nacreous
Nov 12, 2015Hi Edgar, This test script was slightly harder than I expected :) but, it maybe works for you.
Regardswhen CLIENT_ACCEPTED {
set default_pool [LB::server pool]
}
when HTTP_REQUEST {
log local0. " Requesting URI: [HTTP::uri]"
Check if is a complete path (e.g. /path/resource, /path/path/resource, ...)
if { [URI::path [HTTP::uri] depth] > 0 } {
set firstPath [findstr [HTTP::uri] "/" 1 "/"]
Check if is a possible path (e.g. /path or /resource - discards root and /resource.ext )
} elseif { [HTTP::uri] ne "/" and not [string match "*.*" [HTTP::uri]] } {
set firstPath [string range [HTTP::uri] 1 end]
Set to default pool
} else {
log local0. " Request to default pool $default_pool"
pool $default_pool
return
}
log local0. " First path: $firstPath | URI path: [URI::path [HTTP::uri]]"
set newpool "${firstPath}_443.pool"
log local0. " Try pool: $newpool / Catch pool: $default_pool"
if { [catch { pool $newpool }] } {
log local0. "ERROR: Attempting to assign traffic to non-existent pool $newpool"
log local0. "ERROR: switching to default pool $default_pool"
pool $default_pool
} else {
Remove pool path from uri
set uri [string range [HTTP::uri] [expr [string len $firstPath]+1] end]
if { $uri eq "" } {
set uri "/"
}
HTTP::uri $uri
log local0. " Selected pool: $newpool | Request URI: [HTTP::uri]"
unset uri
}
unset firstPath newpool
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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