Forum Discussion

F_Ducloux_29246's avatar
F_Ducloux_29246
Icon for Nimbostratus rankNimbostratus
Aug 04, 2008

iRule help request

Hi Guys, I'm very new at this and I just joined a company that is using F5 BigIPs and i got asked to investigate if I could write a new rule to do this:

 

 

I have several virtual servers called

 

apache1.qa1.ee.com

 

apache2.qa1.ee.com

 

apache3.qa1.ee.com

 

apache1.qa2.ee.com

 

apache2.qa2.ee.com

 

apache3.qa2.ee.com

 

 

then i have an iRule related to that VS that says

 

 

apache1.ee.com

 

when HTTP_REQUEST {

 

if { [HTTP::host] contains "qa1" } {

 

pool apache1.qa1.ee.com

 

} elseif { [HTTP::host] contains "qa2" } {

 

pool apache1.qa2.ee.com

 

}

 

}

 

 

and then again the same thing for apache2.. and i have about 210 virtual servers. with 210 iRules,

 

 

is there anyway that i can get the the VS name into a variable then parse it and only get the first part and then use that to create only one rule for all of the servers?

 

 

something like this

 

 

generic rule

 

when HTTP_REQUEST {

 

if { [HTTP::host] contains "qa1" } {

 

pool $VS.qa1.ee.com

 

} elseif { [HTTP::host] contains "qa2" } {

 

pool $VS.qa2.ee.com

 

}

 

 

Thanks

 

Fernando

5 Replies

  • If you are always triggering off of the second part of the virtual and the mapping is always to apache1."field 2".ee.com, then you can use getfield to extract that value and then dynamically build the pool name

    when HTTP_REQUEST { 
       set token [getfield [HTTP::host] "." 2] 
       pool "apache1.$token.ee.com" 
     }

    You might want to throw in some error validation to make sure that your generated pool name exists. If it does not, then the iRule will terminate and the connection will be broke.

    when HTTP_REQUEST { 
       set token [getfield [HTTP::host] "." 2] 
       if { [catch { pool "apache1.$token.ee.com" } ] } { 
         log local0. "Error using pool apache1.$token.ee.com" 
       } else { 
          do some error handling in here. 
       } 
     }

    If there isn't a one-to-one mapping, then you'll likely need to go with the findclass/matchclass option of building a lookup table.

    Hope this helps...

    -Joe
  • Glad to help! Please feel free to post any questions that come up in the mean time.

     

     

    -Joe