cancel
Showing results for 
Search instead for 
Did you mean: 

Select Pool based on host header

I have several hundred websites that all use host headers in IIS. I would like to use a single virtual/Public IP address and have the traffic manager select the appropriate pool based on the host header passed in. I’ve been using a traffic script similar to the code snippet below. Is there a more efficient way to code this there will be several hundred pools and if statements? Can you do case statements in traffic script?

$HostHeader = http.getHostHeader();

if( string.contains( $HostHeader, "site1.test.com" ) ){
   pool.use( "Pool_site1.test.com_HTTP");
}else if( string.contains( $HostHeader, "site2.test.com" ) ){
   pool.use( "Pool_site2.test.com_HTTP");
}else if( string.contains( $HostHeader, "site3.test.com" ) ){
   pool.use( "Pool_site3.test.com_HTTP");
}else if( string.contains( $HostHeader, "site4.test.com" ) ){
   pool.use( "Pool_site4.test.com_HTTP");
}else if( string.contains( $HostHeader, "site5.test.com" ) ){
   pool.use( "Pool_site5.test.com_HTTP");
}else if( string.contains( $HostHeader, "site6.test.com" ) ){
   pool.use( "Pool_site6.test.com_HTTP");
}else{
   http.changeSite( "http://www.test.com" );  
}

Version history
Revision #:
1 of 1
Last update:
‎01-18-2012 02:56:PM
Updated by:
 
Tags (1)
Comments

Two options...

$hh = http.getHostHeader();

$pool = "Pool+" . $hh . "_HTTP";

if( pool.activeNodes( $pool ) >= 1 ) pool.use( $pool ); # rule will terminate on pool.use()

http.changeSite( "http://www.site.com" );

or...

$hh = http.getHostHeader();

$poolmap = [

   "site1.test.com" => "Pool_site1.test.com_HTTP",

   "site2.test.com" => "Pool_site2.test.com_HTTP",

   "site3.test.com" => "Pool_site3.test.com_HTTP",

   "site4.test.com" => "Pool_site4.test.com_HTTP"

);

$pool = $poolmap[ $hh ];

if( pool.activeNodes( $pool ) >= 1 ) pool.use( $pool ); # rule will terminate on pool.use()

http.changeSite( "http://www.site.com" );


In both cases, in order to use $variables in pool.use() you will need to turn on the trafficscript!variable_pool_use global config setting (this disables some config and validation optimizations we can use if all of your pool names are literal).  Option 1 is good if you are strict about naming your pools; option 2 gives you more flexibility.

Finally, you might appreciate the opportunity to avoind creating several hundred pools.  The 'forward proxy' mode will help, albeit without any health checks if a node is down:

$hh = http.getHostHeader();

$nodemap = [

   "site1.test.com" => "10.1.32.1",

   "site2.test.com" => "10.2.32.2",

   "site3.test.com" => "10.7.45.1",

   "site4.test.com" => "10.5.2.67"

);

$ip = $nodemap[ $hh ];

if( $ip ) pool.use( "mypool", $ip, 80 );


http.changeSite( "http://www.site.com" );



westredd1

We are wanting to use case as well.

 

I had a look in the trafficscript guide but they didnt create a case mehtod of running conditional statements for some reason. Seems incredible that they didnt!

 

Link to guide:

https://support.riverbed.com/download.htm?filename=public/doc/stingray/developer_edition/Stingray_9....

fmemon

Unfortunately there is no switch/case construct in TrafficScript.  What are you trying to do where a switch/case would help?

 

Faisal

westredd1

for me its to query and host header and then point it to the appropriate pool.

 

we have over 100 sites most with ssl and non ssl traffic , so rather than write if statements for each one, it would be better to use a case select.

fmemon

Having a switch/case construct would make the code more readable, but you'd still have to write a case statement for each site.  What do you think of option 1 posted by owen below?

 

Faisal

jberry_1

$hh = http.getHostHeader();

$pool = "Pool+" . $hh . "_HTTP";

if( pool.activeNodes( $pool ) >= 1 ) pool.use( $pool ); # rule will terminate on pool.use()

http.changeSite( "[http://www.site.com | http://www.site.com]" );

In both cases, in order to use $variables in pool.use() you will need to turn on the trafficscript!variable_pool_use global config setting (this disables some config and validation optimizations we can use if all of your pool names are literal).  Option 1 is good if you are strict about naming your pools; option 2 gives you more flexibility.


Option 1 worked for me. I tried this initially but I missed the part about enabling trafficscript!variable_pool_use. Thanks!