Creating a Custom Alarm Template
Function
This API is used to create a custom alarm template.
URI
POST /v2/{project_id}/alarm-templates
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 |
|---|---|---|---|
X-Auth-Token | Yes | String | Definition User token. Constraints N/A Range 1 to 16,384 characters Default Value N/A |
Parameter | Mandatory | Type | Description |
|---|---|---|---|
template_name | Yes | String | Definition Alarm template name. Constraints N/A Range The value allows 1 to 128 characters. It must start with a letter and can only contain letters, digits, underscores (_), and hyphens (-). Default Value N/A |
template_type | No | Integer | Definition Custom alarm template type. Constraints N/A Range The value can be:
Default Value 0 |
template_description | No | String | Definition Alarm template description. Constraints N/A Range [0,256] Default Value An empty string |
is_overwrite | No | Boolean | Definition Whether to overwrite the existing alarm template with the same name. Constraints N/A Range A boolean value.
Default Value false |
policies | Yes | Array of Policies objects | Definition Alarm policies in an alarm template. Constraints A maximum of 1000 policies can be configured. |
Parameter | Mandatory | Type | Description |
|---|---|---|---|
namespace | Yes | String | Definition Namespace of a service. For details about the namespace of each service, see Service Namespaces. Constraints N/A Range The value is in the service.item format. The values of service and item must be a string, starting with a letter and containing only digits (0–9), letters (case-insensitive), and underscores (_). The value must contain 3 to 32 characters. Default Value N/A |
dimension_name | No | String | Definition Resource dimension. Constraints The DimensionName field of the event alarm template is empty. Range The value must start with a letter. Each dimension allows a maximum of 32 characters and can only contain digits, letters, underscores (_), and hyphens (-). Multiple dimensions are separated by commas (,). A maximum of four dimensions are supported. Example: instance_id for single-dimension scenarios and instance_id,disk for multi-dimension scenarios. Default Value N/A |
metric_name | Yes | String | Definition Metric name of a resource. For details about the metrics of each service, see Service Metric Names. Constraints N/A Range The value must start with a letter and can only contain digits, letters, underscores (_), and hyphens (-). 1 to 96 characters 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. Default Value N/A |
extra_info | No | MetricExtraInfo object | Definition Additional information about the alarm policy. Constraints N/A |
period | Yes | Integer | Definition Interval (seconds) for checking whether the alarm rule conditions are met. Constraints N/A Range The value can be:
Default Value N/A |
filter | Yes | String | Definition Aggregation method. Constraints N/A Range average, variance, min, max, or sum Default Value N/A |
comparison_operator | Yes | String | Definition Threshold symbol. Constraints The threshold symbols for metric alarms are >, >=, <, <=, =, !=, cycle_decrease, cycle_increase, and cycle_wave. The threshold symbols for event alarms are >, >=, <, <=, =, and !=. Range The value can be >, <, >=, <=, =, !=, cycle_decrease, cycle_increase, or cycle_wave. cycle_decrease indicates the decrease relative to the last period; cycle_increase indicates the increase relative to the last period; cycle_wave indicates the increase or decrease relative to the last period. Default Value N/A |
value | No | Number | Definition Alarm threshold. 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 N/A Default Value N/A |
hierarchical_value | No | HierarchicalValue object | Definition Multi-level alarm threshold. Constraints If there are both hierarchical_value and value, hierarchical_value is used. When you create or modify an alarm rule, you can set only one threshold in the following scenarios:
|
unit | No | String | Definition Data unit. The value can contain a maximum of 32 characters. Constraints N/A Range [0,32] Default Value N/A |
selected_unit | No | String | Definition The metric unit you selected. It is used for subsequent metric data display and calculation. Constraints N/A Range [0,64] Default Value N/A |
count | Yes | Integer | Definition Number of times that the alarm triggering conditions are met. Constraints N/A Range For event alarms, the value ranges from 1 to 180. For metric and website alarms, the value can be 1, 2, 3, 4, 5, 10, 15, 30, 60, 90, 120, or 180. Default Value N/A |
type | No | String | Definition Alarm policy type. This API has been deprecated. Constraints N/A Range The value can only be auto. Default Value N/A |
alarm_level | No | Integer | Definition Alarm severity. Constraints N/A Range The value can be:
Default Value N/A |
suppress_duration | No | Integer | Definition Alarm suppression interval, in seconds. Constraints N/A Range The value can be:
Default Value N/A |
Parameter | Mandatory | Type | Description |
|---|---|---|---|
origin_metric_name | Yes | String | Definition Original metric name. Constraints N/A Range 0 to 4,096 characters Default Value N/A |
metric_prefix | No | String | Definition Metric name prefix. Constraints N/A Range 0 to 4,096 characters Default Value N/A |
custom_proc_name | No | String | Definition Name of a process. Constraints N/A Range [0,250] Default Value N/A |
metric_type | No | String | Definition Metric type. Constraints N/A Range 0 to 32 characters Default Value N/A |
Parameter | Mandatory | Type | Description |
|---|---|---|---|
critical | No | Double | Definition Threshold for critical alarms. Constraints N/A Range [-1.7976931348623157e+108, 1.7976931348623157e+108] Default Value N/A |
major | No | Double | Definition Threshold for major alarms. Constraints N/A Range [-1.7976931348623157e+108, 1.7976931348623157e+108] Default Value N/A |
minor | No | Double | Definition Threshold for minor alarms. Constraints N/A Range [-1.7976931348623157e+108, 1.7976931348623157e+108] Default Value N/A |
info | No | Double | Definition Threshold for warnings. Constraints N/A Range [-1.7976931348623157e+108, 1.7976931348623157e+108] Default Value N/A |
Response Parameters
Status code: 201
Parameter | Type | Description |
|---|---|---|
template_id | String | Definition Alarm template ID. Constraints N/A Range The value starts with at and allows 2 to 64 characters. It can only contain letters and digits. Default Value N/A |
overwrite_result | OverwriteResultResp object | Definition Whether to overwrite an existing template with the same name. |
Parameter | Type | Description |
|---|---|---|
success_ids | String | Definition: ID of the template that is overwritten. Range: 2 to 64 characters |
failed_ids | String | Definition: ID of the template that is not overwritten. Range: 2 to 64 characters |
Status code: 400
Parameter | Type | Description |
|---|---|---|
error_code | String | Status codes customized by each cloud service when a request error occurs. |
error_msg | String | Request error message. |
request_id | String | Request ID. |
Status code: 401
Parameter | Type | Description |
|---|---|---|
error_code | String | Status codes customized by each cloud service when a request error occurs. |
error_msg | String | Request error message. |
request_id | String | Request ID. |
Status code: 403
Parameter | Type | Description |
|---|---|---|
error_code | String | Status codes customized by each cloud service when a request error occurs. |
error_msg | String | Request error message. |
request_id | String | Request ID. |
Status code: 500
Parameter | Type | Description |
|---|---|---|
error_code | String | Status codes customized by each cloud service when a request error occurs. |
error_msg | String | Request error message. |
request_id | String | Request ID. |
Example Requests
Creating a custom alarm template whose template_name is my_template, count is 2, suppress_duration is 300, and alarm_level is 2.
{
"template_name" : "my_template",
"template_description" : "hello world",
"policies" : [ {
"namespace" : "SYS.ECS",
"dimension_name" : "instance_id",
"metric_name" : "cpu_util",
"period" : 300,
"filter" : "sum",
"comparison_operator" : ">",
"value" : 2,
"unit" : "bit/s",
"count" : 2,
"alarm_level" : 2,
"suppress_duration" : 300
} ]
} Example Responses
Status code: 201
Created
{
"template_id" : "at1628592157541dB1klWgY6"
} Status Codes
Status Code | Description |
|---|---|
201 | Created |
400 | Parameter verification failed. |
401 | Not authenticated. |
403 | Authentication failed. |
500 | Internal system error. |
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.

