Forum Discussion
naladar_65658
Altostratus
Sep 09, 2008Can you refer to a data group from within a switch?
Is it possible to refer to a data group from within a switch? Also, a big thank you to Joe for helping me get this far! You guys are awesome. I have only been at this about a week, but I have learn...
hoolio
Cirrostratus
Sep 09, 2008I 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"
}
AaronHelp 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