vADC Docs

Select Pool based on host header

by jberry_1 on ‎01-18-2012 02:56 PM (4,159 Views)

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" );  
}

Comments
by on ‎03-21-2012 07:39 AM

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" );



by westredd on ‎08-08-2012 12:49 AM

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....

by fmemon on ‎08-08-2012 12:41 PM

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

 

Faisal

by westredd on ‎08-08-2012 03:26 PM

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.

by fmemon on ‎08-08-2012 04:57 PM

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

by jberry_1 on ‎10-01-2012 03:13 PM

$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!