Forum Discussion
hooleylist
Sep 09, 2008Cirrostratus
I think a switch and an if/elseif/else chain are pretty close in terms of efficiency. It might be better to have a single datagroup with the URI tokens followed by the corresponding pool. If you need to support wildcards in the class, you can use foreach instead of findclass.
Here is a sample class:
class paths_pool_class {
"/path1* pool2"
"/path2/test* pool2"
"/path3/ pool1"
}
You could then use a foreach loop to find a matching line in the class. If you parse the second field in the line, you could then specify the pool. There is an example of using foreach and string match to do wildcard matching (Click here). You can use getfield to parse the pool name (Click here).
when HTTP_REQUEST {
Check the requested path against the paths pool class
foreach element $::paths_pool_class {
log local0. "Current \$element: $element"
if {[string match -nocase $element [HTTP::path]]}{
log local0. "Matched \$element: $element. Exiting loop"
break
}
set parsed_pool [getfield $element " " 2]
log local0. "\$parsed_pool: $parsed_pool"
Check if parsed pool is up
if {[active_members $parsed_pool]}{
log local0. "pool $parsed_pool has active members"
pool $parsed_pool
} else {
Take some default action if the parsed pool is down?
HTTP::redirect "http://maintenance.example.com"
}
}
}
I'm not sure if the active_members command will kick out a TCL error if the pool doesn't exist. If it does, you might want to use catch to trap the error. You can use something like this to do so:
if {[catch {active_members $parsed_pool} result]}{
There was an error
log local0. "Error. Catch result: $result"
} else {
log local0. "OK. Catch result: $result"
}
Aaron