Search Alerts


Search for active and history alerts, where the pages of the returned results do not have to be in order.

Request Format

POST https://{apigw-address}/alert-service/v2.1/alerts?action=search

Request Parameters (URI)

Name

Location (Path/Query)

Mandatory/Optional

Data Type

Description

orgId

Query

Mandatory

String

The organization ID which the asset belongs to. How to get orgId>>

Request Parameters (Body)

Name

Mandatory/Optional

Data Type

Description

instanceId

Optional

String

The alert entity, which is the asset at this stage, with its value as the assetId.

metricId

Optional

String

The metric, such as the measurement point.

startOccurTime

Mandatory

String

The start time for triggering alert. To be used with endOccurTime. Time parameters used in API>>

endOccurTime

Mandatory

String

The end time for triggering alert. To be used with startOccurTime. Time parameters used in API>>

startRecoverTime

Optional

String

The start time of the alert recovery. To be used with recoverEndTime. If left blank, the data within the last week will be searched. Time parameters used in API>>

endRecoverTime

Optional

String

The end time of the alert recovery. To be used with recoverStartTime. If left blank, the data within the last week will be searched. Time parameters used in API>>

active

Optional

Boolean

  • true: Search for active alerts.

  • false: Search for history alerts.

  • null (default): Search both active and history alerts.

expression

Optional

String

The query expression, which supports sql-like query. The supported logical operators are “and” and “or”, and query fields are as per the below.

  • instanceId, metricId, severityId, typeId, parentTypeId, contentId, ruleId, eventType amd alertId: support operators “=”, “in”, and “!=”

  • metricTags.* (excluding metricTags.assetTreePath), ruleTags.* and tags.*: support operators “=”, “in”, “!=”, “like”, and “exists”

  • metricTags.assetTreePath: supports operators “=” and “in” based on tree ID

  • inhibited: supports operators “=” and “!=”

  • maskedBy: supports operator “=”

For more information about field description, see AlertVo Struct

How to use expression>>

pagination

Optional

Pagination Request Struct

Random pagination。 When not specified, 10 records are displayed per page by default and sorted in descending order by occurTime. For more details, see Pagination Request Struct.

Response Parameters

Name

Data Type

Description

data

Array of AlertVo Structs

The list of alert records. For details of an AlertVo struct, see AlertVo Struct.

Samples

Request Sample

url: POST https://{apigw-address}/alert-service/v2.1/alerts?action=search&orgId=yourOrgId
method: POST
requestBody:
{
  "startOccurTime": "2019-05-20T00:00:00Z",
  "endOccurTime": "2019-06-15T00:00:00Z",
  "expression": "alertId = 'yourAlertId' and metricTags.modelId = 'modelId_11' and metricTags.assetTreePath in ('s3XMMLph', '2BRE9U8L', 'CkAQRo3y')",
  "pagination": {
    "pageNo": 1,
    "pageSize": 2
  }
}

Return Sample

{
    "pagination":{
        "pageNo":1,
        "pageSize":2,
        "totalSize":1,
        "sortedBy":[
            {
                "field":"occurTime",
                "order":"DESC"
            },
            {
                "field":"alertId",
                "order":"DESC"
            }
        ]
    },
    "code":0,
    "msg":"OK",
    "requestId":"dac2a872-b9b7-460c-992d-0a0c14ea36e9",
    "data":[
        {
            "alertId": "yourAlertId",
            "eventType": 1,
            "orgId": "yourOrgId",
            "instanceId": "deviceId_37233",
            "metricId": "pointId_772",
            "occurTime": 1547824973674,
            "localOccurTime": "2018-01-01 01:01:01",
            "recoverTime": 1547824973674,
            "localRecoverTime": "2018-02-02 00:00:00",
            "recoverReason": "rpc",
            "value": "5",
            "metricTags":{
                "assetTreePath_s3XMMLph": "/JvQqIeUB/th1xnIG4/MlmbC7eG/",
                "assetTreePath": "2BRE9U8L:/nc34Xktx/DjEpY5Qz/MlmbC7eG/,CkAQRo3y:/grZH1o0Z/1ti4BAQU/MlmbC7eG/,s3XMMLph:/JvQqIeUB/th1xnIG4/MlmbC7eG/",
                "assetTreePath_2BRE9U8L": "/nc34Xktx/DjEpY5Qz/MlmbC7eG/",
                "modelId": "modelId_11",
                "modelIdPath" :"path"
            },
            "severityId": "42j",
            "severityDesc": {
                "i18nValue": {
                    "en_US": "warning",
                    "zh_CN": ""
                }
            },
            "typeId": "11d",
            "typeDesc": {
                "i18nValue": {
                    "en_US": "Limit",
                    "zh_CN": ""
                }
            },
            "parentTypeId": "d1",
            "parentTypeDesc": {
                "i18nValue": {
                    "en_US": "Threshold",
                    "zh_CN": ""
                }
            },
            "content": {
                "i18nValue": {
                    "en_US": "Content",
                    "zh_CN": ""
                }
            },
            "ruleId": "5v7",
            "ruleDesc": {
                "i18nValue": {
                    "en_US": "Rule description",
                    "zh_CN": ""
                }
            },
            "ruleTags":{
                "color": "red",
                "category" :"note"
            },
            "tags": {
                "de": "tag"
            },
            "inhibited": false
        }
    ]
}

SDK Samples


You can access the SDK samples for alert engine service on GitHub: