Creating an Alarm Rule (V1)
Function
This API is used to create an alarm rule. The V1 API for creating alarm rules supports only single-resource single-policy rules. You are advised to use [CreateAlarmRules (Recommended)] (CreateAlarmRules.xml) to create alarm rules.
URI
POST /V1.0/{project_id}/alarms
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
project_id |
Yes |
String |
Definition Project ID. It is used to specify the project that an asset belongs to. You can query the assets of a project by project ID. You can obtain the project ID from the API or console. For details, see Obtaining a Project ID. Constraints N/A Range 1 to 64 characters Default Value N/A |
Request Parameters
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
Content-Type |
No |
String |
Definition MIME type of the request body. Constraints N/A Range 1 to 64 characters Default Value The default value is application/json; charset=UTF-8. For APIs used to upload objects or images, the MIME type varies with the flow type. |
|
X-Auth-Token |
No |
String |
Definition User token. Constraints N/A Range 1 to 16,384 characters Default Value N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
alarm_name |
Yes |
String |
Definition: Alarm name. Constraints: N/A Range: The value allows 1 to 128 characters and can only contain digits, letters, underscores (_), and hyphens (-). Default Value: N/A |
|
alarm_description |
No |
String |
Definition: Alarm description. Constraints: N/A Range: [0,256] Default Value: N/A |
|
metric |
Yes |
CreateAlarmMetric object |
Definition: Metric information in the created rule. Constraints: N/A |
|
condition |
Yes |
Condition object |
Definition: Alarm policy configured in the alarm rule. Constraints: N/A |
|
alarm_enabled |
No |
Boolean |
Definition: Whether to enable the alarm rule. Constraints: N/A Range: A boolean value, which can be:
Default Value: true |
|
alarm_action_enabled |
No |
Boolean |
Definition: Whether to enable alarm notifications when the alarm is triggered. Constraints: If alarm_action_enabled is set to true, alarm_actions, ok_actions, or both of them must be specified. If both alarm_actions and ok_actions are specified, their notification_list values must be the same. Range: A boolean value, which can be:
Default Value: true |
|
alarm_level |
No |
Integer |
Definition: Alarm severity. Constraints: N/A Range: The value can only be 1 (critical), 2 (major), 3 (minor), or 4 (informational). Default Value: 2 |
|
alarm_type |
No |
String |
Definition: Alarm type. Constraints: For event alarms, the alarm type is EVENT.SYS (system events) or EVENT.CUSTOM (custom event). For alarms generated for resource groups, the alarm type is RESOURCE_GROUP. For alarms generated for specific resources, the alarm type is MULTI_INSTANCE. Range:
Default Value: N/A |
|
alarm_actions |
No |
Array of Notification objects |
Definition: Information about the notification group or topic subscription when an alarm is triggered. A structure example is as follows: { "type": "notification","notificationList":["urn:smn:southchina:68438a86d98e427e907e0097b7e35d47:sd"] }. The value of type can be notification (SMN notifications) or autoscaling (AS notifications). Constraints: A maximum of 10 recipients are allowed. |
|
insufficientdata_actions |
No |
Array of Notification objects |
Definition: Notification group or topic subscription when an alarm notification is triggered due to insufficient data. (This parameter has been deprecated and does not need to be configured.) Constraints: A maximum of 10 alarm actions can be configured. |
|
ok_actions |
No |
Array of Notification objects |
Definition: Information about the notification group or topic subscription when the alarm is cleared. A structure example is as follows: { "type": "notification","notificationList":["urn:smn:southchina:68438a86d98e427e907e0097b7e35d47:sd"] }. The value of type can be notification (SMN notifications) or autoscaling (AS notifications). Constraints: |
|
alarm_action_begin_time |
No |
String |
Definition: Time when alarm notifications were enabled. Constraints: N/A Range: The value allows 1 to 64 characters and can only contain digits and colons (:). Default Value: N/A |
|
alarm_action_end_time |
No |
String |
Definition: Time when alarm notifications were disabled. Constraints: N/A Range: The value allows 1 to 64 characters and can only contain digits and colons (:). Default Value: N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
namespace |
Yes |
String |
Definition: Metric namespace. For example, the ECS namespace is SYS.ECS, and the DDS namespace is SYS.DDS. For the namespace of each service, see Service Namespaces. Constraints: When alarm_typeis set to EVENT.SYS or EVENT.CUSTOM, you can leave this parameter empty. Range: The value must be in the service.item format and contain 3 to 32 characters. service and item each must start with a letter and contain only letters, digits, and underscores (_). Default Value: N/A |
|
metric_name |
Yes |
String |
Definition: Metric name of a resource. For example, the ECS metric cpu_util indicates the CPU usage of an ECS. The DDS metric mongo001_command_ps indicates the command execution frequency. For details about the metrics of each service, see Service Metric Names. Constraints: N/A Range: The value must start with a letter and allow 1 to 96 characters. It can only contain letters, digits, and underscores (_). Default Value: N/A |
|
dimensions |
No |
Array of Dimension objects |
Definition: Metric dimension. Constraints: A maximum of four dimensions can be added. If resource_group_id is not required, dimensions is mandatory. |
|
resource_group_id |
No |
String |
Definition: ID of the resource group selected during the alarm rule creation. Constraints: If you create alarm rules for resource groups, you must specify resource_group_id and name, enter at least one dimension for dimensions, and set alarm_type to RESOURCE_GROUP, for example, rg1603786526428bWbVmk4rP. Range: The value allows 0 to 64 characters and can only contain letters, digits, underscores (_), and hyphens (-). Default Value: N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
name |
Yes |
String |
Definition: Monitoring dimension name. For example, the dimension of an ECS is instance_id. For details about the metric dimension name of each service resource, see Service Dimension Names. Constraints: N/A Range: The value must start with a letter and can only contain letters, digits, underscores (_), and hyphens (-). It allows 1 to 32 characters. Default Value: N/A |
|
value |
No |
String |
Definition: Monitoring dimension value, for example, the ECS ID. Constraints: N/A Range: [0,256] Default Value: N/A |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
comparison_operator |
Yes |
String |
Definition: Operator of an alarm threshold. Constraints: N/A Range:
NOTE:
, =, <, >=, <=, or !=
Default Value: N/A |
|
count |
Yes |
Integer |
Definition: Number of consecutive times that an alarm is triggered. Constraints: N/A Range: The value ranges from 1 to 5. For event alarms, the value ranges from 1 to 100. Default Value: N/A |
|
filter |
Yes |
String |
Definition: Data aggregation method. Constraints: N/A Range: The value can be:
Default Value: N/A |
|
period |
Yes |
Integer |
Definition Metric period, in seconds. For details about the original metric period for each cloud service, see Supported Services. Constraints N/A Range The value can be:
Default Value N/A |
|
unit |
No |
String |
Definition: Data unit. Constraints: N/A Range: [0,32] Default Value: N/A |
|
value |
Yes |
Number |
Definition: Specifies the alarm threshold. For details about the threshold value, see the value range of each service monitoring metric in the appendix. For example, the value range of cpu_util for ECS in [Services That Can Be Monitored] (ces_03_0059.xml) can be set to 80. Constraints: If there is only one threshold, value and alarm_level are used in pairs. If there are both hierarchical_value and value, hierarchical_value is used. Range: The minimum value is -1.7976931348623157e+108, and the maximum value is 1.7976931348623157e+108. Default Value: None |
|
Parameter |
Mandatory |
Type |
Description |
|---|---|---|---|
|
type |
Yes |
String |
Definition: Alarm notification type. Constraints: N/A Range: notification (SMN notifications) or autoscaling (AS notifications) Default Value: N/A |
|
notificationList |
Yes |
Array of strings |
Definition: Recipients to be notified of the alarm status changes. Constraints: A maximum of 20 recipients can be configured. The value of topicUrn can be obtained from SMN. For details, see section "Querying Topics". If type is set to notification, the value of notificationList cannot be left blank. If type is set to autoscaling, the value of notificationList must be left blank. Note: If alarm_action_enabled is set to true, you must specify either alarm_actions or ok_actions. (You do not need to configure the deprecated parameter insufficientdata_actions.) If alarm_actions and ok_actions coexist, their notificationList values must be the same. (You do not need to configure the deprecated parameter insufficientdata_actions.) |
Response Parameters
Status code: 201
|
Parameter |
Type |
Description |
|---|---|---|
|
alarm_id |
String |
Alarm rule ID. |
Status code: 400
|
Parameter |
Type |
Description |
|---|---|---|
|
- |
String |
Request error. |
Status code: 401
|
Parameter |
Type |
Description |
|---|---|---|
|
- |
String |
The authentication information is not provided or is incorrect. |
Status code: 403
|
Parameter |
Type |
Description |
|---|---|---|
|
- |
String |
Access to the requested page is forbidden. |
Status code: 408
|
Parameter |
Type |
Description |
|---|---|---|
|
- |
String |
The request timed out. |
Status code: 429
|
Parameter |
Type |
Description |
|---|---|---|
|
- |
String |
Too many requests. |
Status code: 500
|
Parameter |
Type |
Description |
|---|---|---|
|
- |
String |
Failed to complete the request because of an internal service error. |
Status code: 503
|
Parameter |
Type |
Description |
|---|---|---|
|
- |
String |
The system is currently unavailable. |
Example Requests
{
"alarm_name" : "alarm-rp0E",
"alarm_description" : "",
"metric" : {
"namespace" : "SYS.ECS",
"dimensions" : [ {
"name" : "instance_id",
"value" : "33328f02-3814-422e-b688-bfdba93d4051"
} ],
"metric_name" : "network_outgoing_bytes_rate_inband"
},
"condition" : {
"period" : 300,
"filter" : "average",
"comparison_operator" : ">=",
"value" : 6,
"unit" : "B/s",
"count" : 1
},
"alarm_enabled" : true,
"alarm_action_enabled" : true,
"alarm_level" : 2,
"alarm_actions" : [ {
"type" : "notification",
"notificationList" : [ "urn:smn:southchina:68438a86d98e427e907e0097b7e35d48:sd" ]
} ],
"ok_actions" : [ {
"type" : "notification",
"notificationList" : [ "urn:smn:southchina:68438a86d98e427e907e0097b7e35d48:sd" ]
} ],
"insufficientdata_actions" : [ {
"type" : "notification",
"notificationList" : [ "urn:smn:southchina:68438a86d98e427e907e0097b7e35d48:sd" ]
} ]
}
Example Responses
Status code: 201
Created
{
"alarm_id" : "al1604473956229Ym1m1Wx6e"
}
Status Codes
|
Status Code |
Description |
|---|---|
|
201 |
Created |
|
400 |
Bad Request |
|
401 |
Unauthorized |
|
403 |
Forbidden |
|
408 |
Request Timeout |
|
429 |
Too Many Requests |
|
500 |
Internal Server Error |
|
503 |
Service Unavailable |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.