Forum Discussion

sandiksk_35282's avatar
sandiksk_35282
Icon for Altostratus rankAltostratus
May 01, 2019

irule not working as expected

Issue with an irule ,from tcpdump dont see traffic hitting the backend servers in the pool.

 

when RULE_INIT { set debug 1 }

 

when HTTP_REQUEST {

 

if {$debug} { set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]" log local0. "=============================================" log local0. "$LogString (request)" foreach aHeader [HTTP::header names] { log local0. "$aHeader: [HTTP::header value $aHeader]" } log local0. "=============================================" }

 

switch -glob [HTTP::header "SOAPAction"] { "; - "; - "; { if { [active_members qa2-pool] > 0 } { pool qa2-pool } else { pool qa1-pool } } } }

 

4 Replies

  • this is the code i am seeing the var/log/ltm

     

    TCL error: /Common/qa2_irule - can't read "debug": no such variable while executing "if {$debug} { set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]" log local0. "..."

     

  • Hello sandiksk.

    You have several mistakes in your iRule.

    1. Set a default condition in your switch sentence (in case of no matching condition)
    2. Remove ';' characters in your switch options
    3. You should use static variables in RULE_INIT to be CMP-compatible (see THIS)
    4. If you are still having problems with 'debug' variable in logs, try to use a comparation statement like this ->

      "

      if { $debug != 0 } {
      " or "
      if { $static::debug != 0 } {
      " (to be CMP-compatible)

    KR, Dario.

  • Cannot access a variable set in

    RULE_INIT
    unless it is a global (don't do it!) or a static, better to set it in
    CLIENT_ACCEPTED
    it is minor overhead and quicker to update and apply

    Some other minor changes but think the following should work for you:

    when CLIENT_ACCEPTED {
        set debug 1
    }
    
    when HTTP_REQUEST {
        if {$debug} {
            set LogString "Client [IP::client_addr]:[TCP::client_port] -> [HTTP::host][HTTP::uri]"
            log local0. "============================================="
            log local0. "$LogString (request)"
            foreach aHeader [HTTP::header names] {
                log local0. "$aHeader: [HTTP::header value $aHeader]"
            }
            log local0. "============================================="
        }
    
        switch -glob [HTTP::header "SOAPAction"] {
            "http://www.user.com/CustomerFacingWebsite/Customer" -
            "http://www.user.com/CustomerFacingWebsite/Points" -
            "http://www.user.com/CustomerInquiry/Balances" { 
                if { [active_members qa2-pool] > 0 } {
                    pool qa2-pool
                } else {
                    pool qa1-pool
                }
            }
        }
    }