Forum Discussion

Gary_Blevins_31's avatar
Gary_Blevins_31
Icon for Nimbostratus rankNimbostratus
Oct 12, 2005

iRule Issue

I have the following iRule set up on my 9.1 BigIP:

 

 

when HTTP_REQUEST {

 

if { [HTTP::host] contains "www.careers.philips.com"} {

 

HTTP::redirect "http://www.philips.com/about/careers"

 

}

 

elseif { [HTTP::host] contains "www.peopleclick.com" or "eeosource.peopleclick.com" or "eeoanalytics.peopleclick.com" or "eeodiversity.peopleclick.com" or "generator.peopleclick.com" or "optimum.peopleclick.com" or "secure.peopleclick.com" or "strategichr.peopleclick.com" or "www.itiliti.com" or "www.eeosource.com" or "www.eeosource.net" or "www.eeosource.org" or "elearning.peopleclick.com"} {

 

pool CorpWeb

 

}

 

else {

 

pool ProdWeb

 

}

 

}

 

 

When I put the rule in, there are no errors, however, in the local traffic log I see the following every time the rule is accesses:

 

 

TCL error: Rule ProdWeb_TrafficRouting_Rules - can't use non-numeric string as operand of "||" while executing "if { [HTTP::host] equals "www.careers.philips.com"} { HTTP::redirect "http://www.philips.com/about/careers" } elseif { [HTTP::host] equals "www.peo..."

 

 

Has anyone seen this before? Any help would be greatly appreciated.

 

 

Thanks,

 

Gary Blevins

5 Replies

  • drteeth_127330's avatar
    drteeth_127330
    Historic F5 Account
    The short answer is that you can't use the "or" operator in that manner. I recommend that you search for some postings about the matchclass command. Good luck!
  • You are using strings as boolean expressions which is what is causing the error.

    You could do something like this:

     

    when HTTP_REQUEST {
      if { [HTTP::host] contains "www.careers.philips.com"} {
        HTTP::redirect "http://www.philips.com/about/careers"
      } elseif { ([HTTP::host] contains "www.peopleclick.com") or 
        ([HTTP::host] contains "eeosource.peopleclick.com") or 
        ([HTTP::host] contains "eeoanalytics.peopleclick.com") or 
        ([HTTP::host] contains "eeodiversity.peopleclick.com") or 
        ([HTTP::host] contains "generator.peopleclick.com") or 
        ([HTTP::host] contains "optimum.peopleclick.com") or 
        ([HTTP::host] contains "secure.peopleclick.com") or 
        ([HTTP::host] contains "strategichr.peopleclick.com") or 
        ([HTTP::host] contains "www.itiliti.com") or 
        ([HTTP::host] contains "www.eeosource.com") or 
        ([HTTP::host] contains "www.eeosource.net") or 
        ([HTTP::host] contains "www.eeosource.org") or 
        ([HTTP::host] contains "elearning.peopleclick.com") } {
        pool CorpWeb
      } else {
        pool ProdWeb
      }
    }

     

    A couple of optimizations, you might use the "equals" command instead of "contains" unless, that is, you want to cover extensions to those domain names.

    Also, I'd look into using the matchclass command instead of all those or's. You can create a String Data Group and you could consolidate all those "or's" into a single line. Search the forums for "matchclass" and you'll find some examples.

    -Joe

  • Hi,

     

     

    Anyone knows how to configure f5 load balancer for constant throughput.

     

    for ex. I want throuput at 5kbps whatever may be input rate.

     

     

    Thanks in advance.

     

     

    -Rahul
  • For the rate shaping, your principal issue is that you are running 9.x. That version of code is well past end-of-life. Having said that, as Chris says (but with link to 9.x guide):

    For the long or set, the use of a glob switch is generally more readable:

     

    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::host]] {
            "www.careers.philips.com*" {
                HTTP::redirect "http://www.philips.com/about/careers"
            }
            
            "www.peopleclick.com*" - 
            "eeosource.peopleclick.com*" - 
            "eeoanalytics.peopleclick.com*" - 
            "eeodiversity.peopleclick.com*" - 
            "generator.peopleclick.com*" - 
            "optimum.peopleclick.com*" - 
            "secure.peopleclick.com*" - 
            "strategichr.peopleclick.com*" - 
            "www.itiliti.com*" - 
            "www.eeosource.com*" - 
            "www.eeosource.net*" - 
            "www.eeosource.org*" - 
            "elearning.peopleclick.com*" {
                pool CorpWeb
            }
            
            default {
                pool ProdWeb
            }
        }
    }
    

     

    I assume you want the equivalent of starts_with rather than contains, but it is trivial to change the meaning.

    But, as @drteeth (a dentist?) observes, matchclass is generally a superior way to achieve this sort of thing:

    which would look something like this (assuming you've created a class called corp-web-hosts in which the indices are lower-case only hostnames):

     

    when HTTP_REQUEST {
        if { [HTTP::host] starts_with "www.careers.philips.com"} {
            HTTP::redirect "http://www.philips.com/about/careers"
        }
        elseif { [matchclass host-match starts_with [string tolower [HTTP::host]]] } {
            pool CorpWeb
        }
        else {
            pool ProdWeb
        }
    }
    

     

    Strictly speaking, the else conditional is not required if the default pool for the Virtual Server is already set to ProdWeb.