Technical data

Table Of Contents
10 ServerIron ADX OpenScript Guide
53-1002445-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.
Power-user script example
The following example is the “power-user” version of the script. It is much more compact with less
extensive notation.
Example 2:
# 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;
# Define an event handler to be called when an HTTP
# request is received
sub HTTP_REQUEST
{
#Get an HTTP request object to manage
# request headers or content.
$request = OS_HTTP_REQUEST::get;
# Pattern we want to match…..
$url_pattern = "index.html";
# …. with pattern data in packet
$url_in_request = $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);
}
}