Forum Discussion

Luke_55733's avatar
Luke_55733
Icon for Nimbostratus rankNimbostratus
Oct 22, 2012

Node selection via URL parameters

Hello everyone! I'm trying to do the following...

 

I would like to monitor individual parts of one of our applications by hitting each member within the F5 pool on a regular basis, and always with the same user (so we can trace in the logs). So what I was thinking of, was calling the application as follows:

 

www.myapplication.com/login.jsp?node=MNS1

 

with an iRule that would:

 

1. Read in the"node" parameter, and route traffic to a particular node based off of that parameter

 

2. Remove the parameter before passing on to the app

 

Is this doable? Is there something like this already out there? If not, are there particular docs that I should take a look at to help me out?

 

Thanks!

 

7 Replies

  • If you've not too many nodes this should do the trick (although I'm sure it can be improved);

    
    when HTTP_REQUEST {
     if { [HTTP::uri] ! contains "MSN" } {
      pool x.x.x.x
      LB normally if URI doesn't contain MSN
     elseif { [HTTP::uri] ends_with "MSN1" } {
      node x.x.x.x port }
     elseif { [HTTP::uri] ends_with "MSN2" } {
        node x.x.x.x port }...and so on...
     else { return }
     }
    

  • Thanks Steve! I'll give that a shot and get back to you. Much appreciate the quick reply.
  • You're welcome. I'm far from an iRule expert right now but it should work fine. Let me know either way.
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Here's another example:

     

     

    Select pool member based on HTTP query string parameter

     

    https://devcentral.f5.com/wiki/iRules.Select_pool_member_based_on_HTTP_query_string_parameter.ashx

     

     

    Aaron
  • nathe's avatar
    nathe
    Icon for Cirrocumulus rankCirrocumulus
    All

    I wonder if this will work? Not at my lab so can't check syntax. Don't be afraid anyone to come back and tell me if this is complete nonsense and won't work.

    when HTTP_REQUEST {
       switch [findstr [HTTP::query] "node=" 5 ] {
          "MNS1" {
             HTTP::uri [string range [HTTP::uri] 0 end-10]
             node x.x.x.x port
           }
          "MNS2" {
             node y.y.y.y port
             HTTP::uri [string range [HTTP::uri] 0 end-10]
           }
           default {
           log local0. "No node= match"
           }
       }
    } 

    Obviously don't know how many parameter values there are or what you want to happen if there's no match.

    Here's hoping,

    N
  • e.g.

    [root@ve10:Active] config  b virtual bar list
    virtual bar {
       snat automap
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       set node_ip [URI::query "?&[HTTP::query]" "node"]
       if { [scan $node_ip {%d.%d.%d.%d} a b c d] == 4 } {
          HTTP::uri [string trimright [string map [list "node=$node_ip" ""] [HTTP::uri]] "?"]
          node $a.$b.$c.$d
       }
    }
    }
    
     test1
    
    [root@ve10:Active] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.20.11(58985) <-> 172.28.19.79(80)
    1350967002.5006 (0.0007)  C>S
    ---------------------------------------------------------------
    HEAD /login.jsp?node=200.200.200.101 HTTP/1.1
    User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.10(58985) <-> 200.200.200.101(80)
    1350967002.5018 (0.0010)  C>S
    ---------------------------------------------------------------
    HEAD /login.jsp HTTP/1.1
    User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
     test2
    
    [root@ve10:Active] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.20.11(58986) <-> 172.28.19.79(80)
    1350967020.3477 (0.0010)  C>S
    ---------------------------------------------------------------
    HEAD /login.jsp?node=200.200.200.111 HTTP/1.1
    User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.10(58986) <-> 200.200.200.111(80)
    1350967020.3489 (0.0010)  C>S
    ---------------------------------------------------------------
    HEAD /login.jsp HTTP/1.1
    User-Agent: curl/7.15.5 (x86_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
  • Thanks everyone for the feedback. Looks like I'm good to go now! Very impressed with the responsiveness of this community compared to others. Thanks again.