Sample scripts, High readability script example – Brocade Virtual ADX OpenScript Programmer’s Guide (Supporting ADX v03.1.00) User Manual
Page 18

10
Brocade Virtual ADX OpenScript Programmer’s Guide
53-1003244-01
Sample scripts
2
Sample scripts
The following examples provide two different approaches to creating a script for the same purpose.
The first example provides a heavily commented example for high readability and the second is a
“power-user” version of the script. It is much more compact with less extensive notation. Both
scripts provide for load-balancing using a URL match in an HTTP GET request.
High readability script example
The following example provides a version of the script that demonstrates high-readability.
# Elegant load balancer with good readability
# Performs server selection based on URI in HTTP
# Request Header
# Tell the script about extensions used in this program
use OS_HTTP_Request;
use OS_SLB;
use strict;
use Sub::StrictDecl;
sub HTTP_REQUEST
{
#Get an HTTP request object to manage
# request headers or content.
# Pattern we want to match…..
$url_pattern = "index.html";
# …. with pattern data in packet
$url_in_request = OS_HTTP_REQUEST::url;
# Perform a Regular Expression Search.
if ($url_in_request =~ m/$uri_pattern/) {
# Forward to a real server identified by name
OS_SLB::forward("RS1");
} else {
# Forward to a real-server group identified by numeric ID
OS_SLB::forward(2);
}
}