Using a Rule on the Traffic Manager

TrafficScript rules are stored in the Rules Catalog. You can use the Rules Catalog to create rules, upload them from an external source, modify or duplicate them, and delete unused rules as required.

To access the Rules Catalog, click Catalogs > Rules.

You can configure a virtual server to execute one or more rules from the catalog each time it receives a new request or response, or at completion of a transaction. This way, several different virtual servers can use the same rule, and modifications to the rule take effect on all virtual servers.

To use a rule, first create or upload a new rule in the catalog. Then configure your virtual server to use the rule (click Services > Virtual Servers > Rules and add the rule using the settings provided).

Creating a Rule in the Catalog

To create a new rule:

1.Click Catalogs > Rules Catalog.

2.In the "Create new rule" section, enter a name for your rule.

3.To write the rule in TrafficScript, click Use TrafficScript Language. To use the RuleBuilder, click Use RuleBuilder.

4.Click Create Rule.

Using the RuleBuilder

Your license key might restrict the availability of certain RuleBuilder options and features and the ability to use TrafficScript. If you encounter problems using some of the features described here, consult your Support Provider who can advise you on the best course of action to upgrade your software or license.

The RuleBuilder allows you to select conditions on the request to be examined, and actions that follow if any or all of these conditions are met.

You can add conditions based on the client’s IP address and port, HTTP parameters, cookies, or the URL requested. Whenever you create a condition, extra text boxes appear for you to fill in the parameters for that item.

You can then select a series of actions for the rule to carry out. Parts of the request can be altered and the Traffic Manager can write log messages before a final action is performed. The possible final actions are to choose a specified pool, or to drop the connection; not more than one final action can be carried out, but a rule is not required to have a final action.

For example, you might construct a rule such as:

IF

   URL Path starts with /servlet

OR

   URL Path ends with .jsp

THEN

   Choose Pool: Servlet Runners

Requests whose URL path does not start with “/servlet” or end in “.jsp” (such as requests for static HTML content) are ignored by this rule. A virtual server applying this rule can use a separate rule to deal with requests for other pages, or assign them to its default pool.

When you are happy with your rule, click Update.

You can also convert your rule to TrafficScript. The TrafficScript language gives you a much wider range and structure of possible conditions and actions. You can click Preview Rule as TrafficScript to see what the TrafficScript rule would look like, and use the Convert Rule button to convert your rule permanently.

When you begin to use the Traffic Manager's rules, you could start by using the RuleBuilder to implement simple rules. Examine the corresponding TrafficScript rule to familiarize yourself with the TrafficScript syntax. When you need to write a complex rule, you could use the RuleBuilder to prototype a simple version; once you have reached the limits of the capabilities of the RuleBuilder, proceed by converting the rule to TrafficScript for further editing.

Special variables

There are several special variables that can be included in the text boxes for RuleBuilder which are expanded to TrafficScript functions. These allow the generation of more dynamic rules, with extra flexibility.

For example, if you create a rule that sets the HTTP header “X-Forwarded-For” to the value %REMOTE_IP%, then the header will be set to the IP address of the client connecting to the Traffic Manager.

The special variables are as follows:

%REMOTE_IP%: replaced with the remote IP of the client connection (TrafficScript function request.getRemoteIP())

%REMOTE_PORT%: replaced with the remote IP of the client connection (TrafficScript function request.getRemotePort())

Writing a TrafficScript Rule

The TrafficScript editing page shows a form where you can enter a text description of the rule, type the rule and check the syntax before compiling it. You may wish to write the rule in a separate text editor before pasting it in.

Click the TrafficScript Reference link to view the quick function reference, and use the Check Syntax button to check your rule. When you have finished, click the Update button.

Some TrafficScript functions and RuleBuilder conditions and actions are appropriate only in request rules, response rules, or transaction completion rules specifically. For example, a function that modifies a parameter of a request has no effect if used in a response rule (because the request has already been submitted to a node). Equally, any transaction completion rule that attempts to use a function with side-effects for the connection (for example, http.setResponseHeader(), connection.discard()) is disallowed. See the Online Help or Pulse Secure Virtual Traffic Manager: TrafficScript Guide for descriptions of each TrafficScript function and RuleBuilder conditions and actions.

Uploading a Rule to the Catalog

The Traffic Manager supports uploading of previously created TrafficScript rules into the Catalog. Your rules should be in plain text, and the Traffic Manager uses the full filename (including extension) as the rule name.

The Traffic Manager performs a syntax check on the uploaded rule file. Warnings and errors are displayed on the Rule Catalog page, the Diagnose page, and in the Event Log.

To upload a rule to the Catalog

1.Click Catalogs > Rules Catalog.

2.In the "Upload an existing rule" section, click Choose file to select a rule file from your local filesystem.

3.Choose whether to overwrite existing rules that have the same name as your filename.

4.Click Upload Rule.

Applying a Rule to a Virtual Server

A newly added rule is not yet in use by the Traffic Manager. To use a rule, add it to your virtual server configuration.

To configure a virtual server to use a rule

1.To access the Virtual Servers > Edit page for your virtual server, click the Services button and then the Virtual Servers tab. Click the name of your virtual server.

2.Click the Rules link. This presents you with lists of request rules, response rules, and transaction completion rules currently in use for your virtual server.

3.To add a new rule to a list, use the “Add rule:” option in each section. Choose a rule from the drop-down list and click Add rule.

4.Rules are executed in a specified order. If the first rule does not make a final decision about a transaction, the second rule is tested, and so on. Use the drag handle at the left side of each rule bar to move a rule within the list.

For most protocols, you can specify whether the rule should be executed just once (against the first request or response), or against every request and response in the protocol dialogue.

In RTSP and SIP the rules are automatically executed on each individual request or response that passes through the Traffic Manager.

This option is not necessary for HTTP virtual servers because HTTP is a single request-response protocol, and requests within a keepalive connection are processed independently.

You can test the effect of a new rule by enabling and disabling it for your test virtual server.