Contribute Open Script

[BRCD_OS_116] Primary and Backup Servers

by Yasir_Liaqatullah on ‎01-20-2012 03:03 PM (63 Views)

Area

Server Selection

Traffic

HTTP

Description

            This script tries to send the requests to a group of primary servers. If none of the primary servers are available, then it forwards to a backup server if it is up. If backup server is not available, ADX will send a redirect message. Administrator of the script can customize the redirect message sent to client by modifying the appropriate part of “BEGIN” section in the script.

Performance Estimate

            Contact us for our detailed reporting

               or

            Report your own performance estimate

Required Backend configuration

            No special configuration is required

Events and API Used

Events

API

HTTP_REQUEST

OS_SLB::forward

OS_SLB::server_name

OS_SLB::up

OS_SLB::redirect

Script source code

# Purpose: Request forwarded to Primary or Backup Servers or send Redirect message

# Send to a group of server, if none of servers in that group are available,

# forward to a backup server. If that server is also not running, send client

# a redirect message

# Customize the variables in sub BEGIN to your network

use OS_SLB;

use OS_HTTP_REQUEST;

my $primary_group_id;

my $backup_server_id;

my @redirect;

sub BEGIN {

$primary_group_id = "30";

$backup_server_id = "1102";

@redirect = ("domain", "www.newhost.com", "status-code", "745", "url","/newpage.html", "port", "8980");

}

sub HTTP_REQUEST () {

print "HTTP Request event is triggered\n";

# Forward to primary group id

OS_SLB::forward("$primary_group_id")

}

sub SERVER_SELECTION_FAILURE () {

# If none of the servers in primary group are available, this event is trigerred.

print "SERVER SELECTION FAILURE event Triggered\n";

# Check if the Backup server is up.

#       First, get the name of server from Backup server-id and

#       then use the name to find if that server is up

my @backup_server = split(/ /, OS_SLB::server_name("$backup_server_id"));

my $backup_server_name = $backup_server;

my $backup_server_port = $backup_server;

my $backup_server_up = OS_SLB::up("$backup_server_name", "$backup_server_port");

# If Backup is UP, forward the request to it, else send a redirect message

if ($backup_server_up) {

print "Forwarding Request to Backup server as Primary Servers are down..\n";

OS_SLB::forward("$backup_server_id");

} else {

print "Primary and Backup Servers are all DOWN. Send Redirect to Client..\n";

OS_SLB::redirect("$redirect"=>"$redirect", "$redirect"=>"$redirect", "$redirect"=>"$redirect", "$redirect"=>"$redirect");

}

}