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;Arg0ool-3;
if( string.ipmaskmatch( request.getremoteip(), "19.19.23.0/24" ) ){
pool.use( "pool-3" );
}
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
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
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:
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:
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
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
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