Forum Discussion

Joe_5599_134300's avatar
Joe_5599_134300
Icon for Nimbostratus rankNimbostratus
Sep 25, 2014

URL and URI Pool Selection iRule

I need help with an new irule. I want to check the URL for default http page and send to port 80 pools. All others will be matched on the URI section.

 

I have the URI section working but when adding in the new URL section the syntax is not correct.

 

The URL section can be added to the very bottom if needed after URI check.

 

*Updated irule using. LTM Still does not like the syntax

 

When HTTP_REQUEST { check for URL and send to pool switch [string tolower [HTTP::host]] { "sam.testsite99.testing2.com" { pool sam.testsite99.testing2.com-80 }

 

"bob.testsite99.testing2.com" { pool bob.testsite99.testing2.com-80 } } when HTTP_REQUEST { switch -glob [HTTP::uri] { "/sam1" { SSL::disable serverside pool testsite99.testing2.com-8080 } "/bob1" { SSL::disable serverside pool bob.testsite99.testing2.com-8080 }

 

"/sam2" { SSL::disable serverside pool testsite99.testing2.com-8081 } "/bob2" { SSL::disable serverside pool bob.testsite99.testing2.com-8081 } "/sam3" { SSL::disable serverside pool testsite99.testing2.com-8085 } "/bob3" { SSL::disable serverside pool bob.testsite99.testing2.com-8085 } "/sam4" { SSL::disable serverside pool testsite99.testing2.com-9080 } "/bob4" { SSL::disable serverside pool bob.testsite99.testing2.com-9080 } "/sam5" { SSL::disable serverside pool testsite99.testing2.com-9081 } "/bob5" { SSL::disable serverside pool bob.testsite99.testing2.com-9081 } "/sam6" { SSL::disable serverside pool testsite99.testing2.com-9082 } "/bob6" { SSL::disable serverside pool bob.testsite99.testing2.com-9082 } "/sam7" { SSL::disable serverside pool testsite99.testing2.com-9085 } "/bob7" { SSL::disable serverside pool bob.testsite99.testing2.com-9085 } "/sam8" { SSL::disable serverside pool testsite99.testing2.com-22 } "/bob8" { SSL::disable serverside pool bob.testsite99.testing2.com-22 } "/sam9" { pool testsite99.testing2.com-443 } "/bob9" { pool bob.testsite99.testing2.com-443 } "/sam0" { pool testsite99.testing2.com-8443 } "/bob0" { pool bob.testsite99.testing2.com-8443 } "/bobdemo" { SSL::disable serverside pool bob.testsite99.testing2.com-80 }

 

}

 

8 Replies

  • mikeshimkus_111's avatar
    mikeshimkus_111
    Historic F5 Account

    Hi, I think you are missing a close bracket in your switch statement.

     

    switch [string tolower [HTTP::host] {

     

    should be:

     

    switch [string tolower [HTTP::host]] {

     

  • THi's avatar
    THi
    Icon for Nimbostratus rankNimbostratus

    Are you missing one closing square bracket in: [string tolower [HTTP::host] { ...?

     

    You can use iRule editor to find syntax errors easier.

     

  • Still not liking the additional bracket 01070151:3: Rule [/Common/Waterloo-Test-Combo] error: line 1: [parse error: missing close-brace] [{ check for URL and send to pool switch [string tolower [HTTP::host]] { sam.testsite99.testing2.com" { pool sam.testsite99.testing2.com-80 } "bob.testsite99.testing2.com" { pool bob.testsite99.testing2.com-80
  • mikeshimkus_111's avatar
    mikeshimkus_111
    Historic F5 Account
    I second what THi said, the iRule editor or a Notepad ++ with TCL language selected will show you unbalanced brackets/braces: https://devcentral.f5.com/s/articles/iRule-Editor-Download
  • THi's avatar
    THi
    Icon for Nimbostratus rankNimbostratus
    You are missing one closing curly bracket on the second pool. I added it and it passed ok on my BIG-IP
  • Now getting this error. Do I need the 2nd WHEN HTTP_REQUEST statement or do I need an ELSE in between sections? 01070151:3: Rule [/Common/Waterloo-Test-Combo] error: line 10: [Duplicate event/priority] [when HTTP_REQUEST { check uri and send to pool switch -glob [HTTP::uri] { "/sam1*" { SSL::disable serverside pool sam.testsite99.testing2.com-8080 }
  • THi's avatar
    THi
    Icon for Nimbostratus rankNimbostratus
    I think you can have same event in a single iRule only once. So either combine the logic into one when HTTP_REQUEST -event, or create a second separate iRule and attach that to the same virtual server (evaluation order matters and hope the logics are not conflicting). See https://devcentral.f5.com/s/articles/stacking-irules-a-modular-approach
  • Hi,

    You have a problem as an iRule can't have two times the same event.

    Also you had problems on missing square brackets.

    This part should work now.
    when HTTP_REQUEST { 
        check for URL and send to pool 
        switch [string tolower [HTTP::host]] { 
            "sam.testsite99.testing2.com" { 
                pool sam.testsite99.testing2.com-80 
            }
            "bob.testsite99.testing2.com" { 
                pool bob.testsite99.testing2.com-80
            }
         } 
    }