cancel
Showing results for 
Search instead for 
Did you mean: 

How to check Pool and if necessary redirect with Trafficscript

Highlighted
Occasional Contributor

How to check Pool and if necessary redirect with Trafficscript

Hi @ all

we just installed a Stingray TM and now I´ve to struggle with TrafficScript Rules ;-)

Until now I used only Rulebuilder, but with TS there´s of course much more possible ...

Ok, here´s my Question, perhaps it´s a "little Thing" but not for me, at this time

We´ve a pool (Example) with 4 Nodes (ex1, ex2, ex3, ex4) ...  now I want to write

a rule with Trafficscript like the following:

When URL equals www.example.com, then use "Pool Example", but

when Pool Example ist dead or not reachable, then redirect or change to site www.example2.com

Here´s my TS-Rule:

if ( http.getheader( "host" ) == www.example.com )

{

   pool.use( "Example" );

}

$status = pool.checknode("Example","ex1",80);

if($status != "Active") {

   pool.use( "Example" );

}

else

http.changeSite( http://www.exmple2.com);

but this don´t work, everytime I got "Service Unavailable" when I disabled Node "ex1"

The next Problem ist how to check, if all 4 Nodes are healthy, not even 1 , like in my rule above

Did somebody have an idea?

Thanks a lot for any Tips.

Regards

3 REPLIES

Re: How to check Pool and if necessary redirect with Trafficscript

Can you try replace the != into = for the status check, and try again....

if($status = "Active") {

   pool.use( "Example" );

}

else

http.changeSite( http://www.exmple2.com);

Contributor

Re: How to check Pool and if necessary redirect with Trafficscript

1. pool.use:

When used in a request rule, aborts all rules processing and specify the pool to give the request to.

that means your trafficscript ends on the line pool.use( "Example" );

2. you are only checking one node, i would do it different:

if ((pool.activenodes("Example") > 1)) {

# you have at least 2 working nodes

   pool.use("Example");

# your script will end here in normal operation

}

# you only come to this line, if you have no working node in pool "Example"

http.changeSite("http://www2.example.com");

# as an alternative, you can do a redirect, depending on your requirements:

# http.redirect( "http://www2.example.com/" );

Occasional Contributor

Re: How to check Pool and if necessary redirect with Trafficscript

Hi Jochen,

that works perfectly, thanks for that.