Forum Discussion

Maciej_Waliszko's avatar
Maciej_Waliszko
Icon for Nimbostratus rankNimbostratus
May 08, 2016

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,

    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
    }