OpenScript

Reply
Occasional Contributor
alessandro.barisone
Posts: 17
Registered: ‎05-23-2012

Sorry server redirect

Hi all, I' m newbie with ADX and Openscript. My question is about a to create a script that redirect a client to a sorry server if the real servers are down.

I think this can be the script:

use OS_SLB;

sub SERVER_SELECTION_FAILURE () {

OS_SLB::redirect ( "domain" => 'http://sorry.xyz.com' , "url"=> '/sorry1.htm' , "port"=>'80' ); }

compile is ok

i' ve bind to virtual server but it' s not working.

Where is my mistake ?

Thanks

Alessandro

Occasional Contributor
alessandro.barisone
Posts: 17
Registered: ‎05-23-2012

Re: Sorry server redirect

I' ve tried also this but without success...  :-((

Script: "redirect.pl"

use OS_SLB;

use OS_HTTP_REQUEST;

sub HTTP_REQUEST {

  if ( OS_SLB::up ("rs1") == 0)

  {

  OS_HTTP_REQUEST::redirect ( "domain"=>"sorry.xyz.com" , "url"=>"/sorry.htm" , "port"=> "80" ) ;

  }

}

Any ideas ?

Thanks

Ale

Occasional Contributor
Derek_Kang
Posts: 50
Registered: ‎12-14-2011

Re: Sorry server redirect

The script seems to be fine. Did you configure this command "server l7-dont-reset-on-vip-port-fail" on the ADX unit? Without the command, the ADX will reset a client connection when all servers are down, meaning the script will not have a chance for run.

Brocade recommends ADX S/W releases12.4.00c for OpenScript; please, upgrade if you haven't.

Occasional Contributor
alessandro.barisone
Posts: 17
Registered: ‎05-23-2012

Re: Sorry server redirect

I' ve put the command and all is fine now. I' ve read your post before but in my version 12.4.00b using the question mark to find the command I didn' t see nothing...maybe an hidden command ?

Anyway, with the second script all is working.

A question:

If I' ve several real server, can I use reg expr instead of the name of the server ?

Thanks

Ale

Occasional Contributor
Derek_Kang
Posts: 50
Registered: ‎12-14-2011

Re: Sorry server redirect

The help menu for the command works starting from 12.4.00c. The regex is not supported as an argument in the API call.

I think that you can go back to your first script with minor modification as follows; you wouldn't need a regex.

use OS_SLB;

use OS_HTTP_REQUEST;

sub HTTP_REQUEST {

  OS_SLB::forward(1);  # "1" is a server group ID you assign to real servers in the CLI configuration

}

sub SERVER_SELECTION_FAILURE () {

  OS_HTTP_REQUEST::redirect ( "domain"=>"sorry.xyz.com" , "url"=>"/sorry.htm" , "port"=> "80" ) ;

}

Occasional Contributor
alessandro.barisone
Posts: 17
Registered: ‎05-23-2012

Re: Sorry server redirect

Hi Derek,
thank for your help. I have another issue to resolve.
I need to configure a virtual server to redirect the http request in https and use the script for the sorry server.

When I try to configure both csw and script under the same virtual server I see that it's not possible.

In which way can I modify the script to operate both to redirect any http request to https and to manage sorry server
when the real server or the service http is down ?

script red.pl

use OS_SLB;
use OS_HTTP_REQUEST;
sub HTTP_REQUEST {
OS_SLB::forward(3);
}
sub SERVER_SELECTION_FAILURE () {
OS_HTTP_REQUEST::redirect ( "domain"=>"sorry.xxx.yyy.com" , "url"=>"/sorry.htm" , "port"=> "80" ) ;
}


------

csw-policy "p1"
default redirect "*" "*" ssl

server virtual aaaa 1.1.1.1
sym-priority 12
sym-active
port ssl sticky
port http
port http csw-policy "p1"
port http csw
port http keep-alive
bind ssl SharePoint3 ssl SharePoint4 ssl SharePoint5 ssl SharePoint8 ssl
bind ssl SharePoint9 ssl
bind http SharePoint3 http SharePoint4 http SharePoint5 http SharePoint9 http
bind http SharePoint8 http

Thanks a lot


Alessandro

Occasional Contributor
Derek_Kang
Posts: 50
Registered: ‎12-14-2011

Re: Sorry server redirect

### Ignore this reply and go to my latest answer; there's an error in the script; the sorry page will not work



Please, try the script below. All the requests on HTTP will be redirected to HTTPS if any of servers is available; if none of servers available, requests will be redirected to the sorry page server.


use OS_SLB;

use OS_HTTP_REQUEST;

sub HTTP_REQUEST {

OS_HTTP_REQUEST::redirect ( "domain"=>"xxx.yyy.com" , "url"=>"/index.htm" , "port"=> "443" ) ;


}

sub SERVER_SELECTION_FAILURE () {

OS_HTTP_REQUEST::redirect ( "domain"=>"sorry.xxx.yyy.com" , "url"=>"/sorry.htm" , "port"=> "80" ) ;

}

Message was edited by: Derek Kang

Occasional Contributor
alessandro.barisone
Posts: 17
Registered: ‎05-23-2012

Re: Sorry server redirect

Derek, I did it before  and that work. But my problem is to change the redirect domain with "any" and url with "any".

This because I have different domain+url listening to the same virtual ip.

So I wanted insert in the script something like the csw-policy:

csw-policy "p1"

default redirect  *  *  ssl

that redirect to ssl any request arriving to http://www.xyz.com  in https://www.xyz.com, as also http://web.com in https://web.com

where www.xyz and web.com are resolved with the same ip address that is the ip address of the virtual server.

Thanks a lot for your answer

Ale

Occasional Contributor
Derek_Kang
Posts: 50
Registered: ‎12-14-2011

Re: Sorry server redirect

Got it. I also found out some mistakes in my previous script.

Please, try the following. I did some basic test in the lab; it should meet your requirements.

-----------------------------------------

use OS_SLB;

use OS_HTTP_REQUEST;

sub BEGIN {

  %rs_list = (1030=>"rs1", 1031=>"rs2", 1032=>"rs3"); #list up your real servers with server ID

}

sub HTTP_REQUEST {

  my $domain = OS_HTTP_REQUEST::host;

  my $url = OS_HTTP_REQUEST::url;

  my $any_server_up = 0;

  foreach my $server_id (keys %rs_list) {

      if (OS_SLB::up($rs_list{$server_id}, 80) == 1) {

          $any_server_up = 1;

          last;

      }

   }

   if ($any_server_up == 1) {

        OS_SLB::redirect("domain"=>$domain, "url"=>$url, "port"=>"443");

   } else {

        OS_SLB::redirect("domain"=>"sorry.xxx.yyy.com" , "url"=>"/sorry.htm" , "port"=> "80" );

     }

}

Occasional Contributor
alessandro.barisone
Posts: 17
Registered: ‎05-23-2012

Re: Sorry server redirect

Derek,

it works! thanks.

please could you explain me this:

foreach my $server_id (keys%rs_list) }

if OS_SLB::up ($rs_list{$server_id}, 80) ==1) {

$any_server_up=1

i understand that the whole meaning is: foreach controls each server in rs_list and  if the list has at least one server up the variable $any_server will be = 1.

What I need to understand is the particular  meaning of the line:

if OS_SLB::up ($rs_list{$server_id}, 80) ==1

Thanks alot

Ale

Join the Community

Get quick and easy access to valuable resource designed to help you manage your Brocade Network.