Forum Discussion

Eric_Waite_1046's avatar
Eric_Waite_1046
Icon for Nimbostratus rankNimbostratus
Jan 08, 2007

findstr

What does the following mean exactly?

 

 

set jsess [findstr [HTTP::uri] "jsessionid" 11 "?"]

 

 

What would it set the jsess variable in the following request?

 

 

http://users.readingplus.com/readingplus/loginSchool.do;jsessionid=F8E2C6F9B4CB4FA10EB277639AD77E96

 

 

I am confused with the syntax of findstr.

 

 

Thanks in advance

 

-Eric

 

 

  • Hi Eric,

    Here is the wiki page on findstr:

    Click here

    findstr [ []

    * Finds the string within and returns a sub-string based on the and from the matched location. Note the following:

    * * The argument may be either a character or length.

    * * If the argument is not specified, it defaults to zero.

    * * If the argument is not specified, it defaults to the end of the string.

    To test this, you can create a test rule that logs the results of the findstr command when the rule is initialized. As the HTTP::uri value won't exist at that point, you can save the URI value you want to test as a string in a variable.

    
    when RULE_INIT {
       set uri "/readingplus/loginSchool.do;jsessionid=F8E2C6F9B4CB4FA10EB277639AD77E96"
       set jsess [findstr $uri "jsessionid" 11 "?"]
       log local0. "\$jsess: $jsess"
    }

    Here is the output from /var/log/ltm:

    Jan 8 17:38:21 tmm tmm[1233]: Rule : $jsess: F8E2C6F9B4CB4FA10EB277639AD77E96

    So findstr is searching the URI for "jsessionid", skipping 11 characters (the length of jsessionid plus the '=', and returning everything up to the '?' if there is one. If the terminator of '?' isn't found, the entire string after the skip count is returned.

    Using a '?' as the terminator here accounts for the possibility of a query string in the URI.

    Holler if you have any questions.

    Aaron
  • Thanks for you help, my problem stems from the following iRule that I am using for persistence. On some of my requests the persistence is not holding and its going to another server in the pool. I am at a loss.

     

     

    I am correct to assume that the response is not what is not controlling what server the request gets sent to?

     

     

    Any help would be appreciated.

     

    - Eri

     

     

     

    when HTTP_RESPONSE {

     

    if { [HTTP::cookie exists "JID"] } {

     

    set resPers [HTTP::cookie "JID"]

     

    log "lookup for $resPers in table = >[persist lookup uie $resPers]<"

     

    if { [persist lookup uie $resPers] equals "" } {

     

    persist add uie $resPers 3700

     

    log "NEW PERSIST - added response entry *$resPers* for server [LB::server addr]"

     

    } else {

     

    log "FOUND PERSIST - continued sessionId *$resPers* for server [LB::server addr]"

     

    }

     

    }

     

    }

     

     

    when HTTP_REQUEST {

     

    set jsess [findstr [HTTP::uri] "jsessionid" 11 "?"]

     

    if { $jsess != "" } {

     

    persist uie $jsess 3700

     

     

    log "USING PERSIST - used URI value is *$jsess*, server [LB::server addr]"

     

    }

     

    }
  • I could never get a 100% solution with only the persist command. Probably my flawed coding, but rather than spin my wheels I switched to the session flavor of persistence so I could store the serverIP. If I get a match, I send the connection directly to the pool member serverIP stored in the session table:

    
    when HTTP_RESPONSE {
      if { [HTTP::cookie exists "JSESSIONID"] } {
        set trimID [lindex [split  [HTTP::cookie "JSESSIONID"] "!" ] 0 ]
        if { [session lookup uie $trimID] equals "" } {
            session add uie $trimID [IP::server_addr] 1800
        }
      }
    }
    when HTTP_REQUEST {
      if { [findstr [HTTP::uri] "jsessionid" 11 "!"] != ""} {
        pool MyPool member [session lookup uie [findstr [HTTP::uri] "jsessionid" 11 "!"] ]
      } else {
          pool MyPool
      }
    }
  • I am now using the following and the persistenc edoes not allways hold, its almost as if the table is removing the entry on BIG_IP.

     

     

    BTW could the "?" be throwing it off, I want to parse up until there is a ? in the URL. To handle passed in request vars.

     

    Why do you use "!" in your parsing of jsessionid?

     

     

     

    - Eric

     

     

     

    when HTTP_RESPONSE {

     

    if { [HTTP::cookie exists "JID"] } {

     

    set resPers [HTTP::cookie "JID"]

     

    if { [persist lookup uie $resPers] equals "" } {

     

    session add uie $resPers [IP::server_addr] 3700

     

    }

     

    }

     

    }

     

     

     

    when HTTP_REQUEST {

     

    set jsess [findstr [HTTP::uri] "jsessionid" 11 "?"]

     

    if { $jsess != "" } {

     

    pool test_pool member [session lookup uie [findstr [HTTP::uri] "jsessionid" 11 "?"] ]

     

    } else {

     

    pool test_pool

     

    }

     

    }
  • I trim at the ! so I only get the session ID. If you trim at the ? you also get the unique weblogic server identifiers, which I have noticed occasionally change.

    If you want to discover these unique identifiers real time, you can insert the header X-Weblogic-Request-ClusterInfo towards the application:

    
    when CLIENT_ACCEPTED {
      set get_server_mappings 1
    }
    when HTTP_REQUEST {
      if { $get_server_mappings } {
        HTTP::header insert "X-Weblogic-Request-ClusterInfo" "true"
        set get_server_mappings 0
      }
    }

    Then on the next response, extract the information from the header X-WebLogic-Cluster-List

    
    when HTTP_RESPONSE {
      if { [HTTP::header exists "X-WebLogic-Cluster-List"] }{
        set server_mappings [split [HTTP::header "X-WebLogic-Cluster-List"] "|" ]
         Remove header before returning to client
        HTTP::header remove "X-WebLogic-Cluster-List"
      }
    }

    I'll leave it to you to discover what to do with this information, weblogic returns a lot of useful information!

  • Thanks for the reply.

     

    I am not using any Enterprise Application Server .... yet.

     

    Just multiple Tomcats.

     

     

    Thanks.

     

     

     

    Eric