Forum Discussion

dkraut_23236's avatar
dkraut_23236
Icon for Nimbostratus rankNimbostratus
Sep 02, 2008

newbie needs irule help....

ok, I'm completely new to irules so break out the coloring book and crayons for me! lol.

 

 

I'm trying to create a rule that takes the incoming URI from the client and appends a number to the end of the host and then forwards to the corresponding pool member. For example, John Doe sends a request to http://bmcmtr:5282

 

and then the F5 adds a 01 to this request and forwards to pool member 01 as > http://bmcmtr01

 

The next request does the same thing except it is forwarded to 02 and the next to 03 and the next to 04.

 

The irule below generates "wrong args" errors when I attempt to create it. Am I completely off base here? Thanks!

 

 

 

when HTTP_REQUEST {

 

if { ([HTTP::host] eq "BMCMTR:5282") } {

 

HTTP::host "BMCMTR01:5282"

 

pool HTTP_pool member 10.1.1.14 80

 

}

 

if { ([HTTP::host] eq "BMCMTR:5382") } {

 

HTTP::host "BMCMTR02:5282"

 

pool HTTP_pool member 10.1.1.15 80

 

}

 

if { ([HTTP::host] eq "BMCMTR:5382") } {

 

HTTP::host "BMCMTR03:5282"

 

pool HTTP_pool member 10.1.1.16 80

 

}

 

if { ([HTTP::host] eq "BMCMTR:5382") } {

 

HTTP::host "BMCMTR04:5282"

 

pool HTTP_pool member 10.1.1.17 80

 

 

}

 

 

}

 

 

}

 

 

10 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    It sounds like you're trying to implement a counter, of sorts, and update the hostname with the value of the counter and then forward to a pool based on that number, resetting it every fourth pass or so. Does that sound about right?

     

     

    Colin
  • For whatever reason, they require that a number be appended to the host name before sending it to the server. I was basically trying to accomplish that while also load balancing. It doesn't have to happen in any set order. User 1 can be sent to server03 and user 4 can be sent to server01, etc.
  • Patrick_Chang_7's avatar
    Patrick_Chang_7
    Historic F5 Account
    You can set up a normal pool and choose whatever load balancing method you want. The iRule would be something like this:

     

    when LB_SELECTED {

     

    use [LB::server addr] to figure out what server was selected so you can do your string replacement logic on the host name

     

    HTTP::header replace "Host"

     

    }
  • Thanks pchang. So if I add in my data (assuming pool members were 10.1.1.1 thru 10.1.1.4) Would the rule look like this?

     

     

     

    when LB_SELECTED {

     

    use [LB::10.1.1.1]

     

    HTTP::header replace "Host"

     

    }

     

    when LB_SELECTED {

     

    use [LB::10.1.1.2]

     

    HTTP::header replace "Host"

     

    }

     

    when LB_SELECTED {

     

    use [LB::10.1.1.3]

     

    HTTP::header replace "Host"

     

    }

     

    when LB_SELECTED {

     

    use [LB::10.1.1.4]

     

    HTTP::header replace "Host"

     

    }
  • Posted By pchang on 09/02/2008 8:00 PM

     

     

    You can set up a normal pool and choose whatever load balancing method you want. The iRule would be something like this:

     

    when LB_SELECTED {

     

    use [LB::server addr] to figure out what server was selected so you can do your string replacement logic on the host name

     

    HTTP::header replace "Host"

     

    }

     

     

     

    ok, after playing around, I don't think this will work. I need to add different replacement strings depending on which pool member the request will be sent to.

     

     

    For example, if the LB is going to send the request to pool member 01 (servername01), I need it to change the host header to servername01. If it is going to send it to pool member 02, I need it to change the host header to servername02. If it is going to send it to pool member 03, I need it to change the host header to servername03. If it is going to send it to pool member 04, I need it to change the host header to servername04. Does that make sense?

     

     

    Thanks!

     

     

  • Hi nmenant, thanks for the reply.

     

     

    We're running BIG-IP 9.1.2 Build 40.6

     

     

    I'm new to F5/irules and am not sure what you mean by >

     

     

    "(datagroup definition you can retrieve in the bigip.conf file)"

     

     

    Do I have to create or edit this file? Can I do that from the GUI or does it have to happen via CLI?
  • You can create a datagroup in the GUI under Local Traffic >> iRules >> Datagroups tab >> Create. If you install the iRule editor (Click here) you can create a datagroup from the Tools | Datagroup Editor menu.

     

     

    Aaron
  • ok all, thanks for all the replies. After numerous iterations, etc. I've come up with the following rule. However, one of our guys took a look at this and could not understand how it would actually load balance? Will this dog hunt?

     

     

     

     

    when HTTP_REQUEST {

     

    if { ([HTTP::host] eq "BMCMTR:5282") } {

     

    HTTP::header replace "Host" "BMCMTR01:5282"

     

    pool bmcmtr member 10.1.1.14 80

     

    }

     

    if { ([HTTP::host] eq "BMCMTR:5382") } {

     

    HTTP::header replace "Host" "BMCMTR02:5282"

     

    pool bmcmtr member 10.1.1.15 80

     

    }

     

    if { ([HTTP::host] eq "BMCMTR:5382") } {

     

    HTTP::header replace "Host" "BMCMTR03:5282"

     

    pool bmcmtr member 10.1.1.16 80

     

    }

     

    if { ([HTTP::host] eq "BMCMTR:5382") } {

     

    HTTP::header replace "Host" "BMCMTR04:5282"

     

    pool bmcmtr member 10.1.1.17 80

     

    }

     

    }

     

  • A couple of things

     

     

    - HTTP::host never returns the PORT informatio

     

     

    - You don't have an IF-ELSEIF-ELSE statement so the evaluation is going to be perform on each conditional IF statement regardless if you meet the condition.

     

    - You are directing the traffic to a member in a pool; so no this will not load balance.

     

     

    Hope this helps

     

    CB

     

  • Posted By cmbhatt on 09/09/2008 3:07 PM

     

     

    A couple of things

     

     

    - HTTP::host never returns the PORT informatio

     

     

    - You don't have an IF-ELSEIF-ELSE statement so the evaluation is going to be perform on each conditional IF statement regardless if you meet the condition.

     

    - You are directing the traffic to a member in a pool; so no this will not load balance.

     

     

    Hope this helps

     

    CB

     

     

     

     

    any thoughts on how to manipulate it so that it will load balance? It's functional now... it returns the web site when you access the VPP. Thanks!