云監控除了電話、短信、郵件、釘釘、飛書、企業微信和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加入防火墻的白名單。當您接收到報警通知后,可以根據通知內容做進一步處理。
操作步驟
創建推送渠道。
本文以創建推送渠道Webhook為例進行介紹。
登錄云監控控制臺。
在左側導航欄,選擇 。
在事件訂閱頁面,單擊推送渠道頁簽。
在推送渠道頁簽,單擊創建推送渠道。
在創建推送渠道面板,輸入渠道名稱,目標類型選擇Webhook,請求方式選擇POST,數據格式選擇JSON,地址輸入報警回調的URL地址,其他參數均不設置。
單擊確認。
創建訂閱策略。
以訂閱ECS實例的系統事件因實例錯誤實例重啟開始,并推送到Webhook為例。
調試事件訂閱。
在訂閱策略頁簽,單擊調試事件訂閱。
在創建事件調試面板,產品選擇云服務器ECS,名稱選擇因實例錯誤實例重啟開始。
系統自動生成JSON格式的調試內容。
單擊確定。
系統提示操作成功,云監控自動給您設置的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