ZenPacks and JSON API

Topic: API call to addThreshold in Zenoss 5

  • User Created
  • addThreshold
  • TemplateRouter
  • JSON API

1.  API call to addThreshold in Zenoss 5

Posted 14 days ago
Edited by Alastair Drong 14 days ago
Hi All,
Using the API I've been able to:
- add a host
- add a template
- add a data source
- set the OID on the data source

Currently I'm stuck on trying to add a threshold. Here's the JSON I'm sending to Zenoss 5
{
  "action": "TemplateRouter",
  "tid": 1,
  "data": [
    {
    "thresholdId": "2_YEAR_UPTIME",
    "thresholdType": "MinMaxThreshold",
    "uid": "/zport/dmd/Devices/Server/Linux/rrdTemplates/TestUptime",
    "dataPoints": ["/zport/dmd/Devices/Server/Linux/rrdTemplates/TestUptime/datasources/TestUptimeDS"]
    }
  ],
  "method": "addThreshold"
}

Here's what Zenoss is sending back:
{
  "uuid": "3ac9af6b-6de6-4fb4-a88a-6c39d3440154",
  "tid": 1,
  "result": {
    "msg": "AttributeError: name",
    "type": "exception",
    "success": false
  },
  "action": "TemplateRouter",
  "type": "rpc",
  "method": "addThreshold"
}

Clearly it's expecting a 'name' attribute in the data I'm sending, but I haven't been able to make it happy. Does anyone have an example of what my JSON needs to look like here?

Thanks


2.  RE: API call to addThreshold in Zenoss 5

Posted 13 days ago
I was able to get this to work by posting the following

[{'action': 'TemplateRouter',
'data': [{
  'dataPoints': ['/zport/dmd/Devices/Network/rrdTemplates/ethernetCsmacd_64/datasources/ifHCInMulticastPkts/datapoints/ifHCInMulticastPkts'],
'thresholdId': 'Threshold Name',
'thresholdType': 'MinMaxThreshold',
'uid': '/zport/dmd/Devices/Network/rrdTemplates/ethernetCsmacd_64'}],
'method': 'addThreshold',
'tid': 0,
'type': 'rpc'}]



Unfortunately I can't see the difference between our two data sets, besides the obvious.  I also get different error messages if I set the uid or datapoints to something I know is wrong.  FYI I'm doing this with a zenoss 5 instance.

------------------------------
FirstName LastName
CompanyName
------------------------------



3.  RE: API call to addThreshold in Zenoss 5

Posted 13 days ago
Hm. Thanks. I noted that you've got a 'type':'rpc' in your call, but that didn't make a difference when I added it to mine. What is the full version number on Zenoss that you're running? I'm on Zenoss 5.2.2 r331. If you're on newer, I'll be curious to read through any release notes to see if maybe this was a bug that's been fixed.


4.  RE: API call to addThreshold in Zenoss 5

Posted 13 days ago
Edited by Alastair Drong 13 days ago
Can you tell me how you identified your 'datapoints' path? I was successful when I realized that I was missing '/datapoints/TestUptime' from the end of my 'dataPoints' value. This is what the complete JSON text should look like.

{
  "action": "TemplateRouter",
  "tid": 1,
  "data": [
    {
      "thresholdId": "2_YEAR_UPTIME",
      "thresholdType": "MinMaxThreshold",
      "uid": "/zport/dmd/Devices/Server/Linux/rrdTemplates/TestUptime",
      "dataPoints": [
        "/zport/dmd/Devices/Server/Linux/rrdTemplates/TestUptime/datasources/TestUptimeDS/datapoints/TestUptimeDS"
      ]
    }
  ],
  "method": "addThreshold"
}


5.  RE: API call to addThreshold in Zenoss 5

Posted 13 days ago
datapoints is a relationship to datasource. You can get the full uid from zendmd or using developer tools and looking at the calls the UI makes when doing certain actions.

The Web UI uses the JSON API 100%. So, if you are ever trying to figure out how to do something with the API, pull up developer tools and see what headers are sent to the router.

Here is an example of me adding a threshold, then adding datapoints.





------------------------------
jstanley
------------------------------



6.  RE: API call to addThreshold in Zenoss 5

Posted 11 days ago
Extremely helpful. Thanks!


7.  RE: API call to addThreshold in Zenoss 5

Posted 12 days ago
Alastair,

Could you try adding "type":"rpc" to your post data and see if that works?  That's the only thing I can see in my data that isn't in yours.  Let me know how it goes.

Ron






8.  RE: API call to addThreshold in Zenoss 5

Posted 12 days ago
I should have checked here rather than sending it from the email digest.  Like jstanley mentioned; try to add it through the UI with your browser's developer tools open, then check the post data sent to the template router and compare it to what you're trying to use.

------------------------------
Ron Phillips
Senior Staff Engineer
Zenoss
------------------------------