云监控除了电话、短信、邮件、钉钉、飞书、企业微信和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