REST query to pull all models based on an specific attribute value.
search cancel

REST query to pull all models based on an specific attribute value.

book

Article ID: 399063

calendar_today

Updated On:

Products

Network Observability

Issue/Introduction

You are trying to get list of devices via REST that have the USER ASSET TAG attribute populated with a string that contains the word "maintenance" as part of the attribute value.

Resolution

This comparison will pull all devices that have the user asset tag contain the string "maintenance" i.e. "maintenance xxx" or "maintenance yyy"
 
with a REST client POST to  
 
https://<OC host>:<OC port>/spectrum/restful/models
 
<?xml version="1.0" encoding="UTF-8"?>
<rs:model-request throttlesize="5"
  xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd ">


    <rs:target-models>
      <rs:models-search>
        <rs:search-criteria
             xmlns="http://www.ca.com/spectrum/restful/schema/filter">
          <filtered-models>
            <has-substring>
   <attribute id="0x12bfb"> <!--USER ASSET TAG attribute -->
                <value>maintenance</value>
              </attribute>
            </has-substring>
          </filtered-models>
        </rs:search-criteria>
      </rs:models-search>
    </rs:target-models>


<!--Attributes of interest -->


    <rs:requested-attribute id="0x1006e" /><!-- Model name -->
    <rs:requested-attribute id="0x129fa" /><!-- Model handle -->
    <rs:requested-attribute id="0x10000" /><!-- Model Type name -->
    <rs:requested-attribute id="0x12bfb" /><!--USER ASSET TAG attribute -->


</rs:model-request>
 
This gives us 2 models:
 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model-response-list xmlns="http://www.ca.com/spectrum/restful/schema/response" total-models="2" throttle="2" error="EndOfResults">
<model-responses>
<model mh="0x101df63"><attribute id="0x1006e">uptime</attribute><attribute id="0x129fa">0x101df63</attribute><attribute id="0x10000">PhoenixFLRouter</attribute><attribute id="0x12bfb">maintenance xxxx</attribute></model>
<model mh="0x10181be"><attribute id="0x1006e">mxone</attribute><attribute id="0x129fa">0x10181be</attribute><attribute id="0x10000">Host_Device</attribute><attribute id="0x12bfb">maintenance yyyyy</attribute>
</model>
</model-responses>
</model-response-list>
 
 

Additional Information

To pull all devices that have the user asset tag exactly equal to the string "maintenance" you can use the same query but change the comparison from    <has-substring> to   <equals>.
 
   <filtered-models>
            <equals>
			  <attribute id="0x12bfb"> <!--USER ASSET TAG attribute -->
                <value>maintenance</value>
              </attribute>
            </equals>
          </filtered-models>