Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Coloring markers on a Map using alerts data

Hector Garcia Tellado edited this page Oct 31, 2017 · 1 revision

[Hui]

In RM1.6, we have the following logic to show color: if a device has alert in the past 10 mins, we show as red (even the alert is closed -- need justification from PM since there is no state for alert in Rm1.6) if a device has alert in the past 1 hour (10mins,1hour], we show as min.

For this purpose, we may want to simplify the API to retrieve the last alert for given deviceId in a given time range.

GET {Device Telemetry endpoint}/alerts?from={time}&to={time}&grouplimit=1&devices=id1,id2,id3,...&fields=deviceid,time
Content-Type: application/json; charset=utf-8

response:
{
    Count: ...
    Items: [
        {
            deviceid, time
        },
        {
            deviceid, time
        },
        ...
    ]
}

[/Hui]

See "Showing devices on a Map" to see how to put devices on a map, and add the following steps.

Get the list of alerts from the Device Telemetry API.

Step 1: Request the open alerts for each device

Request

Request with GET:

GET {Device Telemetry endpoint}/alerts?status=open&from={time}&to={time}&grouplimit=1&order=desc&devices=id1,id2,id3,...

Request with POST:

POST {Device Telemetry endpoint}/alerts-query
Content-Type: application/json; charset=utf-8

{
    Status: open
    From: {time}
    To: {time}
    Order: desc
    GroupLimit: 1
    Devices: [ "id 1", "id 2", ..., "id 3" ]
}

Note: the "grouplimit" option is used to retrieve only the most recent alert for each device.

Response

Content-Type: application/json; charset=utf-8

{
    Count: ...
    Items: [
        {
            deviceid, time, description, status, etc.
            $metadata
        },
        {
            deviceid, time, description, status, etc.
            $metadata
        },
        ...
    ]
    "$metadata": {
        $type: AlertsList;1
        $uri: ...
    }
}

Step 2: Request the acknowledged alerts for each device

Request

Request with GET:

GET {Device Telemetry endpoint}/alerts?status=acknowledged&from={time}&to={time}&grouplimit=1&order=desc&devices=id1,id2,id3,...

Request with POST:

POST {Device Telemetry endpoint}/alerts-query
Content-Type: application/json; charset=utf-8

{
    Status: acknowledged
    From: {time}
    To: {time}
    Order: desc
    GroupLimit: 1
    Devices: [ "id 1", "id 2", ..., "id 3" ]
}

Note: the "grouplimit" option is used to retrieve only the most recent alert for each device.

Response

Content-Type: application/json; charset=utf-8

{
    Count: ...
    Items: [
        {
            deviceid, time, description, status, etc.
            $metadata
        },
        {
            deviceid, time, description, status, etc.
            $metadata
        },
        ...
    ]
    "$metadata": {
        $type: AlertsList;1
        $uri: ...
    }
}

Step 3: calculate the device status

  1. Scroll through the list of "open" alerts, to identify which devices have a new/open alert.
  2. Scroll through the list of "acknowledged" alerts, ignore devices which have an open alert, what remains is the list of devices with an acknoledged alert.
Clone this wiki locally