For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

harton's avatar
harton
Icon for Nimbostratus rankNimbostratus
Oct 04, 2013

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
  }  } 
 } 

6 Replies

  • 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
            }  
        }   
    }
    
  • 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 }
        }
    }
    
  • harton's avatar
    harton
    Icon for Nimbostratus rankNimbostratus

    Thanks for the help. Let me test these out, and I'll let you know which one worked for me.

     

  • harton's avatar
    harton
    Icon for Nimbostratus rankNimbostratus

    Thanks again everyone for your help. I ended up using the if statements that Robert gave.

     

  • 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.

     

    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      >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).