Reply

in-group xml usage

Authority
Posts: 27
6262     0

Hello,

   I am trying to run the following code to return if a device is in an interface group. I checked the group, and the device is definately in there, however, it returns false and passes. Am I missing something, or misunderstanding how in-group works?

<PolicyRuleLogic editor='raw-xml'>
<If>
  <Expr op='in-group'>
  <Expr value='Unused Ports'/>
  </Expr>
<Then>
<PolicyRuleFail>FailMessage</PolicyRuleFail>
</Then>
<Else>
<PolicyRulePass/>
</Else>
</If>
</PolicyRuleLogic>

Any advice is greatly appreciated!

 

 

Thank you,

Jerry

Re: in-group xml usage

Adviser
Posts: 353
6263     0

In the context of the policy rule evaluation, there is an implicit "device" object. So, when you do "in-group" it is checking to see if the device is in the group which is not what you want (since there is no "Unused Ports" device group, only an interface group).

 

What you would want to do instead is something like this (not tested or even syntax checked, but hopefully gets the idea across):

 

<PolicyRuleLogic editor='raw-xml'>
<ForEach>
  <Expr field="interfaces"/>
  <Do>
    <If>
      <Expr object="_loop_value" op='in-group'>
      <Expr value='Unused Ports'/>
      </Expr>
    <Then>
      <PolicyRuleFail>FailMessage</PolicyRuleFail>
    </Then>
    <Else>
      <PolicyRulePass/>
    </Else>
    </If>
  </Do>
</ForEach>
</PolicyRuleLogic>

What that does is loop through all the interfaces on the device, and checks each one for membership in the Unused Ports group. Instead of doing the Pass/Fail in the loop though, you should probably count the passes and failures and just pass or fail once at the end.

 

John

 

 

Re: in-group xml usage

Adviser
Posts: 353
6263     0

Do be clear, the 'field="interfaces"' piece is a call to the "interfaces" method on the implicit device object. You can call methods on other objects too, using the object= attribute.

 

Re: in-group xml usage

Authority
Posts: 27
6263     0

Hello Mr. Belamaric,

    I was afraid that the device wouldn't be the group member, and was just a field for the actual member. I will try this out and update the thread. Also, is there a place that lists all the _variable variables? I have learned the _block, _match, and now _loop_value from these threads.

 

Thank you,

Jerry

Re: in-group xml usage

Authority
Posts: 27
6263     0

Hello Mr. Belamaric,

    I was afraid that the device wouldn't be the group member, and was just a field for the actual member. I will try this out and update the thread. Also, is there a place that lists all the _variable variables? I have learned the _block, _match, and now _loop_value from these threads.

 

Thank you,

Jerry

Re: in-group xml usage

Adviser
Posts: 353
6263     0

The XSD should contain them all. If not, we need to update it, so let us know if you find out about one and it's not documented there.

 

 

Re: in-group xml usage

Authority
Posts: 27
6263     0

Hey Mr. Belamaric,

   I tried your code, and I had to add <Return></Return> wrapping <PolicyRuleFail></PolicyRuleFail>. Other than that, your code worked!

 

Thank you,

- Jerry

 

P.S. I will check the document and update.

Re: in-group xml usage

Authority
Posts: 27
6263     0

Sir,

 

  The only ones mentioned in the XSD was _message, _lineo, _loop_counter, _loop_value. These were under the explination of other elements and not explaining the actual _variable itself.

 

Thank you,

- Jerry

Showing results for 
Search instead for 
Did you mean: 

Recommended for You