In addition to notifications via email, DingTalk, Lark, WeCom, and Slack, Cloud Monitor offers an alert callback feature for more flexible event handling. This topic explains how to use this feature to forward system event notifications to a webhook. This allows you to integrate Cloud Monitor alerts with your existing O&M or notification systems.
Prerequisites
You must have a public URL for your operations or messaging system.
Background information
Cloud Monitor sends alert notifications to your URL as HTTP or HTTPS POST requests. Add the following IP address ranges to your firewall allowlist:
Procedure
Create a push channel.
This example uses a webhook as the push channel.
-
Log on to the Cloud Monitor console.
In the left-side navigation pane, choose Event Center > Event Subscription.
On the Event Subscription page, click the Push Channel tab.
On the Push Channel tab, click Create Push Channel.
In the Create Push Channel panel, enter a Channel Name, set Target Type to Webhook, Request Method to POST, and Data Format to JSON. In the Address field, enter the alert callback URL and use the default settings for the other parameters.
Click OK.
-
Create a subscription policy.
This example subscribes to the Instance Restart Started Due to Instance Error system event for an ECS instance and pushes notifications to the webhook.
Click the Subscription Policy tab.
On the Subscription Policy tab, click Create Subscription Policy.
On the Create Subscription Policy page, configure the parameters.
Basic Information: Enter a name for the subscription policy.
Alert Subscription: If you set Subscription Type to System Event, specify Product as Elastic Compute Service (ECS) and Event Name as Instance Restart Started Due to Instance Error in the Subscription Scope section, and do not configure any other parameters, you will subscribe to the Instance Restart Started Due to Instance Error system event for all ECS instances in your account.
NoteFor more information about the system events that ECS supports, see ECS.
Merge and Denoise: Use the default settings.
Notification: Do not configure Notification Configuration. Use the default notification method for Custom Notification Method.
NoteBecause no alert group is configured for the Notification Settings, there are no alert contacts, and you will not receive alert notifications.
Push and Integration: Select the push channel created in Step 1.
Click Submit.
Debug the event subscription.
On the Subscription Policy tab, click Debug Event Subscription.
In the Create Event Debugging panel, set Product to ECS and Name to Instance Restart Started Due to Instance Error.
The system automatically generates the debug content in JSON format.
Click OK.
The system displays an Operation successful message. Cloud Monitor then automatically sends a test alert notification to the webhook URL that you specified.
Results
When a system event triggers an alert, Cloud Monitor sends the alert information to the URL that you specified. Webhooks support POST and GET request methods. The following examples show the request content for each method:
POST JSON
Parameter name:
body.Sample content:
{ "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": "China (Hangzhou)", "groupId": "", "serviceTypeEn": "ECS", "eventType": "Notification", "serviceTypeZh": "ECS", "regionId": "cn-hangzhou", "eventTime": "20240109T140533.642+0800", "name": "CloudAssistant:FirstHeartbeat", "id": "testid", "status": "Normal", "eventNameZh": "First heartbeat event of the cloud assistant" } } }, "severity": "INFO", "strategyName": "eventwebhook", "userId": "test", "time": 1704780333000 }GET JSON
Parameter name:
data.Sample content:
{ "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": "China (Hangzhou)", "groupId": "", "serviceTypeEn": "ECS", "eventType": "Notification", "serviceTypeZh": "ECS", "regionId": "cn-hangzhou", "eventTime": "20240109T140533.642+0800", "name": "CloudAssistant:FirstHeartbeat", "id": "testid", "status": "Normal", "eventNameZh": "First heartbeat event of the cloud assistant" } } }, "severity": "INFO", "strategyName": "eventwebhook", "userId": "test", "time": 1704780333000 }POST FORM and GET FORM
Parameter
Value
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": "China (Hangzhou)", "groupId": "", "serviceTypeEn": "ECS", "eventType": "Notification", "serviceTypeZh": "ECS", "regionId": "cn-hangzhou", "eventTime": "20240109T140533.642+0800", "name": "CloudAssistant:FirstHeartbeat", "id": "testid", "status": "Normal", "eventNameZh": "First heartbeat event of the cloud assistant" } } }severity
INFO
strategyName
eventwebhook
userId
test
time
1704780333000
Field descriptions
Field | Description | |
Outer fields | batchId | The batch ID of the notification. Each ID represents a unique notification delivery. |
severity | The severity level. | |
strategyName | The name of the subscription policy. | |
userId | The ID of the Alibaba Cloud account. | |
time | The event time. | |
Fields in the | aliyunId | The ID of the Alibaba Cloud account. |
userIdSec | The ID of the RAM user. | |
aliyunIdSec | The masked ID of the Alibaba Cloud account. | |
nickName | The alias of the Alibaba Cloud account. | |
nickNameSec | The masked alias of the Alibaba Cloud account. | |
userName | The logon ID of the Alibaba Cloud account. | |
userId | The ID of the Alibaba Cloud account. | |
userNameSec | The masked logon ID of the Alibaba Cloud account. | |
Fields in the | subscriptionUuid | The unique ID of the subscription policy. |
conditions | The conditions of the subscription policy:
| |
relation | The logical relationship between conditions. Valid values: | |
Fields in the | alertStatus | The alert status. Valid values: |
groupId | The ID of the application group. | |
source | The type of the most recent alert event. | |
dedupId | The deduplication ID of the event. | |
eventName | The event name. | |
arn | The Alibaba Cloud Resource Name (ARN) of the resource that generated the event. | |
timestamp | The event timestamp. | |
traceId | The original ID of the event. | |
severity | The severity level. | |
product | The product name. | |
eventRawContent | The raw event data as a JSON string. The content varies depending on the cloud service. | |
eventType | The event type. | |
userId | The ID of the Alibaba Cloud account. | |
Fields in the | regionNameEn | The name of the region in English. |
resourceId | Information about the resource that is associated with the event. | |
product | The product code. | |
eventNameEn | The name of the event in English. | |
instanceName | The instance name. | |
level | The event level. | |
resource | The ARN of the system event. | |
regionNameZh | The name of the region in Chinese. | |
groupId | The ID of the application group. | |
serviceTypeEn | The service type in English. | |
eventType | The event type. | |
serviceTypeZh | The service type in Chinese. | |
regionId | The region ID. | |
eventTime | The time when the event was generated. | |
name | The event name. | |
id | The event ID. | |
status | The event status. | |
eventNameZh | The name of the event in Chinese. | |
Fields in the | The | |