使用系统事件报警回调(推荐)

更新时间:2025-03-26 05:51:10

云监控除了电话、短信、邮件、钉钉、飞书、企业微信和Slack的报警通知方式外,还可以使用报警回调方式,让您更自由、更灵活的处理事件报警。本文以将订阅的系统事件推送至Webhook为例,为您介绍如何使用系统事件的报警回调功能,实现将云监控发送的报警通知集成到已有的运维系统或消息通知系统。

前提条件

请确保您已准备好公网URL地址。该URL地址为运维系统或消息通知系统的URL地址。

背景信息

云监控通过HTTP协议或HTTPS协议的POST请求推送报警通知到您指定的URL地址,请您将IP地址106.11.225.0/24、106.11.226.0/24、106.11.227.0/24、106.11.242.0/24、106.11.167.0/24、106.11.245.0/24、59.82.0.0/16、59.82.84.0/24、203.119.128.0/17、203.119.156.0/24121.41.9.246加入防火墙的白名单。当您接收到报警通知后,可以根据通知内容做进一步处理。

操作步骤

  1. 创建推送渠道。

    本文以创建推送渠道Webhook为例进行介绍。

    1. 登录云监控控制台

    2. 在左侧导航栏,选择事件中心 > 事件订阅

    3. 事件订阅页面,单击推送渠道页签。

    4. 推送渠道页签,单击创建推送渠道

    5. 创建推送渠道面板,输入渠道名称,目标类型选择Webhook请求方式选择POST数据格式选择JSON地址输入报警回调的URL地址,其他参数均不设置。

    6. 单击确认

  2. 创建订阅策略。

    以订阅ECS实例的系统事件因实例错误实例重启开始,并推送到Webhook为例。

    1. 单击订阅策略页签。

    2. 订阅策略页签,单击创建订阅策略

    3. 创建订阅策略页面,设置订阅策略的相关参数。

      • 基本信息:输入订阅策略名称。

      • 报警订阅订阅类型选择系统事件订阅范围中的产品选择云服务器ECS事件名称选择因实例错误实例重启开始,其他参数均不设置,表示订阅本账号内所有ECS实例的系统事件因实例错误实例重启开始

        说明

        关于云服务器ECS支持的系统事件,请参见云服务器ECS

      • 合并降噪:使用默认值。

      • 通知通知配置不设置,自定义通知方式使用默认通知方式。

        说明

        由于通知配置未设置报警组,即无报警联系人,将不会收到报警通知。

      • 推送与集成:选择步骤 1创建的推送渠道。

    4. 单击提交

  3. 调试事件订阅。

    1. 订阅策略页签,单击调试事件订阅

    2. 创建事件调试面板,产品选择云服务器ECS名称选择因实例错误实例重启开始

      系统自动生成JSON格式的调试内容。

    3. 单击确定

      系统提示操作成功,云监控自动给您设置的Webhook地址发送一条测试报警通知。

执行结果

当系统事件触发报警时,云监控会将报警信息发送到您指定的URL地址。Webhook的请求方法包括POSTGET,其请求内容如下:

  • POST JSON

    参数名称:body

    内容如下:

    {
      "userInfo": {
        "aliyunId": "test",
        "userIdSec": "te***st",
        "aliyunIdSec": "test***test",
        "nickName": "test",
        "nickNameSec": "te***st",
        "userName": "test",
        "userId": "test",
        "userNameSec": "te***st"
      },
      "subscription": {
        "subscriptionUuid": "testid",
        "conditions": [
          {
            "field": "source",
            "op": "EQ",
            "value": "SYS_EVENT"
          },
          {
            "field": "product",
            "op": "IN",
            "value": "ECS,Redis,RDS,Config,tag"
          }
        ],
        "relation": "AND"
      },
      "batchId": "testbatchid",
      "alert": {
        "alertStatus": "TRIGGERED",
        "groupId": "",
        "source": "SYS_EVENT",
        "eventContentMap": {
          "extensions": {
            "agentVersion": "test-version",
            "region": "cn-hangzhou",
            "azone": "cn-hangzhou-i",
            "uptime": 23000
          },
          "vmName": "i-testhost",
          "impact": "Alert",
          "opsCode": "InstanceStatusChange",
          "bizEventId": "test-event-id"
        },
        "dedupId": "test-id",
        "eventName": "CloudAssistant:FirstHeartbeat",
        "arn": "acs:ecs:cn-hangzhou:testuser:instance/i-testhost",
        "timestamp": 1704780333000,
        "traceId": "testid",
        "severity": "INFO",
        "product": "ECS",
        "eventRawContent": "{}",
        "eventType": "Notification",
        "userId": "test",
        "meta": {
          "sysEventMeta": {
            "regionNameEn": "cn-hangzhou",
            "resourceId": "acs:ecs:cn-hangzhou:test:instance/i-testhost",
            "product": "ECS",
            "eventNameEn": "CloudAssistant:FirstHeartbeat",
            "instanceName": "i-testhost",
            "level": "INFO",
            "resource": "",
            "regionNameZh": "华东1(杭州)",
            "groupId": "",
            "serviceTypeEn": "ECS",
            "eventType": "Notification",
            "serviceTypeZh": "云服务器ECS",
            "regionId": "cn-hangzhou",
            "eventTime": "20240109T140533.642+0800",
            "name": "CloudAssistant:FirstHeartbeat",
            "id": "testid",
            "status": "Normal",
            "eventNameZh": "云助手首次心跳事件"
          }
        }
      },
      "severity": "INFO",
      "strategyName": "eventwebhook",
      "userId": "test",
      "time": 1704780333000
    }
  • GET JSON

    参数名称:data

    内容如下:

    {
      "userInfo": {
        "aliyunId": "test",
        "userIdSec": "te***st",
        "aliyunIdSec": "test***test",
        "nickName": "test",
        "nickNameSec": "te***st",
        "userName": "test",
        "userId": "test",
        "userNameSec": "te***st"
      },
      "subscription": {
        "subscriptionUuid": "testid",
        "conditions": [
          {
            "field": "source",
            "op": "EQ",
            "value": "SYS_EVENT"
          },
          {
            "field": "product",
            "op": "IN",
            "value": "ECS,Redis,RDS,Config,tag"
          }
        ],
        "relation": "AND"
      },
      "batchId": "testbatchid",
      "alert": {
        "alertStatus": "TRIGGERED",
        "groupId": "",
        "source": "SYS_EVENT",
        "eventContentMap": {
          "extensions": {
            "agentVersion": "test-version",
            "region": "cn-hangzhou",
            "azone": "cn-hangzhou-i",
            "uptime": 23000
          },
          "vmName": "i-testhost",
          "impact": "Alert",
          "opsCode": "InstanceStatusChange",
          "bizEventId": "test-event-id"
        },
        "dedupId": "test-id",
        "eventName": "CloudAssistant:FirstHeartbeat",
        "arn": "acs:ecs:cn-hangzhou:testuser:instance/i-testhost",
        "timestamp": 1704780333000,
        "traceId": "testid",
        "severity": "INFO",
        "product": "ECS",
        "eventRawContent": "{}",
        "eventType": "Notification",
        "userId": "test",
        "meta": {
          "sysEventMeta": {
            "regionNameEn": "cn-hangzhou",
            "resourceId": "acs:ecs:cn-hangzhou:test:instance/i-testhost",
            "product": "ECS",
            "eventNameEn": "CloudAssistant:FirstHeartbeat",
            "instanceName": "i-testhost",
            "level": "INFO",
            "resource": "",
            "regionNameZh": "华东1(杭州)",
            "groupId": "",
            "serviceTypeEn": "ECS",
            "eventType": "Notification",
            "serviceTypeZh": "云服务器ECS",
            "regionId": "cn-hangzhou",
            "eventTime": "20240109T140533.642+0800",
            "name": "CloudAssistant:FirstHeartbeat",
            "id": "testid",
            "status": "Normal",
            "eventNameZh": "云助手首次心跳事件"
          }
        }
      },
      "severity": "INFO",
      "strategyName": "eventwebhook",
      "userId": "test",
      "time": 1704780333000
    }
  • POST FORMGET FORM

    参数名称

    内容

    参数名称

    内容

    userInfo

    {
        "aliyunId": "test",
        "userIdSec": "te***st",
        "aliyunIdSec": "test***test",
        "nickName": "test",
        "nickNameSec": "te***st",
        "userName": "test",
        "userId": "test",
        "userNameSec": "te***st"
     }

    subscription

    {
        "subscriptionUuid": "testid",
        "conditions": [
          {
            "field": "source",
            "op": "EQ",
            "value": "SYS_EVENT"
          },
          {
            "field": "product",
            "op": "IN",
            "value": "ECS,Redis,RDS,Config,tag"
          }
        ],
        "relation": "AND"
      }

    alert

     {
        "alertStatus": "TRIGGERED",
        "groupId": "",
        "source": "SYS_EVENT",
        "eventContentMap": {
          "extensions": {
            "agentVersion": "test-version",
            "region": "cn-hangzhou",
            "azone": "cn-hangzhou-i",
            "uptime": 23000
          },
          "vmName": "i-testhost",
          "impact": "Alert",
          "opsCode": "InstanceStatusChange",
          "bizEventId": "test-event-id"
        },
        "dedupId": "test-id",
        "eventName": "CloudAssistant:FirstHeartbeat",
        "arn": "acs:ecs:cn-hangzhou:testuser:instance/i-testhost",
        "timestamp": 1704780333000,
        "traceId": "testid",
        "severity": "INFO",
        "product": "ECS",
        "eventRawContent": "{}",
        "eventType": "Notification",
        "userId": "test",
        "meta": {
          "sysEventMeta": {
            "regionNameEn": "cn-hangzhou",
            "resourceId": "acs:ecs:cn-hangzhou:test:instance/i-testhost",
            "product": "ECS",
            "eventNameEn": "CloudAssistant:FirstHeartbeat",
            "instanceName": "i-testhost",
            "level": "INFO",
            "resource": "",
            "regionNameZh": "华东1(杭州)",
            "groupId": "",
            "serviceTypeEn": "ECS",
            "eventType": "Notification",
            "serviceTypeZh": "云服务器ECS",
            "regionId": "cn-hangzhou",
            "eventTime": "20240109T140533.642+0800",
            "name": "CloudAssistant:FirstHeartbeat",
            "id": "testid",
            "status": "Normal",
            "eventNameZh": "云助手首次心跳事件"
          }
        }
      }

    severity

    INFO

    strategyName

    eventwebhook

    userId

    test

    time

    1704780333000

返回字段说明

字段

描述

字段

描述

外层字段

batchId

当前发送通知的批次id,表示每一次通知

severity

严重级别

strategyName

订阅名称

userId

用户ID

time

事件时间

userInfo 对象字段

aliyunId

阿里云ID

userIdSec

阿里云ID

aliyunIdSec

脱敏的阿里云ID

nickName

阿里云别名

nickNameSec

脱敏的阿里云别名

userName

阿里云登录Id

userId

阿里云ID

userNameSec

脱敏的阿里云登录Id

subscription 对象字段

subscriptionUuid

订阅策略的唯一Id

conditions

事件订阅策略条件:

  • field:订阅字段。

  • op:条件对比符号。

  • value:对比值。

relation

订阅条件管理,

取值 AND /OR,默认为AND

alert 对象字段

alertStatus

报警状态:

取值TRIGGERED, RESOLVED;

groupId

应用分组ID

source

最近报警事件类型

dedupId

事件的去重ID

eventName

事件名称

arn

产生事件资源信息

timestamp

事件时间戳

traceId

事件原始Id

severity

严重级别

product

产品名称

eventRawContent

事件原始数据内容JSON字符串,每个云服务不同

eventType

事件类型

userId

用户ID

meta.sysEventMeta(子对象字段)

regionNameEn

region英文信息

resourceId

事件相关资源信息

product

产品code

eventNameEn

事件英文名称

instanceName

实例名称

level

事件等级

resource

系统事件ARN

regionNameZh

region中文信息

groupId

应用分组ID

serviceTypeEn

服务类型(英文)

eventType

事件类型

serviceTypeZh

服务类型(中文)

regionId

region ID

eventTime

事件产生时间

name

事件名称

id

事件ID

status

事件状态

eventNameZh

事件中文名称

eventContentMap(子对象字段)

eventContentMap该字段是有各个业务方上报的信息,需要查具体的云产品的事件文档

相关文档

  • 本页导读 (1)
  • 前提条件
  • 背景信息
  • 操作步骤
  • 执行结果
  • 返回字段说明
  • 相关文档
AI助理

点击开启售前

在线咨询服务

你好,我是AI助理

可以解答问题、推荐解决方案等