Forum Discussion
irule - syntax error, what is wrong with my irule?
Hello, I am trying to write a simple irule but I am getting error. I have no clue why. Can anybody have a look at it and explain me what I am doing wrong? Thank you.
when HTTP_REQUEST { if { [IP::addr [IP::client_addr] equals 212.222.10.211%1] and [active_members V1_P_NSIVMQ1] == 1 } { pool V1_P_NSIVMQ1 } else if { [IP::addr [IP::client_addr] equals 212.122.20.212%1] and [active_members V1_P_NSIVMQ2] == 1 } { pool V1_P_NSIVMQ2 } else if { [IP::addr [IP::client_addr] equals 212.243.220.213%1] and [active_members V1_P_NSIVMQ3] == 1 } { pool V1_P_NSIVMQ3 } else { pool V1_P_NSIVMQ1-3 } }
4 Replies
Hi Maciej,
Try using 'elseif' instead of 'else if'.
Best regards,
Niels
Hello,
It's even better to use the switch/case instead of if elseif else.
- Maciej_Waliszko
Nimbostratus
Thank you very much Niels and Yann
- Stanislas_Piro2
Cumulonimbus
Hi,
this irule may help you to manage pool assignment in a array:
when RULE_INIT { array set static::V1_P_NSIVM { "212.222.10.211%1" V1_P_NSIVMQ1 "212.222.10.212%1" V1_P_NSIVMQ2 "212.222.10.213%1" V1_P_NSIVMQ3 } } when HTTP_REQUEST { if {[info exists static::V1_P_NSIVM([IP::client_addr])] && ([active_members $static::V1_P_NSIVM([IP::client_addr])] == 1 )} { pool $static::V1_P_NSIVM([IP::client_addr]) } else pool V1_P_NSIVMQ1-3 } }Or if you create a pool with only one member, you can assign pool member in the irule instead (with this irule, the pool V1_P_NSIVMQ1-3 may be assigned to the VS):
when RULE_INIT { array set static::V1_P_NSIVM { "212.222.10.211%1" {1.1.1.1 80} "212.222.10.212%1" {1.1.1.2 80} "212.222.10.213%1" {1.1.1.3 80} } } when HTTP_REQUEST { set default_pool [LB::server pool] if {[info exists static::V1_P_NSIVM([IP::client_addr])]} { set member(ip) [lindex $static::V1_P_NSIVM([IP::client_addr]) 0] set member(port) [lindex $static::V1_P_NSIVM([IP::client_addr]) 1] if { [LB::status pool $default_pool member $member(ip) $member(port)] eq "up" }} { pool $default_pool member $member(ip) $member(port) } unset member } unset default_pool }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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