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:
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.
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
Note: The device will go through modeling so it may not stay of type GnSNMPDev
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?
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.
Do you mean something like this?
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
I just ried this without success again:
mtypeid=0x3d0002 (Modeltype_Handle for GnSNMPDev)
parentmh=0x100004 (Model_Handle of the Universe container)
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?
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.
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).
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"
<?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.
I just took you POST and made only a few minor changes for my env:
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?
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).
What are you using to submit your post?
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.
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.
I use the 'Advanced Rest Client' plugin for Chrome which is nice and easy for testing
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.