Forum Discussion
Jason_Hook_4092
Nimbostratus
Dec 03, 2009Looking for peer review on a "simple" iRule
We have a need to direct traffic to different pools based on a header value.
We have a string data group called SysPools with the following entries (here's a couple for example):
001 TTSHE-SysG
013 TTSHE-SysO
015 TTSHE-SysO
030 TTSHE-SysB
This is the iRule on the VIP:
when HTTP_REQUEST {
Set the default target pool
set defaultTarget "TTSHE-SysD"
if {[HTTP::header exists "BETAFirm"]} {
Set $firm to the value of the header
set firm [HTTP::header "BETAFirm"]
log local0.info "Set Firm to $firm"
Set $target to the pool name from the lookup table
set target [findclass $firm $::SysPools " "]
log local0.info "Set Target to $target"
check for a mismatch resulting in a blank pool name and set to default if blank
if { $target eq "" }{
log local0.info "Setting Target to default $defaultTarget"
set target $::defaultTarget
}
Forward request to the set pool
log local0.info "Forwarding request to pool $target"
pool $target
} else {
No Header found...send to default pool
log local0.info "No Header...Forwarding to default pool $defaultTarget"
pool $defaultTarget
}
}
Comments? I'm looking for a few comments to find out if this is the "best" way to accomplish what I'm trying to do. Is this efficient? Is there a different/better way?
Any/all comments are welcome.
Thank you!
Jason
- hoolio
Cirrostratus
Hi Jason, - Jason_Hook_4092
Nimbostratus
So I can simply change it to this: - hoolio
Cirrostratus
Yep. Or you could use the new class (Click here) command. findclass has been deprecated in v10, but will still work in current 10.x versions. - Jason_Hook_4092
Nimbostratus
Maybe I'm just reading the Wiki incorrectly, but I change the look up line to: - Jason_Hook_4092
Nimbostratus
I think I have it...when HTTP_REQUEST { Set the default target pool set defaultTarget "TTSHE-SysD" if {[HTTP::header exists "BETAFirm"]} { Set $firm to the value of the header set firm [HTTP::header "BETAFirm"] log local0.info "Set Firm to $firm" Set $target to the pool name from the lookup table set pair [class search -name SysPools starts_with $firm] log local0.info "Returned '$pair' pair from search" set target [getfield $pair " " 2] log local0.info "Set Target to '$target' from table" check for a mismatch resulting in a blank pool name and set to default if blank if { $target eq "" }{ log local0.info "Setting Target to default $defaultTarget" set target $::defaultTarget } Forward request to the set pool log local0.info "Forwarding request to pool $target" pool $target } else { No Header found...send to default pool log local0.info "No Header...Forwarding to default pool $defaultTarget" pool $defaultTarget } }
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