1. 数据预警

1.1. 数据结构

名称 位置 类型 必选 说明
title body string 预警标题
appId body integer 预警所属 app id
dashboardId body integer 预警条件所选dashboard id
chartId body integer 预警条件所选chart id
options body object 预警配置信息
» rules body [object] 预警触发条件,HE数组。可以有多个条件,每个条件为一个数组项。
»» kind body string none
»» op body string none
»» args body [object] none
»»» kind body string none
»»» op body string none
»»» args body [object] none
»»»» kind body string none
»»»» op body string none
»»»» type body string none
» timing body object 触发时机配置信息
»» cronType body string cronType表达式类型
»» cronDesc body string cron表达式
»» timeZone body string 时区
»» triggerType body string 值为(CRON_JOB)
»» frequency body string 频率,值为(ALWAYS,ONLY_ONCE,ONCE_EVERYDAY)之一
» email body object 邮件推送配置
»» dashboardList body [object] 推送仪表盘列表
»»» id body integer 仪表盘id
»»» title body string 仪表盘标题
»» bodyWithDashboardUrl body boolean 正文是否附加仪表盘链接
»» enabled body boolean 是否开启
»» bodyWithImage body boolean 正文是否附加仪表盘图片
»» compressAttachment body boolean 是否压缩附加
»» receiverList body [object] 衡石系统内接收者列表
»»» id body integer 接收者id
»»» name body string none
»»» loginName body string none
»»» receiverType body string 接收人类型
»» emailSubject body string 主题
»» defaultEmailSubject body string 默认主题
»» emailContentBody body string 内容
»» defaultEmailContentBody body string 默认内容
»» tooLargeContentBody body string 附件内容过大时替换内容
»» defaultTooLargeContentBody body string 默认附件内容过大时替换内容
»» attachmentTypes body string 附件类型
»» emailAddressList body [string] 邮箱地址列表
» webhook body object webhook推送配置
»» enabled body boolean 是否开启
»» url body string webhook推送目的地址
»» method body string HTTP请求类型
»» requestBody body string 请求体(仅支持json格式请求体)
»» headers body [string] 请求头
» wecom body object 企业微信推送配置
»» dashboardList body [object] none
»»» id body integer none
»»» title body string none
»» bodyWithDashboardUrl body boolean none
»» enabled body boolean none
»» bodyWithImage body boolean none
»» targets body [string] 企业微信用户id列表
»» subject body string 消息主题
»» content body string 消息内容
»» bodyCustomized body boolean 是否开启自定义消息
»» defaultContent body string 默认消息内容
» feishu body object 飞书推送配置
»» dashboardList body [object] none
»»» id body integer none
»»» title body string none
»» bodyWithDashboardUrl body boolean none
»» enabled body boolean none
»» bodyWithImage body boolean none
»» targets body [string] none
»» subject body string none
»» content body string none
»» bodyCustomized body boolean none
»» defaultContent body string none
errorPolice body object 预警失败策略
» canPause body boolean 能否暂停任务,暂停任务后需手动重新启动。
» interval body integer 重试间隔时间,单位:分钟
» retryable body boolean 能否重试
» notifyUser body boolean 任务暂停后是否通知应用所有者
» retryTimes body integer 重试总次数
» failureTimes body integer 失败暂停阈值

1.2. 模板变量

支持在推送内容的正文以及标题使用模板变量。

例子:

这是临时预警消息{{%%system.dashboard.url}}

支持的模板变量列表如下:

变量名
system.app.title
system.app.url
system.today
system.dashboard.title
system.chart.title
system.alert.title
system.chart.data

仅Webhook推送方式支持的模板变量列表如下:

变量名
system.dashboard.url

1.2.1. 收件人类型

字段值 描述
USER 用户
ORGANIZATION 用户组
DEPARTMENT 组织机构

1.2.2. 邮件附件类型

字段值 描述
PNG png文件
PDF pdf文件
EXCEL excel文件

1.3. 1.1. POST 创建数据预警条目

POST /api/apps/{appId}/alert

创建属于特定应用的数据预警条目,一个APP最多创建20条预警条目

Body 请求参数示例

{
  "title": "测试预警1",
  "appId": 128149,
  "dashboardId": 1,
  "chartId": 5,
  "options": {
    "rules": [
      {
        "kind": "function",
        "op": "and",
        "args": [
          {
            "kind": "function",
            "op": "!=",
            "args": [
              {
                "kind": "reference",
                "op": "u_32a8edf1946cd3c3_1",
                "type": "number"
              },
              {
                "kind": "constant",
                "op": "0",
                "type": "number"
              }
            ]
          }
        ]
      }
    ],
    "timing": {
      "cronType": "WEEKLY",
      "cronDesc": "0 0 0 ? * 1",
      "timeZone": "GMT+08:00",
      "triggerType": "CRON_JOB",
      "frequency": "ONLY_ONCE"
    },
    "email": {
      "enabled": true,
      "receiverList": [
        {
          "id": 26889,
          "name": "测试用户",
          "loginName": "test1",
          "receiverType": "USER"
        }
      ],
      "emailSubject": "",
      "emailContentBody": "指标已达预警阈值,请知晓并及时处理。<br /><br />预警规则被触发<br />id(求和) != 0<br />指标当前数据如下(只预览最多20条数据,可打开仪表盘链接查看详情):<br />{{%%system.chart.data}}<br /><br />应用:{{%%system.app.title}}<br />仪表盘:{{%%system.dashboard.title}}<br />图表:{{%%system.chart.title}}<br />",
      "defaultEmailSubject": "【指标预警通知】{{%%system.dashboard.title}}:id",
      "defaultEmailContentBody": "指标已达预警阈值,请知晓并及时处理。<br /><br />预警规则被触发<br />id(求和) != 0<br />指标当前数据如下(只预览最多20条数据,可打开仪表盘链接查看详情):<br />{{%%system.chart.data}}<br /><br />应用:{{%%system.app.title}}<br />仪表盘:{{%%system.dashboard.title}}<br />图表:{{%%system.chart.title}}<br />",
      "bodyWithDashboardUrl": true,
      "emailSubjectCustomized": false,
      "emailBodyCustomized": true
    },
    "webhook": {
      "enabled": true,
      "url": "https://www.baidu.com",
      "method": "POST",
      "headers": [],
      "requestBody": ""
    }
  },
  "errorPolice": {
    "canPause": true,
    "interval": 5,
    "retryable": true,
    "notifyUser": true,
    "retryTimes": 2,
    "failureTimes": 3
  }
}

1.3.1. 1.1.1. 请求参数

名称 位置 类型 必选 说明
appId path string none
requestId query string none
body body object none
» title body string 预警标题
» appId body integer 预警所属 app id
» dashboardId body integer 预警条件所选dashboard id
» chartId body integer 预警条件所选chart id
» options body object 预警配置信息
»» rules body [object] 预警触发条件,HE数组。可以有多个条件,每个条件为一个数组项。
»»» kind body string none
»»» op body string none
»»» args body [object] none
»»»» kind body string none
»»»» op body string none
»»»» args body [object] none
»»»»» kind body string none
»»»»» op body string none
»»»»» type body string none
»» timing body object 触发时机配置信息
»»» cronType body string cronType表达式类型
»»» cronDesc body string cron表达式
»»» timeZone body string 时区
»»» triggerType body string 值为(CRON_JOB)
»»» frequency body string 频率,值为(ALWAYS,ONLY_ONCE,ONCE_EVERYDAY)之一
»» email body object 邮件推送配置
»»» dashboardList body [object] 推送仪表盘列表
»»»» id body integer 仪表盘id
»»»» title body string 仪表盘标题
»»» bodyWithDashboardUrl body boolean 正文是否附加仪表盘链接
»»» enabled body boolean 是否开启
»»» bodyWithImage body boolean 正文是否附加仪表盘图片
»»» compressAttachment body boolean 是否压缩附加
»»» receiverList body [object] 衡石系统内接收者列表
»»»» id body integer 接收者id
»»»» name body string none
»»»» loginName body string none
»»»» receiverType body string 接收人类型
»»» emailSubject body string 主题
»»» defaultEmailSubject body string 默认主题
»»» emailContentBody body string 内容
»»» defaultEmailContentBody body string 默认内容
»»» tooLargeContentBody body string 附件内容过大时替换内容
»»» defaultTooLargeContentBody body string 默认附件内容过大时替换内容
»»» attachmentTypes body string 附件类型
»»» emailAddressList body [string] 邮箱地址列表
»» webhook body object webhook推送配置
»»» enabled body boolean 是否开启
»»» url body string webhook推送目的地址
»»» method body string HTTP请求类型
»»» requestBody body string 请求体(仅支持json格式请求体)
»»» headers body [string] 请求头
»» wecom body object 企业微信推送配置
»»» dashboardList body [object] none
»»»» id body integer none
»»»» title body string none
»»» bodyWithDashboardUrl body boolean none
»»» enabled body boolean none
»»» bodyWithImage body boolean none
»»» targets body [string] 企业微信用户id列表
»»» subject body string 消息主题
»»» content body string 消息内容
»»» bodyCustomized body boolean 是否开启自定义消息
»»» defaultContent body string 默认消息内容
»» feishu body object 飞书推送配置
»»» dashboardList body [object] none
»»»» id body integer none
»»»» title body string none
»»» bodyWithDashboardUrl body boolean none
»»» enabled body boolean none
»»» bodyWithImage body boolean none
»»» targets body [string] none
»»» subject body string none
»»» content body string none
»»» bodyCustomized body boolean none
»»» defaultContent body string none
» errorPolice body object 预警失败策略
»» canPause body boolean 能否暂停任务,暂停任务后需手动重新启动。
»» interval body integer 重试间隔时间,单位:分钟
»» retryable body boolean 能否重试
»» notifyUser body boolean 任务暂停后是否通知应用所有者
»» retryTimes body integer 重试总次数
»» failureTimes body integer 失败暂停阈值

返回示例

成功

{
  "version": "4.5-SNAPSHOT@163f990#73d0999",
  "code": 0,
  "msg": "success",
  "data": {
    "id": 213,
    "title": "测试预警3",
    "appId": 128149,
    "dashboardId": 1,
    "chartId": 5,
    "options": {
      "rules": [
        {
          "args": [
            {
              "args": [
                {
                  "op": "u_32a8edf1946cd3c3_1",
                  "kind": "reference",
                  "type": "number"
                },
                {
                  "op": "0",
                  "kind": "constant",
                  "type": "number"
                }
              ],
              "op": "!=",
              "kind": "function"
            }
          ],
          "op": "and",
          "kind": "function"
        }
      ],
      "email": {
        "enabled": true,
        "receiverList": [
          {
            "id": 26889,
            "name": "测试用户",
            "loginName": "test1",
            "receiverType": "USER"
          }
        ],
        "dashboardList": [
          {
            "id": 1,
            "title": "新建仪表盘"
          }
        ],
        "emailSubjectCustomized": false,
        "emailBodyCustomized": true,
        "emailSubject": "",
        "defaultEmailSubject": "【指标预警通知】{{%%system.dashboard.title}}:id",
        "emailContentBody": "指标已达预警阈值,请知晓并及时处理。<br /><br />预警规则被触发<br />id(求和) != 0<br />指标当前数据如下(只预览最多20条数据,可打开仪表盘链接查看详情):<br />{{%%system.chart.data}}<br /><br />应用:{{%%system.app.title}}<br />仪表盘:{{%%system.dashboard.title}}<br />图表:{{%%system.chart.title}}<br />",
        "defaultEmailContentBody": "指标已达预警阈值,请知晓并及时处理。<br /><br />预警规则被触发<br />id(求和) != 0<br />指标当前数据如下(只预览最多20条数据,可打开仪表盘链接查看详情):<br />{{%%system.chart.data}}<br /><br />应用:{{%%system.app.title}}<br />仪表盘:{{%%system.dashboard.title}}<br />图表:{{%%system.chart.title}}<br />",
        "bodyWithDashboardUrl": true
      },
      "webhook": {
        "enabled": true,
        "url": "https://www.baidu.com",
        "method": "POST",
        "headers": [],
        "requestBody": ""
      },
      "timing": {
        "triggerType": "CRON_JOB",
        "cronDesc": "0 0 0 ? * 1",
        "cronType": "WEEKLY",
        "timeZone": "GMT+08:00",
        "frequency": "ONLY_ONCE"
      }
    },
    "status": "RUNNING",
    "enabled": true,
    "createdBy": 11549,
    "updatedBy": 11549,
    "createdAt": "2023-07-11 14:38:51",
    "updatedAt": "2023-07-11 14:38:51",
    "isDelete": false,
    "hsVersion": 0,
    "errorPolice": {
      "retryable": true,
      "interval": 5,
      "retryTimes": 2,
      "canPause": true,
      "failureTimes": 3,
      "notifyUser": true
    }
  },
  "chartDataStartTimeMillis": 0
}

1.3.2. 1.1.2. 返回结果

状态码 状态码含义 说明 数据模型
200 OK 成功 Inline

1.4. 1.2. GET 分页查询预警

GET /api/apps/{appId}/alert/list

1.4.1. 1.2.1. 请求参数

名称 位置 类型 必选 说明
appId path string none
requestId query string none
offset query Long none
limit query Long none

1.5. 1.3. DELETE 删除预警条目

DELETE /api/apps/{appId}/alert/{alertId}

1.5.1. 1.3.1. 请求参数

名称 位置 类型 必选 说明
appId path string none
alertId path string none
requestId query string none

1.6. 1.4. GET 根据ID查询预警

GET /api/apps/{appId}/alert/{alertId}

1.6.1. 1.4.1. 请求参数

名称 位置 类型 必选 说明
appId path string none
alertId path string none
requestId query string none

1.7. 1.5. PUT 编辑数据预警条目

PUT /api/apps/{appId}/alert/{alertId}

编辑特定的预警条目

Body 请求参数

{
  "title": "测试预警1",
  "appId": 128149,
  "dashboardId": 1,
  "chartId": 5,
  "options": {
    "rules": [
      {
        "kind": "function",
        "op": "and",
        "args": [
          {
            "kind": "function",
            "op": "!=",
            "args": [
              {
                "kind": "reference",
                "op": "u_32a8edf1946cd3c3_1",
                "type": "number"
              },
              {
                "kind": "constant",
                "op": "0",
                "type": "number"
              }
            ]
          }
        ]
      }
    ],
    "timing": {
      "cronType": "WEEKLY",
      "cronDesc": "0 0 0 ? * 1",
      "timeZone": "GMT+08:00",
      "triggerType": "CRON_JOB",
      "frequency": "ONLY_ONCE"
    },
    "email": {
      "enabled": true,
      "receiverList": [
        {
          "id": 26889,
          "name": "测试用户",
          "loginName": "test1",
          "receiverType": "USER"
        }
      ],
      "emailSubject": "",
      "emailContentBody": "指标已达预警阈值,请知晓并及时处理。<br /><br />预警规则被触发<br />id(求和) != 0<br />指标当前数据如下(只预览最多20条数据,可打开仪表盘链接查看详情):<br />{{%%system.chart.data}}<br /><br />应用:{{%%system.app.title}}<br />仪表盘:{{%%system.dashboard.title}}<br />图表:{{%%system.chart.title}}<br />",
      "defaultEmailSubject": "【指标预警通知】{{%%system.dashboard.title}}:id",
      "defaultEmailContentBody": "指标已达预警阈值,请知晓并及时处理。<br /><br />预警规则被触发<br />id(求和) != 0<br />指标当前数据如下(只预览最多20条数据,可打开仪表盘链接查看详情):<br />{{%%system.chart.data}}<br /><br />应用:{{%%system.app.title}}<br />仪表盘:{{%%system.dashboard.title}}<br />图表:{{%%system.chart.title}}<br />",
      "bodyWithDashboardUrl": true,
      "emailSubjectCustomized": false,
      "emailBodyCustomized": true
    },
    "webhook": {
      "enabled": true,
      "url": "https://www.baidu.com",
      "method": "POST",
      "headers": [],
      "requestBody": ""
    }
  },
  "errorPolice": {
    "canPause": true,
    "interval": 5,
    "retryable": true,
    "notifyUser": true,
    "retryTimes": 2,
    "failureTimes": 3
  }
}

1.7.1. 1.5.1. 请求参数

名称 位置 类型 必选 说明
appId path string none
alertId path string none
requestId query string none
body body object none

返回示例

成功

{
  "version": "4.5-SNAPSHOT@163f990#73d0999",
  "code": 0,
  "msg": "success",
  "data": {
    "id": 213,
    "title": "测试预警3",
    "appId": 128149,
    "dashboardId": 1,
    "chartId": 5,
    "options": {
      "rules": [
        {
          "args": [
            {
              "args": [
                {
                  "op": "u_32a8edf1946cd3c3_1",
                  "kind": "reference",
                  "type": "number"
                },
                {
                  "op": "0",
                  "kind": "constant",
                  "type": "number"
                }
              ],
              "op": "!=",
              "kind": "function"
            }
          ],
          "op": "and",
          "kind": "function"
        }
      ],
      "email": {
        "enabled": true,
        "receiverList": [
          {
            "id": 26889,
            "name": "测试用户",
            "loginName": "test1",
            "receiverType": "USER"
          }
        ],
        "dashboardList": [
          {
            "id": 1,
            "title": "新建仪表盘"
          }
        ],
        "emailSubjectCustomized": false,
        "emailBodyCustomized": true,
        "emailSubject": "",
        "defaultEmailSubject": "【指标预警通知】{{%%system.dashboard.title}}:id",
        "emailContentBody": "指标已达预警阈值,请知晓并及时处理。<br /><br />预警规则被触发<br />id(求和) != 0<br />指标当前数据如下(只预览最多20条数据,可打开仪表盘链接查看详情):<br />{{%%system.chart.data}}<br /><br />应用:{{%%system.app.title}}<br />仪表盘:{{%%system.dashboard.title}}<br />图表:{{%%system.chart.title}}<br />",
        "defaultEmailContentBody": "指标已达预警阈值,请知晓并及时处理。<br /><br />预警规则被触发<br />id(求和) != 0<br />指标当前数据如下(只预览最多20条数据,可打开仪表盘链接查看详情):<br />{{%%system.chart.data}}<br /><br />应用:{{%%system.app.title}}<br />仪表盘:{{%%system.dashboard.title}}<br />图表:{{%%system.chart.title}}<br />",
        "bodyWithDashboardUrl": true
      },
      "webhook": {
        "enabled": true,
        "url": "https://www.baidu.com",
        "method": "POST",
        "headers": [],
        "requestBody": ""
      },
      "timing": {
        "triggerType": "CRON_JOB",
        "cronDesc": "0 0 0 ? * 1",
        "cronType": "WEEKLY",
        "timeZone": "GMT+08:00",
        "frequency": "ONLY_ONCE"
      }
    },
    "status": "RUNNING",
    "enabled": true,
    "createdBy": 11549,
    "updatedBy": 11549,
    "createdAt": "2023-07-11 14:38:51",
    "updatedAt": "2023-07-11 14:38:51",
    "isDelete": false,
    "hsVersion": 0,
    "errorPolice": {
      "retryable": true,
      "interval": 5,
      "retryTimes": 2,
      "canPause": true,
      "failureTimes": 3,
      "notifyUser": true
    }
  },
  "chartDataStartTimeMillis": 0
}

1.7.2. 1.5.2. 返回结果

状态码 状态码含义 说明 数据模型
200 OK 成功 Inline

1.8. 1.6. POST 验证预警条目

POST /api/apps/{appId}/alert/validate

验证预警配置

Body 请求参数

{
  "id": "123",
  "title": "测试预警1",
  "appId": 128149,
  "dashboardId": 1,
  "chartId": 5,
  "options": {
    "rules": [
      {
        "kind": "function",
        "op": "and",
        "args": [
          {
            "kind": "function",
            "op": "!=",
            "args": [
              {
                "kind": "reference",
                "op": "u_32a8edf1946cd3c3_1",
                "type": "number"
              },
              {
                "kind": "constant",
                "op": "0",
                "type": "number"
              }
            ]
          }
        ]
      }
    ],
    "timing": {
      "cronType": "WEEKLY",
      "cronDesc": "0 0 0 ? * 1",
      "timeZone": "GMT+08:00",
      "triggerType": "CRON_JOB",
      "frequency": "ONLY_ONCE"
    },
    "email": {
      "enabled": true,
      "receiverList": [
        {
          "id": 26889,
          "name": "测试用户",
          "loginName": "test1",
          "receiverType": "USER"
        }
      ],
      "emailSubject": "",
      "emailContentBody": "指标已达预警阈值,请知晓并及时处理。<br /><br />预警规则被触发<br />id(求和) != 0<br />指标当前数据如下(只预览最多20条数据,可打开仪表盘链接查看详情):<br />{{%%system.chart.data}}<br /><br />应用:{{%%system.app.title}}<br />仪表盘:{{%%system.dashboard.title}}<br />图表:{{%%system.chart.title}}<br />",
      "defaultEmailSubject": "【指标预警通知】{{%%system.dashboard.title}}:id",
      "defaultEmailContentBody": "指标已达预警阈值,请知晓并及时处理。<br /><br />预警规则被触发<br />id(求和) != 0<br />指标当前数据如下(只预览最多20条数据,可打开仪表盘链接查看详情):<br />{{%%system.chart.data}}<br /><br />应用:{{%%system.app.title}}<br />仪表盘:{{%%system.dashboard.title}}<br />图表:{{%%system.chart.title}}<br />",
      "bodyWithDashboardUrl": true,
      "emailSubjectCustomized": false,
      "emailBodyCustomized": true
    },
    "webhook": {
      "enabled": true,
      "url": "https://www.baidu.com",
      "method": "POST",
      "headers": [],
      "requestBody": ""
    }
  },
  "errorPolice": {
    "canPause": true,
    "interval": 5,
    "retryable": true,
    "notifyUser": true,
    "retryTimes": 2,
    "failureTimes": 3
  }
}

1.8.1. 1.6.1. 请求参数

名称 位置 类型 必选 说明
appId path string none
requestId query string none
body body object none

返回示例

成功

{
  "version": "4.5-SNAPSHOT@163f990#73d0999",
  "code": 0,
  "msg": "success",
  "chartDataStartTimeMillis": 0
}

1.8.2. 1.6.2. 返回结果

状态码 状态码含义 说明 数据模型
200 OK 成功 Inline

状态码 200

名称 类型 必选 约束 中文名 说明
» version string true none none
» code integer true none none
» msg string true none none
» chartDataStartTimeMillis integer true none none

results matching ""

    No results matching ""

    应用规则 应用订阅