Hi!
I am attempting to write a script that will display the contents of all rules on a given system. In trying to use the query_all_rules method I’m having difficulty with retrieving the details for a given rule.
From the 4.5 SDK
void query_all_rules(
in SessionCredentials creds, <== CORBA Specific
out String[] rule_names,
out String[] rule_details
);
I used the $soap_response-> result to get the rule names and $soap_response->paramsout to get the rule_details. Where I’m having problems is tying the rule detail to a specific rule name. Can someone explain what type of structure rule_details is and how do I access only a specific rule’s detail?
Thanks.
Anthony
Each “rule_details” in the returned list is just a string representation of the rule text, with each rule detail string corresponding to the same rule name at a particular index. For example:
rule_names[i] = “rule_1”
rule_details[i] = “rule details for rule_1”
Hope this helps.
Loc
Anthony, here is code illustrating the use of ITCMLocalLB::Rule::query_all_rules in Perl:
sub getRules()
{
$soapResponse = $LocalLBRule->query_all_rules();
if ( $soapResponse->fault )
{
print $soapResponse->faultcode,
"(faultstring) ", $soapResponse->faultstring,"\n";
print $soapResponse->faultcode,
"(faultdetail) ", $soapResponse->faultdetail, "\n";
}
else
{
@rule_names = @{$soapResponse->result};
@params = $soapResponse->paramsout;
@rule_details = @{@params[0]};
$i = 0;
foreach $rule_name (@rule_names)
{
$rule_detail = @rule_details[$i];
print "Rule $i\n";
print "Name: $rule_name\n";
print "Details: $rule_detail\n";
print "----------------------\n";
$i++;
}
}
}
-Joe
Thanks for the help. It worked.
Is there an example for v9? I’m able to properly query all rules but can’t seem to parse the results and print them. I know the syntax has changed for the results (rule_names --> rule_name, rule_detail --> rule_definition), I made appropriate changes but I get out of memory errors in perl and I’m kinda new to perl so I’m at a loss.
In 9.x the signature for the query_all_rules() method is:
struct RuleDefinition {
string rule_name;
string rule_definition;
};
RuleDefinition[] query_all_rules();
The method now returns an array of RuleDefinition structures.
Here’s some code to query all rule names and rule defintions:
sub getRules()
{
$soapResponse = $LocalLBRule->query_all_rules();
if ( $soapResponse->fault )
{
print $soapResponse->faultcode,
"(faultstring) ", $soapResponse->faultstring,"\n";
print $soapResponse->faultcode,
"(faultdetail) ", $soapResponse->faultdetail, "\n";
}
else
{
$i = 0;
@RuleDefinitionList = @{$soapResponse->result};
foreach $RuleDefinition (@RuleDefinitionList)
{
$rule_name = $RuleDefinition->{"rule_name"};
$rule_definition = $RuleDefinition->{"rule_definition"};
print "Rule $i\n";
print "Name: $rule_name\n";
print "Details: $rule_definition\n";
$i++;
}
}
}
As you see, you cast the $soapResponse->result into an array. You then can enumerate that array and access the RuleDefinition members.
-Joe