Skip to content

数据预警

数据结构

名称位置类型必选说明
titlebodystring预警标题
appIdbodyinteger预警所属 app id
dashboardIdbodyinteger预警条件所选dashboard id
chartIdbodyinteger预警条件所选chart id
optionsbodyobject预警配置信息
» rulesbody[object]预警触发条件,HE数组。可以有多个条件,每个条件为一个数组项。
»» kindbodystringnone
»» opbodystringnone
»» argsbody[object]none
»»» kindbodystringnone
»»» opbodystringnone
»»» argsbody[object]none
»»»» kindbodystringnone
»»»» opbodystringnone
»»»» typebodystringnone
» timingbodyobject触发时机配置信息
»» cronTypebodystringcronType表达式类型
»» cronDescbodystringcron表达式
»» timeZonebodystring时区
»» triggerTypebodystring值为(CRON_JOB)
»» frequencybodystring频率,值为(ALWAYS,ONLY_ONCE,ONCE_EVERYDAY)之一
» emailbodyobject邮件推送配置
»» dashboardListbody[object]推送仪表盘列表
»»» idbodyinteger仪表盘id
»»» titlebodystring仪表盘标题
»» bodyWithDashboardUrlbodyboolean正文是否附加仪表盘链接
»» enabledbodyboolean是否开启
»» bodyWithImagebodyboolean正文是否附加仪表盘图片
»» compressAttachmentbodyboolean是否压缩附加
»» receiverListbody[object]衡石系统内接收者列表
»»» idbodyinteger接收者id
»»» namebodystringnone
»»» loginNamebodystringnone
»»» receiverTypebodystring接收人类型
»» emailSubjectbodystring主题
»» defaultEmailSubjectbodystring默认主题
»» emailContentBodybodystring内容
»» defaultEmailContentBodybodystring默认内容
»» tooLargeContentBodybodystring附件内容过大时替换内容
»» defaultTooLargeContentBodybodystring默认附件内容过大时替换内容
»» attachmentTypesbodystring附件类型
»» emailAddressListbody[string]邮箱地址列表
» webhookbodyobjectwebhook推送配置
»» enabledbodyboolean是否开启
»» urlbodystringwebhook推送目的地址
»» methodbodystringHTTP请求类型
»» requestBodybodystring请求体(仅支持json格式请求体)
»» headersbody[string]请求头
» wecombodyobject企业微信推送配置
»» dashboardListbody[object]none
»»» idbodyintegernone
»»» titlebodystringnone
»» bodyWithDashboardUrlbodybooleannone
»» enabledbodybooleannone
»» bodyWithImagebodybooleannone
»» targetsbody[string]企业微信用户id列表
»» subjectbodystring消息主题
»» contentbodystring消息内容
»» bodyCustomizedbodyboolean是否开启自定义消息
»» defaultContentbodystring默认消息内容
» feishubodyobject飞书推送配置
»» dashboardListbody[object]none
»»» idbodyintegernone
»»» titlebodystringnone
»» bodyWithDashboardUrlbodybooleannone
»» enabledbodybooleannone
»» bodyWithImagebodybooleannone
»» targetsbody[string]none
»» subjectbodystringnone
»» contentbodystringnone
»» bodyCustomizedbodybooleannone
»» defaultContentbodystringnone
errorPolicebodyobject预警失败策略
» canPausebodyboolean能否暂停任务,暂停任务后需手动重新启动。
» intervalbodyinteger重试间隔时间,单位:分钟
» retryablebodyboolean能否重试
» notifyUserbodyboolean任务暂停后是否通知应用所有者
» retryTimesbodyinteger重试总次数
» failureTimesbodyinteger失败暂停阈值

模板变量

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

例子:

text
这是临时预警消息{{%%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

收件人类型

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

邮件附件类型

字段值描述
PNGpng文件
PDFpdf文件
EXCELexcel文件

接口说明

创建数据预警条目

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

请求参数

名称位置类型必选说明
appIdpathstringnone
requestIdquerystringnone
bodybodyobjectnone
» titlebodystring预警标题
» appIdbodyinteger预警所属 app id
» dashboardIdbodyinteger预警条件所选dashboard id
» chartIdbodyinteger预警条件所选chart id
» optionsbodyobject预警配置信息
»» rulesbody[object]预警触发条件,HE数组。可以有多个条件,每个条件为一个数组项。
»»» kindbodystringnone
»»» opbodystringnone
»»» argsbody[object]none
»»»» kindbodystringnone
»»»» opbodystringnone
»»»» argsbody[object]none
»»»»» kindbodystringnone
»»»»» opbodystringnone
»»»»» typebodystringnone
»» timingbodyobject触发时机配置信息
»»» cronTypebodystringcronType表达式类型
»»» cronDescbodystringcron表达式
»»» timeZonebodystring时区
»»» triggerTypebodystring值为(CRON_JOB)
»»» frequencybodystring频率,值为(ALWAYS,ONLY_ONCE,ONCE_EVERYDAY)之一
»» emailbodyobject邮件推送配置
»»» dashboardListbody[object]推送仪表盘列表
»»»» idbodyinteger仪表盘id
»»»» titlebodystring仪表盘标题
»»» bodyWithDashboardUrlbodyboolean正文是否附加仪表盘链接
»»» enabledbodyboolean是否开启
»»» bodyWithImagebodyboolean正文是否附加仪表盘图片
»»» compressAttachmentbodyboolean是否压缩附加
»»» receiverListbody[object]衡石系统内接收者列表
»»»» idbodyinteger接收者id
»»»» namebodystringnone
»»»» loginNamebodystringnone
»»»» receiverTypebodystring接收人类型
»»» emailSubjectbodystring主题
»»» defaultEmailSubjectbodystring默认主题
»»» emailContentBodybodystring内容
»»» defaultEmailContentBodybodystring默认内容
»»» tooLargeContentBodybodystring附件内容过大时替换内容
»»» defaultTooLargeContentBodybodystring默认附件内容过大时替换内容
»»» attachmentTypesbodystring附件类型
»»» emailAddressListbody[string]邮箱地址列表
»» webhookbodyobjectwebhook推送配置
»»» enabledbodyboolean是否开启
»»» urlbodystringwebhook推送目的地址
»»» methodbodystringHTTP请求类型
»»» requestBodybodystring请求体(仅支持json格式请求体)
»»» headersbody[string]请求头
»» wecombodyobject企业微信推送配置
»»» dashboardListbody[object]none
»»»» idbodyintegernone
»»»» titlebodystringnone
»»» bodyWithDashboardUrlbodybooleannone
»»» enabledbodybooleannone
»»» bodyWithImagebodybooleannone
»»» targetsbody[string]企业微信用户id列表
»»» subjectbodystring消息主题
»»» contentbodystring消息内容
»»» bodyCustomizedbodyboolean是否开启自定义消息
»»» defaultContentbodystring默认消息内容
»» feishubodyobject飞书推送配置
»»» dashboardListbody[object]none
»»»» idbodyintegernone
»»»» titlebodystringnone
»»» bodyWithDashboardUrlbodybooleannone
»»» enabledbodybooleannone
»»» bodyWithImagebodybooleannone
»»» targetsbody[string]none
»»» subjectbodystringnone
»»» contentbodystringnone
»»» bodyCustomizedbodybooleannone
»»» defaultContentbodystringnone
» errorPolicebodyobject预警失败策略
»» canPausebodyboolean能否暂停任务,暂停任务后需手动重新启动。
»» intervalbodyinteger重试间隔时间,单位:分钟
»» retryablebodyboolean能否重试
»» notifyUserbodyboolean任务暂停后是否通知应用所有者
»» retryTimesbodyinteger重试总次数
»» failureTimesbodyinteger失败暂停阈值
http
POST /api/apps/{appId}/alert HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

// Request 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
  }
}
http
HTTP/1.1 200 Ok
Content-Type: application/json

{
  "version": "version@9a5e106#6730f0d",
  "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
}

返回结果

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

分页查询预警

http
GET /api/apps/{appId}/alert/list HTTP/1.1
Accept: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

请求参数

名称位置类型必选说明
appIdpathstringnone
requestIdquerystringnone
offsetqueryLongnone
limitqueryLongnone

删除预警条目

http
DELETE /api/apps/{appId}/alert/{alertId} HTTP/1.1
Accept: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

请求参数

名称位置类型必选说明
appIdpathstringnone
alertIdpathstringnone
requestIdquerystringnone

根据ID查询预警

http
GET /api/apps/{appId}/alert/{alertId} HTTP/1.1
Accept: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

请求参数

名称位置类型必选说明
appIdpathstringnone
alertIdpathstringnone
requestIdquerystringnone

编辑数据预警条目

编辑特定的预警条目

请求参数

名称位置类型必选说明
appIdpathstringnone
alertIdpathstringnone
requestIdquerystringnone
bodybodyobjectnone
http
PUT /api/apps/{appId}/alert/{alertId} HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

// Request 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
  }
}
http
HTTP/1.1 200 OK
Content-Type: application/json

{
  "version": "version@9a5e106#6730f0d",
  "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
}

返回结果

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

验证预警条目

验证预警配置

请求参数

名称位置类型必选说明
appIdpathstringnone
requestIdquerystringnone
bodybodyobjectnone
http
POST /api/apps/{appId}/alert/validate HTTP/1.1
Content-Type: application/json
Cookie: csrf=183f1c4...; sid=26ee552d...; _USER_SESSION_ID=f2a01083...

// Request 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
  }
}
http
HTTP/1.1 200 OK
Content-Type: application/json

{
  "version": "version@9a5e106#6730f0d",
  "code": 0,
  "msg": "success",
  "chartDataStartTimeMillis": 0
}

返回结果

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

状态码 200

名称类型必选约束中文名说明
» versionstringtruenonenone
» codeintegertruenonenone
» msgstringtruenonenone
» chartDataStartTimeMillisintegertruenonenone

HENGSHI SENSE API 使用手册