Forum Discussion

Kirit_Patel_521's avatar
Kirit_Patel_521
Icon for Nimbostratus rankNimbostratus
Jul 19, 2015

irule syntax error

what is wrong with my syntax here

01070151:3: Rule [/Finance/testsol] error: /Finance/testsol:3: error: [parse error: PARSE syntax 190 {syntax error in expression "([string tolower [HTTP::uri]] starts_with "/solr/spruat_slav...": unexpected operator &}][{([string tolower [HTTP::uri]] starts_with "/solr/spruat_slave") || ([string tolower [HTTP::uri]] starts_with “/sol”) }]

when HTTP_REQUEST {

log local0. { "http::uri" [HTTP::uri] } if {([string tolower [HTTP::uri]] starts_with "/solr/spruat_slave") || ([string tolower [HTTP::uri]] starts_with “/sol”) } { log local0. "matched [HTTP::uri]" pool mhf_pool_172.16.250.72-slave

}
   }
  • Try this:

    when HTTP_REQUEST {
        log local0. "http uri: [HTTP::uri]"    
    
        if { ( [string tolower [HTTP::uri]] starts_with "/solr/spruat_slave" ) or ( [string tolower [HTTP::uri]] starts_with “/sol” ) } {     
            log local0. "matched [HTTP::uri]"           
            pool mhf_pool_172.16.250.72-slave
        }           
    } 
    

    I'd comment though that the second condition will always be met if the first is true. It may be simpler to consolidate down to:

    if { [string tolower [HTTP::uri]] starts_with "/sol" }
    
  • Did you by chance copy this iRule from an Office document? It looks like the double quotes around "/sol" are incorrect. If replace those. Otherwise the syntax looks correct.

     

  • Vernon_97235's avatar
    Vernon_97235
    Historic F5 Account

    It's your quotes around "/sol". They are so-called "smart quotes". They are a character sequence that cannot be processed by the iRule loader. You can remove them, or copy-and-paste this:

    when HTTP_REQUEST {
        log local0. "http uri: [HTTP::uri]"    
    
        if { ( [string tolower [HTTP::uri]] starts_with "/solr/spruat_slave" ) or ( [string tolower [HTTP::uri]] starts_with "/sol" ) } {
            log local0. "matched [HTTP::uri]"           
            pool mhf_pool_172.16.250.72-slave
        }           
    }
    

    Incidentally, I found these by going to the command-line and executing:

    tmsh create ltm rule foo
    

    Once I pasted in your rule, the bad characters were reasonably obvious.

    • Kirit_Patel_521's avatar
      Kirit_Patel_521
      Icon for Nimbostratus rankNimbostratus
      Thanks . In this irule what do i need to do if all the conditions are not met than use pool mhf_pool_172.16.250.72-80?
  • It's your quotes around "/sol". They are so-called "smart quotes". They are a character sequence that cannot be processed by the iRule loader. You can remove them, or copy-and-paste this:

    when HTTP_REQUEST {
        log local0. "http uri: [HTTP::uri]"    
    
        if { ( [string tolower [HTTP::uri]] starts_with "/solr/spruat_slave" ) or ( [string tolower [HTTP::uri]] starts_with "/sol" ) } {
            log local0. "matched [HTTP::uri]"           
            pool mhf_pool_172.16.250.72-slave
        }           
    }
    

    Incidentally, I found these by going to the command-line and executing:

    tmsh create ltm rule foo
    

    Once I pasted in your rule, the bad characters were reasonably obvious.

    • Kirit_Patel_521's avatar
      Kirit_Patel_521
      Icon for Nimbostratus rankNimbostratus
      Thanks . In this irule what do i need to do if all the conditions are not met than use pool mhf_pool_172.16.250.72-80?
  • You can use an else condition:

    when HTTP_REQUEST {
        log local0. "http uri: [HTTP::uri]"    
    
        if { ( [string tolower [HTTP::uri]] starts_with "/solr/spruat_slave" ) or ( [string tolower [HTTP::uri]] starts_with "/sol" ) } {
            log local0. "matched [HTTP::uri]"           
            pool mhf_pool_172.16.250.72-slave
        } else {           
            pool mhf_pool_172.16.250.72-80
        }
    

    }

    Or you can simply apply the mhf_pool_172.16.250.72-80 pool to the virtual server configuration. In either case you should also apply OneConnect - a setting in the virtual server and in the associated HTTP profile.

  • There's something wonky about the formatting somewhere, otherwise the code looks right. Try commenting out the two pool statements and the log statement and updating. Does it compile?

     

  • Okay, here's what I would do. Considering that you had some "magic quotes" in the first version, I'm guessing you copied and passed this from someplace else. I would rewrite this, manually, from scratch in the iRule editor. The iRule looks good, so it has to be a formatting or hidden special character somewhere.

     

  • Try this

     

    when HTTP_REQUEST { log local0. "http uri:$uri" set uri [HTTP::uri] if { $uri starts_with "/solr/spruat_slave" } { pool mhf_pool_172.16.250.72-slave } elseif { $uri starts_with "sol" } { pool mhf_pool_172.16.250.72-slave } }