Help Center/ Cloud Eye/ API Reference/ API/ Alarms/ Alarm Rules/ Creating an Alarm Rule (Recommended)
Updated on 2026-06-11 GMT+08:00

Creating an Alarm Rule (Recommended)

Function

This API is used to create alarm rules.

Debugging

You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.

  • If you are using role/policy-based authorization, see Permissions Policies and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

    Action

    Access Level

    Resource Type (*: required)

    Condition Key

    Alias

    Dependencies

    ces:alarms:create

    Write

    -

    • g:EnterpriseProjectId

    • g:RequestTag/<tag-key>

    • g:TagKeys

    • ces:namespace

    -

    -

URI

POST /v2/{project_id}/alarms

Table 1 Path Parameters

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

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

Content-Type

No

String

Definition

MIME type of the request body.

Constraints:

None

Value range:

The value can contain 1 to 64 characters.

Default value:

The default type is application/json; charset=UTF-8.

X-Auth-Token

No

String

Definition

User token.

Constraints:

None

Value range:

The value can contain 1 to 16,384 characters.

Default value:

None

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

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

description

No

String

Definition

Alarm description.

Constraints

N/A

Range

[0,256]

Default Value

N/A

namespace

Yes

String

Definition

Namespace of the service. For details, see Services Interconnected with Cloud Eye.

Constraints

N/A

Range

The value is in the service.item format. The values of service and item must start with a letter and contain only letters, digits, and underscores (_). It can contain up to 32 characters.

Default Value

N/A

resource_group_id

No

String

Definition

Resource group ID.

Constraints

N/A

Range

The value starts with rg and is followed by 22 characters that may include letters, digits, or a combination of both. It can contain 2 to 24 characters.

Default Value

N/A

resources

Yes

Array<Array<Dimension>>

Definition

Resource list.

Constraints

If an alarm rule is created for all resources or resources in a resource group, leave the resource dimension blank. If the alarm rule is created for specified resources, the resource dimension value is mandatory, and you can specify multiple resources to be monitored at a time. A maximum of 1,000 resource dimensions can be specified.

policies

No

Array of AlarmRulePolicy objects

Definition

Alarm policy.

Constraints

This parameter is mandatory when alarm_template_id is left blank. Otherwise, leave it empty. You can specify up to 50 policies.

type

Yes

String

Definition

Alarm rule type.

Constraints

N/A

Range

The value can be:

  • ALL_INSTANCE: The alarm rule is created for all resources.

  • RESOURCE_GROUP: The alarm rule is created for resource groups.

  • MULTI_INSTANCE: The alarm rule is created for specific resources.

  • EVENT.SYS: The alarm rule is created for system events.

  • EVENT.CUSTOM: The alarm rule is created for custom events.

  • DNSHealthCheck: The alarm rule is created for health check.

Default Value

N/A

alarm_notifications

No

Array of Notification objects

Definition

Notification group or topic subscription for alarm notifications.

Constraints

You can specify up to 10 notification groups or topic subscriptions.

ok_notifications

No

Array of Notification objects

Definition

Information about the notification group or topic subscription when the alarm is cleared.

Constraints

You can specify up to 10 notification groups or topic subscriptions.

notification_begin_time

No

String

Definition

Time when alarm notifications were enabled. Example: 00:00

Constraints

N/A

Range

The value allows 1 to 64 characters and can only contain digits and colons (:).

Default Value

N/A

notification_end_time

No

String

Definition

Time when alarm notifications were disabled. Example: 08:00

Constraints

N/A

Range

The value allows 1 to 64 characters and can only contain digits and colons (:).

Default Value

N/A

effective_timezone

No

String

Definition

Time zone, for example, GMT-08:00, GMT+08:00, or GMT+0:00.

Constraints

N/A

Range

1 to 16 characters

Default Value

N/A

enterprise_project_id

No

String

Definition

Enterprise project ID.

Constraints

N/A

Range

The value can only contain lowercase letters, digits, and hyphens (-). 0 indicates the ID of the default enterprise project.

Default Value

N/A

enabled

Yes

Boolean

Definition

Whether to enable the alarm rule.

Constraints

N/A

Range

A boolean value.

  • true: enabled

  • false: disabled

Default Value

true

notification_enabled

Yes

Boolean

Definition

Whether to enable alarm notifications. If notification_enabled is set to true, you must specify either alarm_notifications or ok_notifications.

Constraints

N/A

Range

A boolean value, which can be:

  • true: enabled.

  • false: disabled.

Default Value

true

alarm_template_id

No

String

Definition

ID of the alarm template associated with the alarm rule.

Constraints

If this parameter is specified, the policies associated with the alarm rule will change accordingly.

Range

The value starts with at and allows 2 to 64 characters. It can only contain letters and digits.

Default Value

N/A

tags

No

Array of ResourceTag objects

Definition

Tenant tags.

Constraints

You can specify up to 20 tags.

product_name

No

String

Definition

Cloud product name. It needs to be specified when you create an alarm rule for a cloud product. Generally, the value format is Service namespace,First-level dimension of the service, for example, SYS.ECS,instance_id.

Constraints

N/A

Range

0 to 128 characters.

Default Value

N/A

resource_level

No

String

Definition

Resource level of the alarm rule to create.

Constraints

N/A

Range

The value can be:

  • product: cloud product.

  • dimension: specific dimension.

Default Value

Specific dimension.

Table 4 Dimension

Parameter

Mandatory

Type

Description

name

Yes

String

Definition

Dimension name of a resource. For example, the dimension of an ECS is instance_id . For details about the dimension names of each resource, see their service documentation. You can navigate there from Services Interconnected with Cloud Eye.

Constraints

N/A

Range

The value must start with a letter and can only contain letters, digits, underscores (_), and hyphens (-). It can contain 1 to 32 characters.

Default Value

N/A

value

No

String

Definition

Resource dimension value, which is an instance ID, for example, 4270ff17-aba3-4138-89fa-820594c39755.

Constraints

N/A

Range

1 to 256 characters

Default Value

N/A

Table 5 AlarmRulePolicy

Parameter

Mandatory

Type

Description

metric_name

Yes

String

Definition

Metric name of a resource. For details about the metric names of each resource, see their service documentation. You can navigate there from Services Interconnected with Cloud Eye.

Constraints

N/A

Range

The value must start with a letter and can only contain letters, digits, underscores (_), and hyphens (-). It allows 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

period

Yes

Integer

Definition

Metric period, in seconds. For details about the original metric period for each cloud service, see Services Interconnected with Cloud Eye.
  • 0: The alarm is triggered immediately. This value applies only to event scenarios.

  • 1: original metric period. For example, if the original period of an RDS metric is 60s, the metric data is collected and calculated every 60s.

  • 300: The metric data is collected and calculated every 5 minutes.

  • 1200: The metric data is collected and calculated every 20 minutes.

  • 3600: The metric data is collected and calculated every hour.

  • 14400: The metric data is collected and calculated every 4 hours.

  • 86400: The metric data is collected and calculated every day.

Default Value

N/A

Constraints

N/A

Range

The value can be:

filter

Yes

String

Definition

Aggregation method.

Constraints

When period is set to 1 (original value), the filter field does not take effect. The default value of filter is average. The filter parameter takes effect only when period is greater than 1.

Range

  • average

  • variance

  • min: minimum value.

  • max: maximum value.

  • 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. For details, see Services Interconnected with Cloud Eye.

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

-1.7976931348623157e+108 to 1.7976931348623157e+108

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:

  1. The alarm type is Metric and the alarm policy is Trigger an alarm when all policies are met.

  2. The alarm type is Event.

unit

No

String

Definition

Data unit.

Constraints

N/A

Range

[0,32]

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

suppress_duration

No

Integer

Definition

Alarm suppression duration, in seconds. This parameter corresponds to the last field in the alarm policy when you create an alarm rule. This field is used to mitigate frequent alarm occurrences.

Constraints

N/A

Range

The value can be:

  • 0: An event alarm is not suppressed in the immediate triggering scenario, and is generated only once in the accumulated triggering scenario.

  • 300: An alarm is generated every 5 minutes once the alarm triggering condition is met.

  • 600: An alarm is generated every 10 minutes once the alarm triggering condition is met.

  • 900: An alarm is generated every 15 minutes once the alarm triggering condition is met.

  • 1800: An alarm is generated every 30 minutes once the alarm triggering condition is met.

  • 3600: An alarm is generated every 60 minutes once the alarm triggering condition is met.

  • 10800: An alarm is generated every 3 hours once the alarm triggering condition is met.

  • 21600: An alarm is generated every 6 hours once the alarm triggering condition is met.

  • 43200: An alarm is generated every 12 hours once the alarm triggering condition is met.

  • 86400: An alarm is generated once every day once the alarm triggering condition is met.

Default Value

N/A

level

No

Integer

Definition

Alarm severity.

Constraints

N/A

Range

The value can be:

  • 1: critical.

  • 2: major.

  • 3: minor.

  • 4: warning.

Default Value

2

namespace

No

String

Definition

namespace and dimension_name need to be specified for product-level rules to specify the resources to which the policy applies. For details about service namespaces, see Services Interconnected with Cloud Eye.

Constraints

N/A

Range

The value is in the service.item format. The values of service and item must start with a letter and contain only letters, digits, and underscores (_). The value can contain up to 32 characters.

Default Value

N/A

dimension_name

No

String

Definition

Dimension name of a resource. For details about the dimension names of each resource, see their service documentation. You can navigate there from Services Interconnected with Cloud Eye. namespace and dimension_name need to be specified for cloud product-level rules to specify the resources to which the policy applies.

Constraints

N/A

Range

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

Table 6 HierarchicalValue

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

Table 7 Notification

Parameter

Mandatory

Type

Description

type

Yes

String

Definition

Notification type.

Constraints

N/A

Range

The value can be:

  • notification: notification groups or topic subscriptions

  • contact: cloud account contacts

  • contactGroup: notification groups (deprecated)

  • autoscaling: AS notifications. This value is used only for AS.

  • groupwatch: deprecated

  • ecsRecovery: deprecated

  • iecAction: deprecated

Default Value

N/A

notification_list

Yes

Array of strings

Definition

Recipients to be notified of the alarm status changes. The value of topicUrn can be obtained from SMN. For details, see section "Querying Topics."

Constraints

If type is set to notification, the value of notification_list cannot be left blank. If type is set to autoscaling, the value of notification_list must be left blank. If notification_enabled is set to true, you must specify either alarm_notifications or ok_notifications or both. If both alarm_notifications and ok_notifications are specified, their notification_list values must be the same. You can specify up to 20 recipients.

Table 8 ResourceTag

Parameter

Mandatory

Type

Description

key

Yes

String

Definition

Tag name.

Constraints

N/A

Range

1 to 128 Unicode characters.

Default Value

N/A

value

Yes

String

Definition

Tag value.

Constraints

N/A

Range

0 to 255 Unicode characters.

Default Value

N/A

Response Parameters

Status code: 201

Table 9 Response body parameters

Parameter

Type

Description

alarm_id

String

Definition

Alarm rule ID. Example: al123232232341232132

Range

The value starts with al and is followed by 22 characters of letters, digits, or a combination of both. It contains 24 characters.

Status code: 400

Table 10 Response body parameters

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

Table 11 Response body parameters

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 an alarm rule whose name is alarm-lxy-rg-RDS, type is RESOURCE_GROUP, ** suppress_duration** is 86400, and level is 2.

{
  "name" : "alarm-lxy-rg-RDS",
  "description" : "",
  "namespace" : "SYS.RDS",
  "type" : "RESOURCE_GROUP",
  "resources" : [ [ {
    "name" : "rds_cluster_id"
  } ] ],
  "policies" : [ {
    "metric_name" : "rds001_cpu_util",
    "period" : 1,
    "filter" : "average",
    "comparison_operator" : ">=",
    "value" : 0,
    "unit" : "%",
    "count" : 1,
    "suppress_duration" : 86400,
    "level" : 2
  } ],
  "enabled" : true,
  "notification_enabled" : false,
  "resource_group_id" : "rg1623429506587NbRweoa3J",
  "enterprise_project_id" : "a9d919b7-0456-4bb8-b470-6a23b64f4f7e",
  "alarm_template_id" : "at1628592157541dB1klWgY6"
}

Example Responses

Status code: 201

Alarm rule created.

{
  "alarm_id" : "alCzk8o9dtSQHtiDgb44Eepw"
}

Status Codes

Status Code

Description

201

Alarm rule created.

400

Parameter verification failed.

500

Internal system error.

Error Codes

See Error Codes.