DX NetOps

 View Only
Expand all | Collapse all

Cannot create models in Spectrum using RESTful API

  • 1.  Cannot create models in Spectrum using RESTful API

    Posted Jul 28, 2015 02:38 PM

    I'm trying to create models using the POST operation but nothing happens. I can't even modify an attribute to an existing model (e.g. the model name) by using the PUT operation.

     

    for the POST operation, I'm using this URL:

    http://SERVER-IP:PORT/spectrum/restful/model?landscapeid=0x500000&mtypehandle=0x3d0002&port=161&commstring=MY-COMM-STRING&retry=1&timeout=1000&ipaddress=181.30.11.226&parentmh=0x10091&attr=1006e&val=RestSNMP

     

    That means, I'm trying to create a GnSNMPDev model (mtypehandle=0x3d0002) in the SS05 (landscapeid=0x50000) whose parent model is the Universe (parentmh=0x10091) and I want to name this model I'm creating like RestSNMP (attr=1006e&val=RestSNMP)

     

    I've tried using two different environments (one for lab and one productive) pointing to their correspondent OneClick, without success. I get the same results. I have Spectrum 9.2.3.

     

    The PUT operation just works as if it where a GET operation, because it returns some data, but it does no update the atrribute I want to change.

     

    Any idea?



  • 2.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 28, 2015 03:52 PM

    Hello ElioteArg,

     

    There are a few mistakes in your query above
        The agent port should be &agentport=161 (&port= was a typo in the earlier guides)
        The Model_Name attribute is missing the 0x prefix, should be &attr=0x1006e
        The Parent Model Handle &parentmh= should be the Model_Handle of the Universe model (not the ModelType_Handle), in my case it was 0x200004

     

    ex.

    http://OneClickServer:8080/spectrum/restful/model?landscapeid=0x200000&mtypehandle=0x3d0002&agentport=161&commstring=public&retry=1&timeout=1000&ipaddress=10.10.20.20&parentmh=0x200004&attr=0x1006e&val=RestSNMP

     

    Note: The device will go through modeling so it may not stay of type GnSNMPDev

     

    -Greg



  • 3.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 28, 2015 04:12 PM

    Thanks Greg,

         It's good to know about the typo of the agent port variable

         Yes, I copied it wrongly from the request, in which it was ok actually.

         I noticed that after publishing the post, but thanks for the observation.

     

    However, it is still not working. Should the device be discoverable? I mean, does Spectrum create the model despite it can reach it? Or just if Spectrum can discover it the model is then created?



  • 4.  Re: Cannot create models in Spectrum using RESTful API

    Broadcom Employee
    Posted Jul 28, 2015 04:34 PM

    You can do a "Model By Type" with the REST API by removing the "ipaddress" parameter in the URL and changing that to 0x12d7f (network_address attribute and giving that the value of the ip address). You also need to specify a model type handle.



  • 5.  Re: Cannot create models in Spectrum using RESTful API



  • 6.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 28, 2015 05:02 PM

    It looks like OneClick wants the Model Type Handle as mtypeid, so change &mtypehandle=0x3d0002 to &mtypeid=0x3d0002, remove the

       'dd' after the parentmh and you should be good to go.

     

    I was able to test this with the change scoch03 suggested and changing mtypeid and it works

     

    -Greg



  • 7.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 29, 2015 08:51 AM

    I just ried this without success again:

     

    http://OneClickServer/spectrum/restful/model?landscapeid=0x100000&mtypeid=0x3d0002&agentport=161&commstring=public&retry=1&timeout=1000&parentmh=0x100004&attr=0x1006e&val=RestSNMPdev&attr=0x12d7f&val=181.30.11.226

     

    mtypeid=0x3d0002 (Modeltype_Handle for GnSNMPDev)

    parentmh=0x100004 (Model_Handle of the Universe container)

    attr=0x1006e (Model_Name)

    attr=0x12d7f (Network_Address)

     

    I just don't know what else to do. It seems that only the GET operation is working, as the other three (PUT, POST and DELETE) are doing nothing. I don't get it. I'm logged in with an administrator user in OneClick, and I'm also using these credentials to make tests via API.

     

    Any other idea? Or should I open a Support Ticket by now?



  • 8.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 30, 2015 04:29 AM

    To add SNMP device:

     

    http://<ONECLICK>:<PORT>/spectrum/restful/model?landscapeid=<LANDSCAPE ID>&ipaddress=<IP ADDRESS>&attr=0x1006e&val=<DEVICE NAME>&commstring=<SNMPCOMMUNITY>&port=<SNMP PORT>&parentmh=<PARENT CONTAINER MH>&retry=1&timeout=1000

     

    Just a note: if you want to use SNMPv2, you need to prefix any community value with '#v2/'. If you don't do this it will use SNMPv1.

     

    To add ICMP device:

     

    http://<ONECLICK>:<PORT>/spectrum/restful/model?landscapeid=<LANDSCAPE ID>&mypehandle=0x10001&mtypeid=0x10290&attr=0x1006e&val=<DEVICE NAME>&attr=0x12d7f&val=<IP ADDRESS>&parentmh=<PARENT CONTAINER MG>&retry=1&timeout=1000

     

    This is what works for me anyway.

     

    Regards,


    Frank



  • 9.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 30, 2015 09:31 AM

    Thanks Frank,

    That's what I first tried without any success. By the way, the variable &port is actually &agentport as I've been told a few posts back. And I also read that adding an ICMP device by the REST API was not supported by CA (it just does not make sense to me although).



  • 10.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 30, 2015 10:25 AM

    This definitely works on 9.2.x so I'll test this tonight on Spectrum 10. Perhaps they changed the 'port' to 'agentport' - I'll check that too.

     

    Regarding ICMP models, this is a lie. They said the same to me and it's not true. The example I gave definitely works on 9.2.x. I raised 2 tickets and both times they said it could not be done and we are doing it.

     

    from Command Line:

     

    curl -s -X 'POST' --header 'content-type: application/xml' --user SPECUSER:SPECPASS "http://SERVER:8080/spectrum/restful/model?landscapeid=0x1200000&ipaddress=192.168.1.10&attr=0x1006e&val=testServer&commstring=public&port=161&parentmh=0x12d31c2&retry=1&timeout=1000"

     

    This produced:

     

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?><create-model-response xmlns="http://www.ca.com/spectrum/restful/schema/response" error="Success"><model mh="0x12d0003"/></create-model-response>

     

    Remember to use quotes if you have spaces in your name - eg: 'test Server'. You don't need quotes if it's one string with no spaces.

     

    You will need to install curl if you don't have it but I've tested this on a Linux host and it works.



  • 11.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 30, 2015 09:10 AM

    I just took you POST and made only a few minor changes for my env:

     

    http://192.168.2.101:8080/spectrum/restful/model?landscapeid=0x1900000&mtypeid=0x3d0002&agentport=161&commstring=public&…

     

    and the device modeled successfully.

     

    You mentioned GET is working but PUT POST and DELETE are not. What are you using to submit you POST?

     

    Joe



  • 12.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 30, 2015 10:38 AM

    for these two calls I used:

     

    curl -s -X 'POST' --header 'content-type: application/xml' --user <SPECUSER>:<SPECPASS> "http://<ONECLICK>:<PORT>/spectrum/restful/model?landscapeid=<LANDSCAPE ID>&ipaddress=<IP ADDRESS>&attr=0x1006e&val=<DEVICE NAME>&commstring=<SNMPCOMMUNITY>&port=<SNMP PORT>&parentmh=<PARENT CONTAINER MH>&retry=1&timeout=1000"

     

    This is the command line version using curl - I use the 'LWP' module in perl.

     

    I can confirm this works currently with 9.2.x with both ICMP and SNMP.

     

    The GET doesn't make sense to use here. Most of the times GET is used to get values from Spectrum only (except in some cases where you want to trigger an Inference Handler)

    DELETE makes no sense here either

    and PUT just didn't work after I tested it.

     

    This is the info I wish they would put in their documentation. It's been a painful ride so far trying to work this stuff out, where a well documented API guide would have been ideal. I've used other REST API's like the Cisco Prime Infrastructure and it's just so well documented (although fails to provide good example code).



  • 13.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 30, 2015 11:29 AM

    @EliotArg

     

    What are you using to submit your post?

     

    Joe



  • 14.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 30, 2015 03:52 PM

    Hi ackjo04

    I'm just testing with Chrome by putting the URL directly in the address bar of the browser. I also tried in IE, but it didn't work either, as expected.



  • 15.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 30, 2015 04:17 PM

    Ahh! That is what I thought! You cannot use a browser for POST. You have to use something like culr as mentioned by franktonjes or perle or Python or Ruby. I use RESTClient 2.4.

     

    Joe



  • 16.  Re: Cannot create models in Spectrum using RESTful API

    Posted Jul 30, 2015 04:53 PM

    I use the 'Advanced Rest Client' plugin for Chrome which is nice and easy for testing

     



  • 17.  Re: Cannot create models in Spectrum using RESTful API

    Posted Aug 03, 2015 02:56 PM

    Great! That made it. I'm not familiar with this yet. I think I should have known that I was not going to be able to POST anything by putting the information directly in the URL.

    Thanks!