Search Alerts


查询当前和历史告警,返回结果可随便跳页。

请求格式

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

请求参数(URI)

名称 位置(Path/Query) 必需/可选 数据类型 描述
orgId Query 必需 String 资产所属的组织 ID。如何获取 orgId 信息>>

请求参数(Body)

名称 必需/可选 数据类型 描述
instanceId 可选 String 告警的实体,现阶段只有 asset,取值为 assetId。
metricId 可选 String metric,比如测点。
startOccurTime 必需 String 查询起始时间,与 endOccurTime 配合使用,表示查询该时段内被触发的告警。API 在使用的时间参数>>
endOccurTime 必需 String 查询结束时间,与 startOccurTime 配合使用,表示查询该时段内被触发的告警。API 在使用的时间参数>>
startRecoverTime 可选 String 查询起始时间,与 endRecoverTime 配合使用,表示查询在该时段内异常状态恢复正常的告警,若不指定,默认为最近一周的数据。若为空,只返回当前告警。API 在使用的时间参数>>
endRecoverTime 可选 String 查询起始时间,与 startRecoverTime 配合使用,表示查询在该时段内异常状态恢复正常的告警,若不指定,默认为最近一周的数据。若为空,只返回当前告警。API 在使用的时间参数>>
active 可选 Boolean
  • true:只搜索正在进行中的告警
  • false:搜索历史告警
  • null:搜索全部告警,包括历史告警和正在进行中的告警。默认为 null。
expression 可选 String

查询表达式,支持类 SQL 的查询。目前支持的逻辑运算是 and 和 or,查询的字段和对应的运算符清单如下。

  • instanceIdmetricIdseverityIdtypeIdparentTypeIdcontentIdruleIdeventTypealertId:=、in 和 !=
  • metricTags.* (除 metricTags.assetTreePath)、ruleTags.*tags.*:=、in、!=、like 和 exists
  • metricTags.assetTreePath:= 和 in,根据 tree ID。如需使用该参数,需在当前环境中安装 2.3 CU2
  • inhibited:= 和 !=
  • maskedBy:=

字段描述参见 AlertVo 结构体

如何使用查询表达式>>

pagination 可选 Pagination 请求结构体 随机分页。只能按照 occurTime 倒序排列,不能指定排序字段。如未指定,默认分页大小为 10。Pagination 请求结构体>>

响应参数

名称 数据类型 描述
data AlertVo 结构体数组 告警记录的信息列表。有关 AlertVo 结构体的定义,参见 AlertVo 结构体

AlertVo 结构体

名称 数据类型 描述
alertId String 告警 ID。
eventType Integer
  • 0:告警解除,通过规则触发(历史告警)
  • 1:告警开始,通过规则触发(当前告警)
  • 2:告警解除,通过接口创建(历史告警)
  • 3:告警开始,通过接口创建(当前告警)
  • 4:离散告警(历史告警)
  • 5: 乱序告警(历史告警)

其中,在 Create Alert 接口中,只允许填 2、3、4。

orgId String 资产所属的组织 ID。
instanceId String 告警的实体,现阶段只有 asset,取值为 assetId。
metricId String 原始度量数据的 ID。
occurTime Long 告警发生的时间,以 UTC 时间表示,格式见 UTC 采用的 ISO8601 标准时间格式>>
localOccurTime String 告警发生的时间,以本地时间表示,格式见 localtime 采用的日期时间格式>>
recoverTime Long 触发告警的异常状况恢复正常的时间,以 UTC 时间表示,格式见 UTC 采用的 ISO8601 标准时间格式>>
localRecoverTime String 触发告警的异常状况恢复正常的时间,以本地时间表示,格式见 localtime 采用的日期时间格式>>
recoverReason String 异常状况恢复的原因。
value String 告警产生时的 metric value,对于高级的告警功能比如多测点告警或者时序告警,使用产生告警对应的那个 metric 的 value。
metricTags Map

原始度量数据的标签。Key 和 Value 为 String。标签的作用与表示方法>>

不同业务/系统会有不同的原始度量,定义的标签也会不同。EnOS 有以下可能出现在 metricTags 标准标签。 其中带有 __ 前缀和后缀的标签是通用的 key,没带 __ 的是与业务相关的 key。

{

__timezone__: 时区

__instance__: instanceId

__metric__: metricId

__alias__: metricId 的别名

modelIdPath: 模型路径

modelId: modelId

assetTreePath: 资产树路径

assetTreePath_${treeId}: 指定 treeId 的资产树路径

}

severityId String 告警级别编号。
severityDesc StringI18n 告警级别描述。结构参见 国际化名称结构体
typeId String 告警类型编号。
typeDesc StringI18n 告警类型描述。结构参见 国际化名称结构体
parentTypeId String 告警父类型编号。
parentTypeDesc StringI18n 告警父类型描述。结构参见 国际化名称结构体
content StringI18n 告警内容。结构参见 国际化名称结构体
ruleId String 告警规则编号。
ruleDesc StringI18n 告警规则描述。结构参见 国际化名称结构体
ruleTags Map 规则上的标签。
tags Map 标签,只支持全量更新。标签的作用与表示方法>>
inhibited Boolean
  • true:屏蔽
  • false:没被屏蔽

示例

请求示例

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

注解

如需使用 metricTags.assetTreePath 参数,需在当前环境中安装 2.3 CU2

返回示例

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

Java SDK 调用示例

public void testSearchAlerts(){
  String accessKey = "yourAppAccessKey";
  String secretKey = "yourAppSecretKey";
  SearchAlertRequest request = new SearchAlertRequest();
  request.setOrgId("yourOrgId");
  request.setStartOccurTime("2019-05-20T00:00:00Z");
  request.setEndOccurTime("2019-06-15T00:00:00Z");
  Pagination pagination = new Pagination();
  pagination.setPageSize(2);
  pagination.setPageNo(1);
  request.setPagination(pagination);
  request.setExpression("alertId = 'yourAlertId' and metricTags.modelId = 'modelId_11' and metricTags.assetTreePath in ('s3XMMLph', '2BRE9U8L', 'CkAQRo3y')");
  /** 如需使用 metricTags.assetTreePath 参数,需在当前环境中安装 `2.3 CU2 </docs/api/zh_CN/2.3.0/releasenote/2.3.0/cu2.html#id4>`_。*/
  try {
    SearchAlertResponse response = Poseidon.config(PConfig.init().appKey(accessKey).appSecret(secretKey).debug())
            .url("https://{apigw-address}")
            .getResponse(request, SearchAlertResponse.class);
    Gson gson = new Gson();
    System.out.println(gson.toJson(response));
  }catch(Exception e){
    System.out.print(e);
  }
}

注解

如需使用 metricTags.assetTreePath 参数,需在当前环境中安装 2.3 CU2