DX NetOps

 View Only
  • 1.  get alarm details by API

    Posted Mar 13, 2019 09:42 AM

    I've already searched the community, but until now I'm not able to get any details for an alarm id.

     

    Querying the API using GET

     

    /spectrum/restful/alarms

    This returns:

     

        <?xml version="1.0" encoding="UTF-8" standalone="yes"?><alarm-response-list xmlns="http://www.ca.com/spectrum/restful/schema/response" error="EndOfResults" throttle="1" total-alarms="1"><alarm-responses><alarm id="5ac628c3-0008-1000-0203-008010245a1c"/></alarm-responses></alarm-response-list>

    Which endpoint should I use to get details about the alarm?

    I already tried:

     

        /spectrum/restful/alarms/5ac628c3-0008-1000-0203-008010245a1c

        /spectrum/restful/alarms/?id=5ac628c3-0008-1000-0203-008010245a1c

        /spectrum/restful/alarms/?alarm_id=5ac628c3-0008-1000-0203-008010245a1c

     

    Until now nothing from these resulted in a valid response.



  • 2.  Re: get alarm details by API

    Posted Mar 13, 2019 09:52 AM

    Hey Janis,

     

    You will need to POST, and include this in the body:

     

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

    <!--

     

     

       CA Technologies, Inc.

       One CA Plaza

       Islandia, NY 11749 USA

     

       Copyright (c) 2012 CA Technologies, Inc.

       All rights reserved.

     

       IN NO EVENT SHALL CA TECHNOLOGIES INCORPORATED BE LIABLE FOR

       ANY INCIDENTAL, INDIRECT, SPECIAL, OR CONSEQUENTIAL DAMAGES

       WHATSOEVER (INCLUDING BUT NOT LIMITED TO LOST PROFITS) ARISING OUT

       OF OR RELATED TO THIS SOFTWARE, EVEN IF CA TECHNOLOGIES INCORPORATED

       HAS BEEN ADVISED OF, KNOWN, OR SHOULD HAVE KNOWN, THE POSSIBILITY OF

       SUCH DAMAGES.

     

     

    -->

     

    <rs:alarm-request throttlesize="10"

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

     

        <!--

             This xml can be posted to the Alarms URL to obtain

             attributes on the specified alarms

          -->

         

        <!-- Attributes of Interest -->

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

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

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

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

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

       

        <!-- Alarms of Interest -->

        <rs:alarms id="4d2cc290-4854-1000-026e-0023aeab765c" />

        <rs:alarms id="4d2cc31a-9434-1002-034e-0080102af862" />

     

    </rs:alarm-request>

     

    This would return something like this:

     

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

    <alarm-response-list xmlns="http://www.ca.com/spectrum/restful/schema/response" error="EndOfResults" throttle="2" total-alarms="2">

        <alarm-responses>

            <alarm id="5b510783-cece-1002-03b1-005056830acd">

                <attribute id="0x11f53">0x100a1c</attribute>

                <attribute id="0x10000">MCastGroup</attribute>

                <attribute id="0x11f56">3</attribute>

                <attribute id="0x12b4c">SOURCE TRAFFIC APPEARS TO BE ZERO</attribute>

                <attribute id="0x11f4d">false</attribute>

            </alarm>

            <alarm id="5b97a0cf-397c-1036-03b1-005056830acd">

                <attribute id="0x11f53">0x10007d</attribute>

                <attribute id="0x10000">Rtr_Cisco</attribute>

                <attribute id="0x11f56">3</attribute>

                <attribute id="0x12b4c">CHASSIS DOWN</attribute>

                <attribute id="0x11f4d">false</attribute>

            </alarm>

        </alarm-responses>

    </alarm-response-list>

     

    You can obviously change the requested attributes to what you want to see.

    From here:

     

    https://docops.ca.com/ca-spectrum/10-2-3/en/programming/web-services-api-reference/how-to-use-the-ca-spectrum-web-services-api/restful-resources-nouns/alarm-and-model-attributes

     

    Hope this helps.

     

    -Matt

     



  • 3.  Re: get alarm details by API

    Posted Mar 13, 2019 10:13 AM

    You mean using curl like this:

     

    curl -u user:pass-d "xml version=1.0&encoding=UTF-8&alarms id=5ac628c3-0008-1000-0203-008010245a1c" -X POST http://127.0.0.1:8080/spectrum/restful/alarms



  • 4.  Re: get alarm details by API

    Posted Mar 13, 2019 10:23 AM

    Curl would be a command line way of doing it, yes.

    You could put the XML into a file.

     

    Then do something like:

     

    curl -X POST -d @myfilename http://user:pass@myhost/hudson/job/_jobName_/postBuildResult

     

    Making sure to also pass the BASIC AUTH that OneClick uses.

     



  • 5.  Re: get alarm details by API

    Posted Mar 13, 2019 10:30 AM

    Using curl like mentioned above by me is returning an empty response. Are the fields set correctly for spectrum?

     



  • 6.  Re: get alarm details by API

    Posted Mar 13, 2019 10:48 AM

    You will also have to set the content type when doing it command lind.

     

    Like this:

     

    curl -X POST -H 'Content-type: application/xml' -d @testfile.xml  pass@hostname.domain.com:port/spectrum/restful/alarms?symptoms=no" rel="nofollow" target="_blank">http://user:pass@hostname.domain.com:port/spectrum/restful/alarms?symptoms=nopass@hostname.domain.com:port/spectrum/restful/alarms?symptoms=no



  • 7.  Re: get alarm details by API

    Posted Mar 14, 2019 05:14 AM

    I was using:

     

    curl -v -X POST --header 'content-type:application/xml' -d test.xml --user spectrum:spectrum http://localhost:8080/spectrum/restful/alarms > userliste_output.xml

     

    Where test.xml contains:

     

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


    <rs:alarm-request throttlesize="10"

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

    <!-- Attributes of Interest -->

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

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

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

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

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


    <!-- Alarms of Interest -->

    <rs:alarms id="5ac628c3-0008-1000-0203-008010245a1c" />


    </rs:alarm-request>

    This returns:

     

    JAXBException occurred : Content is not allowed in prolog.. Content is not allowed in prolog.. 



  • 8.  Re: get alarm details by API
    Best Answer

    Posted Mar 14, 2019 07:46 AM

    Try putting the "@” in front of the file name like I have in mine.

    I tested my query and it works - so its just minor changes to get yours to work.

     

    So like this:

     

    curl -v -X POST --header 'content-type:application/xml' -d @test.xml --user spectrum:spectrum http://localhost:8080/spectrum/restful/alarms > userliste_output.xml