DX NetOps

Expand all | Collapse all

Spectrum rest API filter

  • 1.  Spectrum rest API filter

    Posted 10-15-2015 03:42 AM

    Hello All

     

    I am trying to receive some data from spectrum for our CMDB.

    Now I have the following which works.

     

    Now the problem is that I have another spectrum where there are more landscapes and I only want models from on specific landscape

     

    http://IP_SPECTRUM/spectrum/restful/model?

    <rs:model-request throttlesize='10000' 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'>

                        <devices-only-search />

                        <filtered-models> 

                            <is-derived-from>

                                <model-type>0x1004b</model-type>

                            </is-derived-from>

                        </filtered-models>

                    </rs:search-criteria>

                </rs:models-search>

            </rs:target-models>

            <rs:requested-attribute id='0x1006e' />

            <rs:requested-attribute id='0x10000' />

            <rs:requested-attribute id='0x12d7f' />

            <rs:requested-attribute id='0x12d80' />

            <rs:requested-attribute id='0x12dbd' />

            <rs:requested-attribute id='0x12a1f' /> 

            </rs:model-request>

     

    Invoke-RestMethod -Uri $spectrumHost -Credential $Credential -Body $xml -ContentType "application/xml" -Method Post

     

    Now I want to extend this with a landscape filter.

    Can somebody tell me what to add ?

     

    I already tried  http://IP_SPECTRUM/spectrum/restful/model?landscape=0x4....   but with the GET Tunneling this parameter is ignored.

     

    I hope someone can help me

     

    Greetings

    Brent



  • 2.  Re: Spectrum rest API filter

    Posted 11-11-2015 04:42 PM

    Hi,

    sorry I have not all the code on this current notebook, but lets explain it a bit.

    1. You could combine different methods to fetch and filter the searched models.

    Why not filtering by Modeltype and Modelhandle or other attributes?

     

    <filtered-models>

    <and>

    .. some filters

    <model-type>0x1004b</model-type>

    <equals><attribute id="0x129fa"><value>abcdefg</value></attribute></equals>

    </and>

     

    I have once build a filter where I searched for the model-handles in the range of the possible modelhandles of a landscape. .. it worked but was not buitiful from the development-side. .. in this case I was able to use the integer-values or the hex-values... long time ago.

     

    .. yes, If You use Post, then You cannot add GET-Parameters.

    I tried same ...

     

    Best Regards

    Erich



  • 3.  Re: Spectrum rest API filter

    Posted 11-26-2015 10:26 AM

    This is what I use to limit landscape scope within a query. Make sure this is surrounded with an AND tag.

     

    e.g. model handle is "greater than 0x400000" and "less than 0x4fffff".

     

                     <greater-than>

                      <attribute id="0x129fa">

                        <value>LANDSCAPEHEX00000</value>

                      </attribute>

                    </greater-than>

                    <less-than>

                      <attribute id="0x129fa">

                        <value>LANDSCAPEHEXfffff</value>

                      </attribute>

                    </less-than>



  • 4.  Re: Spectrum rest API filter

    Posted 11-27-2015 05:01 AM

    Yes sadly there is no way to specify landscape handles. You have to use the ModelHandle as explained by lutelewis. This is how I do it as well.

     

    If have have specific landscapes in-between others, you have to specify the upper and lower ranges of model handles for each landcape.

     

    For the range of models on a landscape it is:

     

    Landscape handle (start of models)

     

    to

     

    Landscape handle with last 5 characters changed to 5 'f's ('fffff')

     

    eg. Landscape 0x100000 has models up to '0x1fffff', and

    Landscape 0x2a00000 contains models up to '0x2afffff'.



  • 5.  Re: Spectrum rest API filter

    Posted 12-08-2015 04:50 AM

    You could as well put the models you are interested in, in a Global Collection (where you can easily filter on the landscape), and then get the content of the Global Collection with the REST API, with something like:

     

    <?xml version="1.0" encoding="UTF-8"?>

    <rs:model-request throttlesize="60000"

    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>

    <and>

    <has-substring><attribute id="0x12adb"> <value>$GLOBAL_COLLECTION_NAME</value> </attribute></has-substring>

    </and>

    </filtered-models>

    </rs:search-criteria>

    </rs:models-search>

    </rs:target-models>

    <rs:requested-attribute id="0x12a1f" />

    </rs:model-request>

     

    Cheers, Veronique