Learn OpenScript

OpenScript Walk-through, "Hello, OpenScript"

by Derek_Kang on ‎12-22-2011 01:56 PM (653 Views)

We are going to create an OpenScript that performs the following task:

  • If the URL of an HTTP request from a client PC includes a string, “openscript”, print out a debugging message on the console, “Hello, OpenScript”, and forward the request to real server rs1; otherwise, print “Hey, No OpenScript?” and forward to real server rs2.

Basically, we create and edit an OpenScript code named “hello.pl”, using the Web GUI of ServerIron ADX and associate the script with an SLB VIP port. Follow the steps below.

  • Make sure that your ADX runs 12.4.00 or later software releases.
  • Configure a basic SLB configuration as follows on the ServerIron ADX.

server real rs1
port http
server real rs2
port http
server virtual v1                   
port http

  • After logging into the ADX via the Web GUI, click the Configure tab at the top and the Traffic menu below.
  • Click the OpenScript menu on the left side bar; you will get to the following screen.


  • Click the New button at the bottom. You will get to the following screen.


  • Enter an OpenScript file name, “hello.pl” in the Script Name field and source code in the Script Code field as follows. Note that the last step of this procedure includes the source code; you can copy and paste.


  • Click the Compile button and then the Apply button.
  • Associate the OpenScript code with a VIP port. You will see the following output if the url in your HTTP request includes "openscript".

server virtual v1                        
port http                                           
port http script "hello.pl"

  • Go into the rconsole mode and run traffic to the VIP.

ADX#rconsole 1 2
ADX1/2#Hello, OpenScript!

  • You can list up all the script files and/or view source codes using CLI as well as the WebGUI.

ADX#show script all
Total Script: 1
            1:             hello.pl

ADX#show script hello.pl program
Script: "hello.pl"
use OS_SLB;

# This sub routine is called when the ADX receives an HTTP request from a client.

        my $url = OS_HTTP_REQUEST::url;

# Perl provides a powerful regular expression feature; the ADX looks for "openscript" in the URL.
        if ($url =~ m/openscript/) {
# Print a message; to see the message, get into the rconsole mode, e.g., enter "rcon 1 1".
# Note that we use "print" for demo or debugging purpose. The print function consumes lots of CPU cycles.
# Do not use print statements for production traffic.
                print "Hello, OpenScript!\n";
        } else {
                print "Hey, No OpenScript?\n";