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

云监控除了电话、短信、邮件、钉钉、飞书、企业微信和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/24和121.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的请求方法包括POST和GET,其请求内容如下:

  • 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 FORM和GET 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

相关文档