DX NetOps

Expand all | Collapse all

How can I get the device id and the id interface that appears in the URL for a given device name and its interface

  • 1.  How can I get the device id and the id interface that appears in the URL for a given device name and its interface

    Posted Mar 07, 2019 06:58 AM

    Hi,

     

    when I see the detail of a device or interface in the CA performance center no url vai o InterfaceID e o DeviceID, for example:

     

    https://<ip_address>:8182/pc/desktop/page?pg=r&DeviceID=271 


    https://<ip_address>:8182/pc/desktop/page?pg=i&InterfaceID=8802


    https://<ip_address>:8182/pc/desktop/page?pg=i&InterfaceID=8802&tnid=40001

     

    when doing a query in database using ODATA the devices ID's and InterfaceID's are different from what appears in the URL.

     

    In ODATA query result:

     

    interface

    ID

    DeviceItemID

    9163413

    9128546

     

    How can I get the device id and the id interface that appears in the URL for a given device name and its interface?

     

    I need this because I'm developing a tool that builds the url automatically to see the detail in the performance center.

     

    Thank you.

     

    David Fernandes



  • 2.  Re: How can I get the device id and the id interface that appears in the URL for a given device name and its interface

    Broadcom Employee
    Posted Mar 07, 2019 07:49 AM

    Hi David:

     

    The id in the URL is CAPC's ItemID for the device in the mysql database. 

     

    Example:

     

    SourceID: 3
    LocalID: 9358
    ItemSubTypeName: server
    ItemID: 1241

     

    I would think that would equate to the deviceitemid.  What does the query look like?

     

    Joe



  • 3.  Re: How can I get the device id and the id interface that appears in the URL for a given device name and its interface

    Posted Mar 07, 2019 09:23 AM

    Hi,

     

    For this particular case, the query in ODATA returns this:

     

    interface

    ID

    DeviceItemID

    Name

    Description

    DisplayDescription

    DisplayName

    AlternateName

    9163413

    9128546

    Bundle-Ether1

    Bundle-Ether1

    Bundle-Ether1

    Bundle-Ether1 - Bundle-Ether1

    Bundle-Ether1

     

    and either the device id or the id interface are different from the IDs that appear in the URL.

     

    BR

     

    David



  • 4.  Re: How can I get the device id and the id interface that appears in the URL for a given device name and its interface

    Broadcom Employee
    Posted Mar 07, 2019 09:38 AM

    David,

     

    This is because ODATA is based off of the Data Aggregator/Data Repository only.  As Joe mentioned the URL's are based off of CAPC and use its itemid.  They are not the same number.  CAPC consolidates potentially multiple data sources together (DA, Spectrum, NFA etc) and assigns the consolidated item, an itemid.  It is this id that you see in the CAPC Report URL and it is this id that you cannot use for ODATA.  You cannot get CAPC's itemid (the one in the URL) from the Data Aggregator.

     

    Troy



  • 5.  Re: How can I get the device id and the id interface that appears in the URL for a given device name and its interface

    Posted Mar 07, 2019 12:01 PM

    Hi,

     

    Thanks for the answer.

     

    By the way, I'm an end user of the CA platform that we have in our company, so there are issues and terms related to the administration of the CA platform that I am not entirely comfortable with.

     

    So, there is a way to get the CAPC's itemid? To map CAPC's itemid and the IDs I get from the Data Aggregator?

     

    BR.

     

    David



  • 6.  Re: How can I get the device id and the id interface that appears in the URL for a given device name and its interface

    Broadcom Employee
    Posted Mar 07, 2019 12:54 PM

    David,

     

    Unfortunately short of directly querying the MySQL database which can be dangerous, something that is not even on the DA and ultimately is not supported, there is no current way to "convert" the DA itemid into the CAPC counterpart.  The DA has no idea of CAPC's consolidation efforts.

     

    This would likely be something to fall under the category of an Enhancement Request/Idea.  To take it down that route you would want to post an "Idea" on this forum for Community and Product Owner/Management consideration.

     

    Troy



  • 7.  Re: How can I get the device id and the id interface that appears in the URL for a given device name and its interface

    Broadcom Employee
    Posted Mar 07, 2019 01:34 PM

    David,

     

    Apologies but after some more digging I found a method that may work for you but will require some parsing/additional scripting on your part.

     

    Data Sources Web Service - CA Performance Management - 3.6 - CA Technologies Documentation 

     

    Specifically the "Get item IDs from local IDs" section.  An example:

     

    The device I am looking for the CAPC id for, in the DA has the id of 5190.  The name of my Data Aggregator is: "Data Aggregator@rontr01-Z90210", utilizing the HTML codes for space and @ and it would be: Data%20Aggregator%40rontr01-Z90210.  Taking that information, we can construct our CURL command:

     

     

    curl -k -u admin:admin --header 'Content-Type: application/xml' --request POST --data '<LocalIDs><LocalID ID="5190"/></LocalIDs>' --url https://rontr01-Z8675309:8182/pc/center/webservice/datasources/dataSourceConsoleName/Data%20Aggregator%40rontr01-Z90210/itemids

     

    If you pull it apart you will have:

     

    1. -k, as I am using a self-signed and not trusted cert for HTTPS, this tells CURL to ignore the error

    2. -u, the CAPC username and password

    3. --header 'Content-Type: application/xml', this is the required header for REST calls in CAPM

    4. --request POST, the method we are utilizing for this call

    5. --data '<LocalIDs><LocalID ID="5190"/></LocalIDs>', broken out, this is the body of the request:

     

    <LocalIDs>

       <LocalID ID="5190"/>

    </LocalIDs>

     

    6. --url ...... , There are other possible methods of constructing the URL as the documentation mentions that you can use the data source id as well as its GUID but I figured the console name was likely the easiest.

     

    The response will look something like this:

     

    <?xml version="1.0" encoding="UTF-8"?><ItemIDResults><ItemIDResult LocalID="5190" ItemID="171"/></ItemIDResults>

     

    In this case, the DA Item ID = 5190 and the CAPC Item ID = 171

     

    Regards,

    Troy



  • 8.  Re: How can I get the device id and the id interface that appears in the URL for a given device name and its interface

    Posted Apr 08, 2019 11:41 AM

    Hi,

     

    I was able to successfully extract the CAPC ID with the curl command:

     

    $ curl -k -u user:pass --header 'Content-Type: application/xml' --request POST --data '<LocalIDs><LocalID ID="9528017"/></LocalIDs>' --url https://rhtpcapc001:8182/pc/center/webservice/datasources/dataSourceConsoleName/Data%20Aggregator%40RHTPCADA201/itemids

     

    Result:

     

    <?xml version="1.0" encoding="UTF-8"?><ItemIDResults><ItemIDResult LocalID="9528017" ItemID="828570"/></ItemIDResults>

     

    I built a python script to run the curl command and extract the CAPC ID

     

    #!/usr/bin/python

    import requests
    import urllib3
    import json

    urllib3.disable_warnings()


    headers = {
       
    'Content-Type': 'application/xml',
    }

    data = {
     
    '<LocalIDs><LocalID ID': '"9528017"/></LocalIDs>'
    }

    response = requests.post(
    'https://rhtpcapc001:8182/pc/center/webservice/datasources/dataSourceConsoleName/Data%20Aggregator%40RHTPCADA201/itemids', headers=headers, data=data, verify=False, auth=('user', 'pass'))

     

    print (response.headers['Content-Type']) 

     

    print (response.headers) 

     

    print (response.text)

     

    print (response.content)

     

    print (response.reason)

     

     

    however it is giving me an error when I run the script:

     

    text/plain

     

    {'Set-Cookie': 'JSESSIONID=13fkizsp7jiqi1mb4pdtiy3xaf;Path=/pc;Secure', 'Expires': 'Thu, 01 Jan 1970 00:00:00 GMT', 'Content-Type': 'text/plain', 'Date': 'Mon, 08 Apr 2019 15:35:23 GMT', 'Content-Length': '173', 'Server': 'Jetty(9.3.5.v20151012)'}

     

    JAXBException occurred : ParseError at [row,col]:[1,1]

    Message: Content is not allowed in prolog.. ParseError at [row,col]:[1,1]

     

    Message: Content is not allowed in prolog..

     

    b'JAXBException occurred : ParseError at [row,col]:[1,1]\nMessage: Content is not allowed in prolog.. ParseError at [row,col]:[1,1]\nMessage: Content is not allowed in prolog.. '

     

    Bad Request

     

    I have no idea what the error means:

     

    ParseError at [row, col]: [1,1]

    Message: Content is not allowed in prolog .. ParseError at [row, col]: [1,1]

     

     

    BR

     

    David



  • 9.  Re: How can I get the device id and the id interface that appears in the URL for a given device name and its interface

    Broadcom Employee
    Posted Apr 08, 2019 12:04 PM

    David,

     

    I have not used the functionality you have constructed or similar but by searching on "content is not allowed in prolog" you can find a few things like:

     

    java - "Content is not allowed in prolog" when parsing perfectly valid XML on GAE - Stack Overflow 

     

    You may want to check into what encoding your parser is using.  You can see in the result, CAPM is using UTF-8, match that.

     

    Troy



  • 10.  Re: How can I get the device id and the id interface that appears in the URL for a given device name and its interface

    Posted Apr 08, 2019 12:52 PM

    Hi,

     

    When I print the encoding I received in response I have this:

     

    print (response.encoding)

     

    ISO-8859-1

     

    What is really strange because as you said, the encoding is “UTF-8”

     

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

     

    seeing the requests documentation


     

    http://docs.python-requests.org/en/master/user/advanced/

    Encodings

    When you receive a response, Requests makes a guess at the encoding to use for decoding the response when you access the Response.text attribute. Requests will first check for an encoding in the HTTP header, and if none is present, will use chardet to attempt to guess the encoding.

    The only time Requests will not do this is if no explicit charset is present in the HTTP headers and the Content-Type header contains text. In this situation, RFC 2616 specifies that the default charset must be ISO-8859-1. Requests follows the specification in this case. If you require a different encoding, you can manually set the Response.encoding property, or use the raw Response.content.

     

    in this case the parser should see that the encoding is "UTF-8" but it looks like it can not read and uses the default charset ISO-8859-1

     

    BR

     

    David