Mango REST API -- event detectors
-
Re: How do I create event detectors using the Mango API?
Hi all,
I see that event-detectors is now part of the API :)
I'm trying to create multiple event detectors for the same multi-state data point; is that possible to do in one single step?
At the moment I'm trying to do a single event detector using the POST method through the API and using this code (obtained via GET for another data point, and changing the xid, dataSourceId and dataPointId) -- it doesn't work, though, and I get an error 500 back.
{ "xid": "socket_2026-vacant", "name": "Socket 2026 is vacant", "duration": 0, "durationType": "SECONDS", "alarmLevel": "INFORMATION", "supportedDataTypes": [ "MULTISTATE" ], "description": "Socket 2026 is vacant", "alias": "Socket 2026 is vacant", "eventType": { "dataSourceId": 229, "dataPointId": 400, "duplicateHandling": "IGNORE", "typeName": "DATA_POINT", "rateLimited": false }, "rtnApplicable": true, "detectorSourceType": "DATA_POINT", "validationMessages": [], "detectorType": "MULTISTATE_STATE" }
I want these event detectors to be created immediately after the data points are created, so I'm using response.data.id and response.data.dataSourceId to get this info.
I would think that these two ids are enough to link the event detector with the data point? What am I doing wrong here? And can I create multiple event detectors at once?
Thanks and sorry for so many questions ^^U
Silvia
-
@silvia Have you checked the response from the API in the developer tools? There should be an error message.
I have used the API to create high/low limit event detectors posting something like this
{ "xid": "", "name": "", "limit": 1500, "resetLimit": 0, "notHigher": false, "useResetLimit": false, "duration": 60, "durationType": "SECONDS", "alarmLevel": "WARNING", "supportedDataTypes": [ "NUMERIC" ], "alias": "", "detectorSourceType": "DATA_POINT", "sourceId": 123, "rtnApplicable": true, "validationMessages": [], "detectorType": "HIGH_LIMIT" }
Try removing the eventType property. Also try without an XID and name.
-
Silvia,
One option for doing large configuration additions/changes is to use the /rest/v2/json-emport endpoints. Data points have an array of event detectors (like in the regular import/export, though that may change and even detectors may move into their own array) and very large configurations can be submitted for import at once.
-
@Jared-Wiltshire, @phildunlap, thanks for your answers. Because I'm trying to create 5 events for each data point, it'd rather do it in bulk importing the JSON.
I can easily import using the 'Import' tab.
However, if I try to do the same through the API (either using POST /v1/json-emport or /v1/json-emport/upload-file), I get error 202 - no content.
These are the response headers:
{ "Location": "http://192.168.100.254:8080/rest/v1/json-emport/import/IMPORT_e85e1010-ed81-46c3-bc02-2a24637e1065", "Date": "Wed, 15 Nov 2017 09:33:46 GMT", "Cache-Control": "no-cache, no-store, max-age=0, must-revalidate", "X-Content-Type-Options": "nosniff", "X-Frame-Options": "SAMEORIGIN", "Content-Length": "0", "X-Xss-Protection": "1; mode=block" }
I've also tried removing the outer object and the "dataPoints" array, so that the body only contains the data point object. Regarding the timezone, I'm setting it to either blank, '+00:00' or 'Europe/London', as another post suggested checking here for valid timezones: http://joda-time.sourceforge.net/timezones.html.
Any new ideas please? Thanks :)
-
Hi Silvia,
I believe you've posted a response to a successful request. Because these imports could be very large, they could take a long time, and thus the response to the submission of an import is better fast, with a Location header you can GET for information on how the import task is progressing.
-
As Phillip said HTTP 202 (Accecpted) is a successful response indicating that the import has started.
-
You're both absolutely right, maybe I wasn't refreshing the page to see the newly created events, I can now... Thanks so much for all of your help! :)