DX NetOps Manager

Expand all | Collapse all

Spectrum RESTFul

Jump to Best Answer
  • 1.  Spectrum RESTFul

    Posted 09-22-2014 11:49 AM

    When trying to match deivces with specific model handles, I keep getting the interfaces and child models for those models.

     

    Is there any way to not get these child models?

     

    Even if I use:

     

    <rs:model-request throttlesize="1000"

      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>

              <or>

                <equals>

                  <attribute id="0x129fa">

                    <value>0x1e35cd1</value>

                  </attribute>

                </equals>

                <equals>

                  <attribute id="0x129fa">

                    <value>0x1b07a15</value>

                  </attribute>

                </equals>

                <equals>

                  <attribute id="0x129fa">

                    <value>0x1b07a97</value>

                  </attribute>

                </equals>

                <equals>

                  <attribute id="0x129fa">

                    <value>0x1b021c2</value>

                  </attribute>

                </equals>

              </or>

            </filtered-models>

          </rs:search-criteria>

        </rs:models-search>

      </rs:target-models>

     

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

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

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

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

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

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

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

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

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

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

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

     

    </rs:model-request>

     

    I get the 4 devices including the sub-interfaces and other child models of the parent device.

     

    It seems the '<devices-only-search/>' doesn't make any difference here at all.

     

    Any ideas?

     

    In the returned XML, I also get a lot of  '<model mh="0x1322091" error="NoSuchModel"/><model mh="0x1301171" error="NoSuchModel"/>' which I find unusual.

     

    Thanks,

     

    Frank



  • 2.  Re: Spectrum RESTFul

    Posted 10-29-2014 08:31 PM

    Hi, it seems that there is a bug.

    I have tried the same with version 9.3.3 -  which provides the same.

     

    I tried the query without the "devices-only-search"-tag. - same bug

     

    I tried it then only with one model-handle but the response was for the wrong modelhandle, ... crazy

     

    ..<equals><attribute id="0x129fa"><value>0x4037540</value></attribute></equals>..

     

    the response was for the model 0x100000 ...

     

    Is someone able to query attributes for multiple models ??

     

    Best Regards

    Erich



  • 3.  Re: Spectrum RESTFul

    Posted 11-12-2014 08:50 AM

    Hi all,

    I have correct my last comment. It works, Bug ISO Layer 8 - read the manual.

    It is very simple to request the attributes for models where the model-handles are known.

    I have done it in PHP, - looks like "BASIC" *-).

     

    This example is not the right answer to the question.

    It is not possible to fetch the childmodels for a device and their attributes in one step.

    To get the child-models we have to to fetch the models which have a relation or association to the device.

     

    This is more compareable to the fetch for the Models in a global collection..

    // static assigned to GC

    // http://192.0.1.2:8080/spectrum/restful/associations/relation/0x0001003b/model/0xffe0046f?side=left

    // dynamic assigned to GC

    // http://192.0.1.2:8080/spectrum/restful/associations/relation/0x0001003a/model/0xffe0046f?side=left

     

    The result is a association-response-list and not model-response-list. But this will provide the model-handles of the childs.

    Then, in a second step, it would be possible to fetch the needed attributes per model.

     

    In my case, I fetch attributes for given models, identified by model-handles.

     

    $modelArr is an array out of Model-Handles, for example 0x1234a67 or 0x1234a68

     

    $filter = "<rs:target-models>";

     

    foreach ($modelArr as $modelEntry)

    {

    $filter = $filter . '<rs:model mh="'.  trim($modelEntry) .'"/>';

    }

    $filter = $filter ."</rs:target-models>";

     

    $data     = '<?xml version="1.0" encoding="UTF-8"?><rs:model-request throttlesize="'.$throttlesize.'"

            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 ">';     

     

        if ($filter <> "")

        {   

            $data = $data . $filter ;

        }

      $data = $data .'

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

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

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

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

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

    </rs:model-request>';

     

    Finally it looks like this for these two models 0x1234a67 and 0x1234a68:

    <?xml version="1.0" encoding="UTF-8"?><rs:model-request throttlesize="1000"

            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:model mh="0x1234a67"/>

    <rs:model mh="0x1234a68"/>

    </rs:target-models>

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

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

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

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

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

    </rs:model-request>

     

    Perhaps this helps *-)



  • 4.  Re: Spectrum RESTFul

    Posted 11-12-2014 10:57 AM

    To solve this I use is-derived-from criteria

     

    <is-derived-from>
        <model-type>0x1004b</model-type> <!-- Device -->
    </is-derived-from>
    


  • 5.  Re: Spectrum RESTFul

    Posted 03-11-2015 07:26 AM

    This is what sorted it out. Thanks. I'm just surprised at how it responds without the 'is-derived-from' 'code'.

     

    Yes, e.heinemann your example also works, but I wanted to get it all in one go. We do a lot of restful work and the less individual transactions, the better Thanks all.



  • 6.  Re: Spectrum RESTFul
    Best Answer

    Posted 03-16-2015 10:28 AM

    So the code/request I finally use is:

     

    ---------

     

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    # Make sure you have the following perl modules and their dependencies installed:
    # This might change on your system depending on what libraries you already have installed.
    # libwww-perl, URI, REST-Client, Crypt-SSLeay
    
    use REST::Client;
    
    my $unam = '<SPECTRUM USER>';        # User which REST query runs as
    my $pswd = '<SPECTRUM PASSWORD>';    # Password for above user
    my $server = 'http://<SERVER:PORT>'; # OneClick Server name/IP and port (80 for Windows, 8080 for Linux)
    my $queryType = 'POST';
    my $body = << "END";
    <?xml version="1.0" encoding="UTF-8"?>
    
    <rs:model-request throttlesize="1000"
      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>
              <and>
                <or>
                  <equals>
                    <attribute id="0x12adb">
                      <value>GLOBAL COLLECTION NAME</value>
                    </attribute>
                  </equals>
                  <or>
                    <has-substring>
                      <attribute id="0x12adb">
                        <value>GLOBAL COLLECTION NAME:</value>
                      </attribute>
                    </has-substring>
                    <has-substring>
                      <attribute id="0x12adb">
                        <value>:GLOBAL COLLECTION NAME:</value>
                      </attribute>
                    </has-substring>
                    <has-substring>
                      <attribute id="0x12adb">
                        <value>:GLOBAL COLLECTION NAME</value>
                      </attribute>
                    </has-substring>
                  </or>
                </or>
                <is-derived-from>
                  <model-type>0x1004b</model-type>
                </is-derived-from>
              </and>
            </filtered-models>
          </rs:search-criteria>
        </rs:models-search>
      </rs:target-models>
    
      <rs:requested-attribute id="0x1006e"/>
      <rs:requested-attribute id="0x129fa"/>
    
    </rs:model-request>
    
    END
    
    print "REQUEST: $server/spectrum/restful/models\n\nTYPE: POST\n\nBODY:\n\n$body\n\n";
    
    my $ua = new LWP::UserAgent;
    my $req = new HTTP::Request $queryType, "$server/spectrum/restful/models";
    
    $req->content_type('application/xml');
    $req->content($body);
    $req->authorization_basic($unam, $pswd);
    
    my $res = $ua->request($req);
    my $resultXml;
    
    if ($res->is_error) {
    
      print "ERROR: $res->message\n";
    
    } elsif ($res->is_success) {
    
      $resultXml = $res->decoded_content;
    
    } else {
    
      print "Unknown Error\n";
    
    }
    
    print "RESULT:\n\n$resultXml\n\n";
    

    ---------

     

    We use code to 'iterate' through the results and extract the info. If you need this let me know.

     

    I could have just used the following in the XML body:

     

                  <has-substring>

                      <attribute id="0x12adb">

                        <value>GLOBAL COLLECTION NAME</value>

                      </attribute>

                    </has-substring>

     

     

    but this would have been able to pick up other GC's - eg. if I had a GC called 'GLOBAL' and 'GLOBAL COLLECTION' it would pick up both when searching for 'GLOBAL'. The above method checks for exact matches.

     

    Replace 'GLOBAL COLLECTION NAME' with your Global Collection name. Also change the <SPECTRUM USER>, <SPECTRUM PASSWORD> and <SERVER:PORT> to reflect your environment.

     

    If you have things like '&' in your CG names you need to replace it with '&amp;' - e.g. GC name of 'A, B & C' becomes 'A, B &amp; C'.

     

    Hope this helps.

     

    Regards,

     

    Frank



  • 7.  Re: Spectrum RESTFul

    Posted 03-16-2015 11:54 AM

    Nice! But why don't you just use REST::Client instead of WP::UserAgent and HTTP::Request?



  • 8.  Re: Spectrum RESTFul

    Posted 03-16-2015 11:58 AM

    Good point. This is one of my older components which hasn't changed for a while - I'll have a look.



  • 9.  Re: Spectrum RESTFul

    Posted 03-16-2015 11:25 AM

    Can you please let me know how to paste code as you have done here please?


    Thanks.



  • 10.  Re: Spectrum RESTFul

    Posted 03-16-2015 11:57 AM

    Use the advanced editor (top right corner of the editor window). Once in the advanced editor you click in the last icon of the tollbar (>>) and chose syntax highlight. There is no perl highlight so I just use c++ or php.

     

    It's odd that they don't have perl highlight since CA use it extensively in their tools.



  • 11.  Re: Spectrum RESTFul

    Posted 03-16-2015 12:49 PM

    I use "plain" why highlighting code that isn't in the syntax menu. I've asked for perl (Syntax highlighting for Perl). Please vote it up and they might move it from 'Wish-listed' (aka yeah right) to planned.



  • 12.  Re: Spectrum RESTFul

    Posted 02-20-2015 12:35 PM

    Instead of pulling back 0x129fa use the "Significant_ID" 0x12a56.



  • 13.  Re: Spectrum RESTFul

    Posted 09-14-2015 03:32 AM

    Hello, Frank.

     

    Thank you for your post. It is very usefull.