All Products
Search
Document Center

Cloud Monitor:ApplyMetricRuleTemplate

Last Updated:Jul 10, 2026

Applies an alert template to an application group to generate alert rules.

Operation description

This topic provides an example on how to apply the alert template 700**** to the application group 123456. The ID of the generated alert rule is applyTemplate8ab74c6b-9f27-47ab-8841-de01dc08****, and the name is test123.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

cms:ApplyMetricRuleTemplate

create

*MetricRuleTemplate

acs:cms::{#accountId}:group/{#groupId}

None None

Request parameters

Parameter

Type

Required

Description

Example

SilenceTime

integer

No

The mute for. Unit: seconds. Default value: 86400.

Note

When monitoring data continuously exceeds the alert rule threshold, only one alert notification is sent within each mute period.

86400

GroupId

integer

Yes

The ID of the application group.

For information about how to obtain the application group ID, see DescribeMonitorGroups.

123456

TemplateIds

string

Yes

The ID of the alert template.

For information about how to obtain the alert template ID, see DescribeMetricRuleTemplateList.

700****

EnableStartTime

integer

No

The start time of the alert effective period. Valid values: 00 to 23, which indicates 00:00 to 23:00.

00

EnableEndTime

integer

No

The end time of the alert effective period. Valid values: 00 to 23, which indicates 00:59 to 23:59.

23

NotifyLevel

integer

No

The alert notification method. Valid values:

4: TradeManager + DingTalk chatbot.

4

ApplyMode

string

No

The mode in which the alert template is applied. Valid values:

  • GROUP_INSTANCE_FIRST: application group instances take priority. When the alert template is applied, instances in the application group take priority. If an instance does not exist in the application group, the rule in the template is ignored.

  • ALARM_TEMPLATE_FIRST: alert template instances take priority. When the alert template is applied, alert rules are created regardless of whether the instances exist in the application group.

GROUP_INSTANCE_FIRST

Webhook

string

No

The callback URL to which a POST request is sent when an alert is triggered.

https://www.aliyun.com

AppendMode

string

No

The policy for applying the template. Valid values:

  • all: deletes all rules that were created from alert templates for the selected group, and then creates new alert rules based on the template (default value).

  • append: deletes the rules that were created from this alert template for the selected group, and then creates new alert rules based on the current template.

all

For more information about common request parameters, see Common parameters.

Response elements

Element

Type

Description

Example

object

Code

integer

The status code.

Note

The value 200 indicates success.

200

Message

string

The error message.

The specified resource is not found.

RequestId

string

The request ID.

3F897F3C-020A-4993-95B4-63ABB84F83E6

Success

boolean

Indicates whether the operation was successful. Valid values:

  • true: Successful.

  • false: Failed.

true

Resource

object

The resources affected by the alert rules.

GroupId

integer

The ID of the application group.

123456

AlertResults

array<object>

The details of the generated alert rules.

object

The details of the generated alert rules.

Code

string

The status code.

Note

A value of 200 indicates success.

200

Message

string

The returned message.

alert rule is creating, please wait a few minutes.

Success

boolean

Indicates whether the operation was successful. Valid values:

  • true: Successful.

  • false: Failed.

true

RuleName

string

The alert rule name.

test123

RuleId

string

The alert rule ID.

applyTemplate8ab74c6b-9f27-47ab-8841-de01dc08****

Examples

Success response

JSON format

{
  "Code": 200,
  "Message": "The specified resource is not found.",
  "RequestId": "3F897F3C-020A-4993-95B4-63ABB84F83E6",
  "Success": true,
  "Resource": {
    "GroupId": 123456,
    "AlertResults": [
      {
        "Code": "200",
        "Message": "alert rule is creating, please wait a few minutes.",
        "Success": true,
        "RuleName": "test123",
        "RuleId": "applyTemplate8ab74c6b-9f27-47ab-8841-de01dc08****"
      }
    ]
  }
}

Error codes

HTTP status code

Error code

Error message

Description

400 ParameterInvalid Illegal parameters.
500 InternalError The request processing has failed due to some unknown error.
403 AccessForbidden User not authorized to operate on the specified resource.
404 ResourceNotFound %s

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.