Forum Discussion
Irule with elseif and pool selection
Hello,
I'm trying to write an irule that routes traffic to a specific pool based on the host. I think I'm fairly close, but I can't figure out the following error:
01070151:3: Rule [test-pool-selection] error: line 5: [undefined procedure: elseif] [elseif]
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
if { [HTTP::host] starts_with "abc" } {
pool ss-devsp3-pool
} elseif { [HTTP::host] starts_with "def" } {
pool ss-devsp3-pool-81
} elseif { [HTTP::host] starts_with "ghi" } {
pool ss-devsp3-pool-82
} }
}
- Kevin_StewartEmployee
You're using an if/elseif structure inside a switch conditional. Try this:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "abc*" { pool ss-devsp3-pool } "def*" { pool ss-devsp3-pool-81 } "ghi*" { pool ss-devsp3-pool-82 } } }
- RobertColbertNimbostratus
The problem you have is you are starting with a switch and confusing the runtime with if statements.
If you want to use If's, then it would look more like this:
when HTTP_REQUEST { set hostname [string tolower [HTTP::host]] if { $hostname starts_with "abc" } { pool ss-devsp3-pool } elseif { $hostname starts_with "def" } { pool ss-devsp3-pool-81 } elseif { $hostname starts_with "ghi" } { pool ss-devsp3-pool-82 } }
Using the switch statement, it would look more like this:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { abc* { pool ss-devsp3-pool } def* { pool ss-devsp3-pool-81 } ghi* { pool ss-devsp3-pool-82 } } }
- hartonNimbostratus
Thanks for the help. Let me test these out, and I'll let you know which one worked for me.
- hartonNimbostratus
Thanks again everyone for your help. I ended up using the if statements that Robert gave.
- psavalam_195881Nimbostratus
Also similar question here what happens if the pool "ss-devsp3-pool" is down, will it reach default pool if configured . And shouldn't switch have a default pool ?? am I wrong in understanding this.
- nitassEmployee>what happens if the pool "ss-devsp3-pool" is down, will it reach default pool if configured . no, i do not think so because load balancing is based on host header (not availability of pool).
Recent Discussions
Related Content
* 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