Forum Discussion
IF-elseif-else irule issue
I am trying to add the last else so in case the cookie cookiecrisp then just send the traffic directly to the POOL_443 but it gives me an error. And I was wondering if someone can help me out with this issue
when HTTP_REQUEST {
if { [HTTP::cookie exists cookiecrisp] } {
switch [HTTP::cookie value cookiecrisp] {
"azul" { if { [LB::status pool POOL-443 member 172.16.1.21 443] eq "up" } {
persist uie 1
pool POOL-443 member 172.16.1.21 443
} elseif {
[LB::status pool POOL-443 member 172.16.1.22 443] eq "up" } {
pool POOL-443 member 172.16.1.22 443
} else {
pool POOL-443
}
}
"rojo" { if { [LB::status pool POOL-443 member 172.16.1.23 443] eq "up" } {
persist uie 3
pool POOL-443 member 172.16.1.23 443
} elseif {
[LB::status pool POOL-443 member 172.16.1.21 443] eq "up" } {
pool POOL-443 member 172.16.1.21 443
} else {
pool POOL-443
}
}
"amarillo" { if { [LB::status pool POOL-443 member 172.16.1.22 443] eq "up" } {
persist uie angel
pool POOL-443 member 172.16.1.22 443
} elseif {
[LB::status pool POOL-443 member 172.16.1.23 443] eq "up" } {
pool POOL-443 member 172.16.1.23 443
} else {
pool POOL-443
}
}
} else {
pool POOL-443
}
}
}
Thank you so much!
Erika
Hi
seems you forgot to close the switch statement right before the added $1 section. Below is the rearanged and already corrected code...
when HTTP_REQUEST { if { [HTTP::cookie exists cookiecrisp] } { switch [HTTP::cookie value cookiecrisp] { "azul" { if { [LB::status pool POOL-443 member 172.16.1.21 443] eq "up" } { persist uie 1 pool POOL-443 member 172.16.1.21 443 } elseif { [LB::status pool POOL-443 member 172.16.1.22 443] eq "up" } { pool POOL-443 member 172.16.1.22 443 } else { pool POOL-443 } } "rojo" { if { [LB::status pool POOL-443 member 172.16.1.23 443] eq "up" } { persist uie 3 pool POOL-443 member 172.16.1.23 443 } elseif { [LB::status pool POOL-443 member 172.16.1.21 443] eq "up" } { pool POOL-443 member 172.16.1.21 443 } else { pool POOL-443 } } "amarillo" { if { [LB::status pool POOL-443 member 172.16.1.22 443] eq "up" } { persist uie angel pool POOL-443 member 172.16.1.22 443 } elseif { [LB::status pool POOL-443 member 172.16.1.23 443] eq "up" } { pool POOL-443 member 172.16.1.23 443 } else { pool POOL-443 } } } } else { pool POOL-443 } }
Cheers, Kai
- Stanislas_Piro2Cumulonimbus
You can use following code (it assign the pool at the beginning to remove else statements):
when HTTP_REQUEST { pool POOL-443 set preferedMember [list] switch [HTTP::cookie value cookiecrisp] { "azul" { set preferedMember [list "172.16.1.21" 443 "172.16.1.22" 443] } "rojo" { set preferedMember [list "172.16.1.23" 443 "172.16.1.21" 443] } "amarillo" { set preferedMember [list "172.16.1.22" 443 "172.16.1.23" 443] } } foreach {memberip memberport} $preferedMember { if { [LB::status pool $default_pool member $memberip $memberport] eq "up" } { pool POOL-443 member $memberip $memberport break } } }
I'm not sure the persistence is useful! I guess you can remove it.
The persistence record will match only is cookie value is the same as the previous request and the server is alive. so persistence is only done by cookie value.
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