Forum Discussion

Dave_22402's avatar
Dave_22402
Icon for Nimbostratus rankNimbostratus
Apr 19, 2010

Irule switch - comment

How does one put comments into a Irule. This is on V10.

 

 

Here is an example of what I want to do - but the iRule Editor says the syntax is wrong:

 

 

when HTTP_REQUEST {

 

log local0. "[IP::client_addr]i IP recieved"

 

switch [IP::client_addr] {

 

"123.123.123.123" {

 

comment on where ip is

 

switch -glob [string tolower [HTTP::uri]] {

 

"/URL/*" { pool TEST_POOL}

 

"*" { pool PROD_POOL}

 

}

 

}

 

default {

 

switch -glob [string tolower [HTTP::uri]] {

 

"/URL/*" { HTTP::respond 301 Location }

 

"*" { pool PROD_POOL}

 

}

 

}

 

}

 

}

3 Replies

  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi Dave,

     

     

    That rule looks valid to me and the iRule editor on a 10.0.1 unit. What is the exact error you're seeing?

     

     

    See this post for details on comments in the switch command:

     

     

    http://devcentral.f5.com/Default.aspx?tabid=53&aft=1172116

     

     

    and the TCL page for switch:

     

     

    http://www.tcl.tk/man/tcl8.4/TclCmd/switch.htm

     

     

    Edit: On a side note, it would be more efficient to use IP::addr to check the IP address:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/ip__addr

     

     

    Aaron

     

  • Aaron

     

     

    Tired to go to http://devcentral.f5.com/Default.as...ft=1172116 and get a mesage "We're Sorry - Your request was not completed as expected "

     

     

    Also, with the comments in the iRule Editor - when I try to save it - I get red dots next to each comment line and it does not save the record.

     

     

    I have tired a couple of spots in the rule - and inside the switch - it does not work.

     

     

    I beielve I have tried the IP:addr - and it gave me the wrong IP - I am wanting the IP of the client machine - is IP:addr suppose to do that?

     

     

    Thanks for the feed back.
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Hi Dave,

     

     

    DC shortens URLs now. Can you try removing the spaces from this URL to get to the page?

     

     

    http:// devcentral.f5.com/Default.aspx?tabid=53&aft=1172116

     

     

    What's the error that the iRule editor shows at the bottom of the code window for the red dots?

     

     

    And here is an example using IP::addr to check a single host or network:

     

     

    
    when HTTP_REQUEST {
    
       log local0. "[IP::client_addr] IP recieved"
    
       if {[IP::addr [IP::client_addr] equals 123.123.123.123]}{
    
         comment on where ip is
         switch -glob [string tolower [HTTP::uri]] {
            "/URL/*" { pool TEST_POOL}
            default { pool PROD_POOL}
         }
       } else {
          switch -glob [string tolower [HTTP::uri]] {
             "/URL/*" { HTTP::respond 301 Location https://some.location }
             default { pool PROD_POOL}
          }
       }
    }
    

     

     

    Aaron