Forum Discussion

Shay_Ben-David1's avatar
Shay_Ben-David1
Icon for Nimbostratus rankNimbostratus
Nov 01, 2006

choos nodes according to cookie name and value ?

i need irule to choose between nodes (servers) according to the cookie comes in the http/https request, lets say if client came with cookie name: abc and value 1, it will go to server A, if it comes with cookie name: abc and value 2 it will go to server B ?

 

6 Replies

  • You can inspect the cookies a client presents with the HTTP::cookie commands. You can set a node for a specific request using the node command. You can check the respective wiki pages for HTTP::cookie (Click here) and node (Click here), or search the forums for examples. Repost here if you have any questions.

     

     

    Deb posted an example (Click here) which shows how to verify the status of the node is up before using the node.

     

     

    Aaron
  • thanks for the assist, but nothing here helps in this, i need irule example for track the client request and decide wich server to get the client according to the cookie name and value, here is an example of what i try, but i can't get it work, when i come to the vip it do load balancing eventhough i have irule on the vip.

     

     

    when HTTP_REQUEST {

     

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

     

    switch [HTTP::cookie "amlbcookie"] {

     

    *server1* { node 192.168.10.66 }

     

    *server2* { node 192.168.10.67 }

     

    log "Cookie header: [HTTP::cookie exists amlbcookie]"

     

    }

     

    }

     

    else {

     

    pool skyp-AM-1873

     

    }

     

    }

     

     

    "amlbcookie" is the cookie name and the value can be "01" for node 192.168.10.66, nad value "02" for node node 192.168.10.67 , hope this can clear few things.

     

    10nx

     

  • Hi,

    If the cookie values are literally 01 and 02, you would need to modify the *server1* and *server1* to 01 and 02. Also, try adding some logging to the switch statement so you can see which condition was met:

     
     when HTTP_REQUEST { 
        if { [HTTP::cookie exists "amlbcookie"] } { 
        log local0. "[HTTP::cookie "amlbcookie"]" 
           switch -glob [HTTP::cookie "amlbcookie"] { 
              *01* { 
                 node 192.168.10.66 
                 log local0. "matched 01" 
              } 
              *02* {  
                 node 192.168.10.67  
                 log local0. "matched 02" 
              } 
      
           } 
        } 
        else { 
           pool skyp-AM-1873 
           log local0. "default" 
        } 
     } 
     

    Aaron
  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    BTW, "switch" by default is an exact match. You need to add "-glob" to match with *'s.

     

     

    You might also want to add a "default" case, to catch the times when the cookie exists but doesn't match any of your cases.
  • thanks guys, seems to be better, but i didnt understand the log, there is two time "Default", should that be, because if he got a match, why using the pool ?

     

    log example:

     

     

    Nov 2 21:46:46 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : Default

     

    Nov 2 21:46:49 tmm tmm[727]: 01220002: repeated 21 times

     

    Nov 2 21:46:50 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : 02

     

    Nov 2 21:46:50 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : matched 02

     

    Nov 2 21:46:51 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : 02

     

    Nov 2 21:46:51 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : matched 02

     

    Nov 2 21:46:51 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : 02

     

    Nov 2 21:46:51 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : matched 02

     

    Nov 2 21:46:52 tmm tmm[727]: 01220002: repeated 32 times

     

    Nov 2 21:47:04 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : Default

     

    Nov 2 21:47:04 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : 02

     

    Nov 2 21:47:04 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : matched 02

     

    Nov 2 21:47:04 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : 02

     

    Nov 2 21:47:04 tmm tmm[727]: 01220002:6: Rule AM-Cookie-track : matched 02
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    I would imagine that requests with no cookie, or at least with a cookie that doesn't have the value you're expecting, would log the "default" message.

     

     

    Colin