Forum Discussion

lipos_54863's avatar
lipos_54863
Icon for Nimbostratus rankNimbostratus
Aug 05, 2009

persisting on a cookie

Hi,

I'm wondering is there a way to create a persistence based on a cookie when checking only first three letters of the cookie name?

Here's my example:

 
 when HTTP_RESPONSE {  
 if { [HTTP::cookie exists "1234567890"] } {  
 persist add uie [HTTP::cookie "1234567890"]  
 }  
 }  
 when HTTP_REQUEST {  
 if { [HTTP::cookie exists "1234567890"] } {  
 persist uie [HTTP::cookie "1234567890"]  
 }  
 }  
 

Part 1234 never changes, but 567890 will.

Any suggestions?
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    If you want to parse part of the cookie value, you can use 'string range' (Click here) to get it. It would be good to make sure there is a value before trying to persist on it.

     

     

    Aaron
  • I need to persist on a cookie but its name changes every session.

     

    Only first four characters stay the same.

     

    It's not the cookie value.

     

    I just need a way of catching the right cookie since there are couple.
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Sorry, for the cookie name, you could loop through the cookies by name:

      
     foreach a_cookie [HTTP::cookie names] { 
      
        if {$a_cookie starts_with "1234"}{ 
      
            Found a cookie that starts with 1234, so do something 
        } 
     } 
     

    Aaron
  • Thank you!

     

    One more thing..

     

    I got this updated iRule:

     

       
     when HTTP_RESPONSE {     
       foreach a_cookie [HTTP::cookie names] {      
         if {$a_cookie starts_with "1234"}{      
           persist add uie [HTTP::cookie "$a_cookie"]      
           log local0.debug "Cookie persist - client IP: [IP::client_addr], Cookie: $a_cookie, Server IP: [IP::server_addr]"     
         } else {     
           persist source_addr 255.255.255.255 3600      
           log local0.debug "Source persist - client IP: [IP::client_addr] , Server IP: [IP::server_addr]"     
           }     
        }     
     }     
     when HTTP_REQUEST {     
       foreach a_cookie [HTTP::cookie names] {      
          if {$a_cookie starts_with "1234"}{      
            persist uie [HTTP::cookie "a_cookie"]      
            log local0.debug "Client IP: [IP::client_addr], Cookie value: $a_cookie"     
           }      
        }      
     }    
     

     

    I would like to persist on a cookie which starts with 1234, but if it's not available I need to run source IP persistence.

     

    I already set this up in the HTTP_RESPONSE but I just wonder how to enable it on a VS is my primary persistence will be set to Universal.

     

    If the fallback persistence will work in this example or I need to add more code looking up the persistence table for this IP?
  • I think I finally got it.

    Thanks!

      
     }timing on  
     HTTP responds catches the first responds from the node to back to the client.  
     It checking all cookies in the header and grabs all starting with 1234.  
     After it adds the cookie value to the persistance table and log values to syslog.  
     Else persist the client for 60 minutes based on source IP with /32 mask and log values to syslog.  
      
     when HTTP_RESPONSE {  
     foreach a_cookie [HTTP::cookie names] {   
     if {$a_cookie starts_with "1234"}{   
     persist add uie [HTTP::cookie "$a_cookie"]   
     log local0.debug "Cookie persist - client IP: [IP::client_addr], Cookie: $a_cookie, Server IP: [IP::server_addr]"  
     } else {  
     persist source_addr 255.255.255.255 3600   
     log local0.debug "Source persist - client IP: [IP::client_addr] , Server IP: [IP::server_addr], lookup [persist lookup uie [IP::client_addr]]"  
     }  
     }  
     }  
     HTTP request catches the first responds from the node to back to the client.  
     It checking all cookies in the header and grabs all starting with 1234.  
     After it persist on the cookie value in the persistance table.  
     Aslo, log values to syslog  
      
     when HTTP_REQUEST {  
     foreach a_cookie [HTTP::cookie names] {   
     if {$a_cookie starts_with "1234"}{   
     persist uie [HTTP::cookie "a_cookie"]   
     log local0.debug "Client IP: [IP::client_addr], Cookie value: $a_cookie"  
     } else {  
     persist uie [IP::client_addr]  
     log local0.debug "Source IP Persistence used - Client IP: [IP::client_addr], Persistance entries used persist uie [persist lookup uie [IP::client_addr]]"  
     }  
     }   
     }
  • There is article about posted here

     

     

    http://devcentral.f5.com/Default.aspx?tabid=63&articleType=ArticleView&articleId=160

     

     

    I hope this helps

     

    CB