vADC Forum

Reply
New Contributor
Posts: 3
Registered: ‎04-19-2013

Stingray REST API: how to parse the rule

I am using the REST API to get the rules. I need to extract the rule's details from the response. Is there a recommended way to parse the response?

This is an example of the response:

#CQualifier:Any;

#Param:Remote IP Address;Op:equals;Expr:19.19.23.0/24;

#Type:Choose Pool;Arg0Smiley Tongueool-3;

if( string.ipmaskmatch( request.getremoteip(), "19.19.23.0/24" ) ){

    pool.use( "pool-3" );

}

Frequent Contributor
Posts: 321
Registered: ‎11-29-2012

Re: Stingray REST API: how to parse the rule

Hi Rinaldo,

The response you're looking at is the contents of a RuleBuilder rule.

The three comment lines at the beginning (the lines beginning with '#') define the rule logic as it is configured using the RuleBuilder UI.  The TrafficScript code below is the generated rule that matches the RuleBuilder logic.

The contents are not intended to be parsed by anything other than the RuleBuilder UI and the core Stingray trafficscript compiler.

What are you trying to achieve?  There are various techniques to generate and manage rules automatically; for example, it's common to create a rule that imports a table of data (libTable.rts: Interrogating tables of data in TrafficScript) and acts on it - a list of URL-to-Redirect mappings, or a list of IP-addresses-to-Blacklist.  Then you just need to manage the contents of the table, and don't have to edit the rule.

regards

Owen

New Contributor
Posts: 3
Registered: ‎04-19-2013

Re: Stingray REST API: how to parse the rule

Hi Owen

Thanks for the prompt answer.

We only need to read the rules and extract the relevant information so that we can analyze it.

Is there a RuleBuilder library that can help to parse the rules?

Our program is in Java.

Thanks

Rinaldo

Frequent Contributor
Posts: 321
Registered: ‎11-29-2012

Re: Stingray REST API: how to parse the rule

Hi Rinaldo,

The format of rulebuilder rules is quite straightforward, and it clearly imitates what you see in the RuileBuilder UI.

Recall that a RuleBuilder rule consists of two parts:

  1. A set of tests (conditions), containing a parameter (e.g. the host header), and operator (e.g. 'equals') and an expression (e.g. 'www.riverbed.com')
  2. An ordered set of actions that are performed if the conditions are met

The RuleBuilder rule can trigger the actions if either /all/ of the conditions are met, or if /any/ of the conditions are met

The components of the rule are stored as comments:

  • #CQualifier - All or Any: actions are triggered if all or any conditions are met
  • #Param:<name>;Op:<operator>;Expr:<expression>; - each condition is stored in this fashion
  • #Type:<action type>;Arg0:<arg>;...; - each action is stored in this fashion

When a rule is edited by the UI, the RuleBuilder configuration is stored in comments of this type.  The UI also writes a TrafficScript rule that corresponds to the RuleBuilder configuration, and the Stingray software executes this TrafficScript rule.  If you edit the comments, this will have no effect until the UI re-reads the rule and then saves it.

There are no public libraries that can be used to parse or generate RuleBuilder rules.  You can find the conditions and actions described in the VTSData.pm file in the Stingray distribution (zxtmadmin/lib/perl/Zeus/ZXTM/VTSData.pm) .

regards

Owen

New Contributor
Posts: 3
Registered: ‎04-19-2013

Re: Stingray REST API: how to parse the rule

So basically I can use any method to parse the comments because I can rely on the consistency of the keywords ("CQualifier", "All", "Any", "Param", "equals", ........... ) and on the consistency of the structure of the components in the comments.

Thanks

Rinaldo

Frequent Contributor
Posts: 321
Registered: ‎11-29-2012

Re: Stingray REST API: how to parse the rule

Yep. Although the format of the rulebuilder rules is not published, it is straightforward and consistent and at present we have no plans to change it.

Owen

Join the Community

Get quick and easy access to valuable resource designed to help you manage your Brocade Network.