Forum Discussion

shlomi_133455's avatar
shlomi_133455
Icon for Nimbostratus rankNimbostratus
Apr 02, 2014

iRule to Select pool by parsing

Hello, I want to Create an Irule that will forward a request coming to Site1.website.com to pool Site1. I want it to be generic so if i add another pool named SiteXYZ and assign another DNS record named SiteXYZ.website.com it will also take it. I am guessing it will be something like this:

 

when HTTP_REQUEST { set content [HTTP::host] set PoolName [split $content "."]

 

if { pool $PoolName[1] Exist } pool $PoolName[1] else return error of somekind

 

will that work?

 

2 Replies

  • John_Alam_45640's avatar
    John_Alam_45640
    Historic F5 Account

    Name the pools site1 and site2.... siteX..

    it can be as easy as this.
    when HTTP_REQUEST {  
       extract the first part of hostname.   
      set poolname [getfield [HTTP::header host] "." 1]   
      pool $poolname  
    }  
    

    To make sure you don't send user to an undefined pool name do this:

    when HTTP_REQUEST {  
       extract the first part of hostname.  
      set poolname [getfield [HTTP::header host] "." 1]   
      if { [catch {pool $poolname} id ] } {  
          You can find this in the local traffic log from GUI or via : tail /var/log/ltm  
         log local0. "Pool name $poolname does not exist yet."    
       }  
    }  
    
  • Thanks a lot, this is exactly what i was looking for. just Small FYI to whoever will use it in the future... Pools are case Sensitive so you need to take it under consideration when creating the redirect.