TECHZEN Zenoss User Community ARCHIVE  

API call to addThreshold in Zenoss 5

Subject: API call to addThreshold in Zenoss 5
Author: Alastair Drong
Posted: 2017-05-15 18:51

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


Subject: RE: API call to addThreshold in Zenoss 5
Author: Tim Caiazza
Posted: 2017-05-16 10:17

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.


Subject: RE: API call to addThreshold in Zenoss 5
Author: Alastair Drong
Posted: 2017-05-16 15:20

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.


Subject: RE: API call to addThreshold in Zenoss 5
Author: Alastair Drong
Posted: 2017-05-16 16:32

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


Subject: RE: API call to addThreshold in Zenoss 5
Author: Jay Stanley
Posted: 2017-05-16 17:28

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


Subject: RE: API call to addThreshold in Zenoss 5
Author: Alastair Drong
Posted: 2017-05-18 13:55

Extremely helpful. Thanks!


Subject: RE: API call to addThreshold in Zenoss 5
Author: Ron Phillips
Posted: 2017-05-17 12:01

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



Subject: RE: API call to addThreshold in Zenoss 5
Author: Ron Phillips
Posted: 2017-05-17 12:04

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


< Previous
JSON event query less then or greater than
  Next
Set Threshold as percentage of a data point
>