Forum Discussion

Michael_108908's avatar
Michael_108908
Historic F5 Account
Jul 12, 2007

iRULE genetating an error in ltm log

One of my customers created this iRule:

 

 

when HTTP_REQUEST {

 

if{[[HTTP::header User-Agent] contains "BlackBerry8100"]}

 

pool BB_Test_Pool

 

elseif{[[HTTP::header User-Agent] contains "BlackBerry7250"]}

 

pool BB_TEST_POOL1

 

}

 

 

and it generates the following error:

 

 

TCL error: Rule WAP_iRULE HTTP_REQUEST - invalid command name BlackBerry8100/4.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/149contains while executing [HTTP::header User-Agent]contains BlackBerry8100

 

 

According to the iRule editor the rule is syntactically correct. This is my first iRule case and I am a little lost. Can someone please help?

4 Replies

  • The first clue is always the error message.

     

     

    if { [[HTTP::header User-Agent] contains "BlackBerry8100"] }

     

    Enclosing the block with brackets tells the TCL engine to execute that code as a procedure. In this case it tries to execute a procedure that is " contains BlackBerry8100" which is why the error of invalid command is given. Fix here is to remove the brackets.

     

     

    Secondly there is no curly brackets around the code blocks of the if/elseif. Odds are when the first error is corrected, you'll get a syntax error here.

     

     

    This version should work:

     

     

    when HTTP_REQUEST {
      if { [HTTP::header User-Agent] contains "BlackBerry8100" } {
        pool BB_Test_Pool
      } elseif { [HTTP::header User-Agent] contains "BlackBerry7250" } {
        pool BB_TEST_POOL1
      }
    }

     

     

    -or- you could do it this way with a switch

     

     

    when HTTP_REQUEST {
      switch -glob [HTTP::header User-Agent] {
        "*BlackBerry8100*" {
          pool BB_Test_Pool
        }
        "*BlackBerry7250*" {
          pool BB_TEST_POOL1
        }
      }
    }

     

     

    You pick which one you like better, they should both be functionally equivalent.

     

     

    -Joe