全部產品
Search
文件中心

CloudMonitor:使用系統事件警示回調(推薦)

更新時間:Jun 19, 2024

CloudMonitor除了郵件、DingTalk、飛書、企業微信和Slack的警示通知方式外,還可以使用警示回調方式,讓您更自由、更靈活的處理事件警示。本文以將訂閱的系統事件推送至Webhook為例,為您介紹如何使用系統事件的警示回調功能,實現將CloudMonitor發送的警示通知整合到已有的營運系統或訊息通知系統。

前提條件

請確保您已準備好公網URL地址。該URL地址為營運系統或訊息通知系統的URL地址。

背景資訊

CloudMonitor通過HTTP協議或HTTPS協議的POST請求推送警示通知到您指定的URL地址,請您將IP地址47.74.206.0/26、47.74.206.64/26、47.74.206.128/26、47.74.206.192/26和8.222.159.116/26加入防火牆的白名單。當您接收到警示通知後,可以根據通知內容做進一步處理。

操作步驟

  1. 建立推送渠道。

    本文以建立推送渠道Webhook為例進行介紹。

    1. 登入CloudMonitor控制台

    2. 在左側導覽列,選擇事件中心 > 事件訂閱

    3. 事件訂閱頁面,單擊推送渠道頁簽。

    4. 推送渠道頁簽,單擊建立推送渠道

    5. 建立推送渠道面板,輸入渠道名稱,目標類型選擇Webhook請求方式選擇POST資料格式選擇JSON地址輸入警示回調的URL地址,其他參數均不設定。

    6. 單擊確認

  2. 建立訂閱策略。

    以訂閱ECS執行個體的系統事件因執行個體錯誤執行個體重啟開始,並推送到Webhook為例。

    1. 單擊訂閱策略頁簽。

    2. 訂閱策略頁簽,單擊建立訂閱策略

    3. 建立訂閱策略頁面,設定訂閱策略的相關參數。

      • 基本資料:輸入訂閱策略名稱稱。

      • 警示訂閱訂閱類型選擇系統事件訂閱範圍中的產品選擇Elastic Compute Service事件名稱選擇因執行個體錯誤執行個體重啟開始,其他參數均不設定,表示訂閱本帳號內所有ECS執行個體的系統事件因執行個體錯誤執行個體重啟開始

        說明

        關於Elastic Compute Service支援的系統事件,請參見Elastic Compute Service

      • 合并降噪:使用預設值。

      • 通知通知配置不設定,自訂通知方式使用預設通知方式。

        說明

        由於通知配置未設定警示組,即無警示連絡人,將不會收到警示通知。

      • 推送與整合:選擇步驟 1建立的推送渠道。

    4. 單擊提交

  3. 調試事件訂閱。

    1. 訂閱策略頁簽,單擊調試事件訂閱

    2. 建立事件調試面板,產品選擇Elastic Compute Service名稱選擇因執行個體錯誤執行個體重啟開始

      系統自動產生JSON格式的調試內容。

    3. 單擊確定

      系統提示操作成功,CloudMonitor自動給您設定的Webhook地址發送一條測試警示通知。

執行結果

當系統事件觸發警示時,CloudMonitor會將警示資訊發送到您指定的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": "Elastic Compute Service",
            "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": "Elastic Compute Service",
            "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": "Elastic Compute Service",
            "regionId": "cn-hangzhou",
            "eventTime": "20240109T140533.642+0800",
            "name": "CloudAssistant:FirstHeartbeat",
            "id": "testid",
            "status": "Normal",
            "eventNameZh": "雲助手首次心跳事件"
          }
        }
      }

    severity

    INFO

    strategyName

    eventwebhook

    userId

    test

    time

    1704780333000

相關文檔