ApplyMetricRuleTemplate

Updated at:

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

Operation description

This topic provides an example to show 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

If the monitoring data continuously exceeds the threshold of the alert rule, the system will send only one alert notification within each epoch.

86400

GroupId

integer

Yes

The ID of the application group.

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

123456

TemplateIds

string

Yes

The ID of the alert template.

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

700****

EnableStartTime

integer

No

The start hour of the effective period for the alert. The value is a two-digit string, such as "00", "09", or "23". Valid values: 00 to 23, which represent 00:00 to 23:00. The default time zone is UTC+8.

00

EnableEndTime

integer

No

The end hour of the effective period for the alert. The value is a two-digit string, such as "00", "18", or "23". Valid values: 00 to 23. The value specifies the hour when the effective period ends, and the period actually ends at the 59th minute of the hour. For example, "23" indicates that the effective period ends at 23:59. The default time zone is UTC+8.

23

NotifyLevel

integer

No

The alert notification method. Valid values:

  • 2: phone call, text message, mailbox, TradeManager, and DingTalk chatbot.

  • 3: text message, mailbox, TradeManager, and DingTalk chatbot.

  • 4: TradeManager and DingTalk chatbot.

4

ApplyMode

string

No

The application mode of the template. Valid values:

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

  • ALARM_TEMPLATE_FIRST: alert template instances take precedence. 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 webhook URL to which an HTTP POST request is sent when an alert is triggered.

https://www.aliyun.com

AppendMode

string

No

The application policy of the template. Valid values:

  • all: deletes all rules created by using alert templates on the selected application groups, and then creates new alert rules based on the current template. This is the default value.

  • append: deletes the rules created by using the current alert template on the selected application groups, and then creates new alert rules based on the current template.

all

DryRun

boolean

No

Specifies whether to only precheck the request. Valid values:

  • true: sends a check request. No security groups are bound to instances. The check items include whether the required parameters are specified, the request format, and the service limits. If the check fails, the corresponding error is returned. If the check succeeds, the error code DryRunOperation is returned.

  • false (default): sends a normal request. If the check succeeds, the HTTP 2xx status code is returned and the operation is performed.

false

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

Response elements

Element

Type

Description

Example

object

Code

integer

The HTTP status code.

Note

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: The operation was successful.

  • false: The operation failed.

true

Resource

object

The resources affected by the alert rules.

GroupId

integer

The ID of the application group.

123456

AlertResults

array<object>

The detailed results of the generated alert rules.

object

The detailed results of the generated alert rules.

Code

string

The HTTP status code.

Note

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: The operation was successful.

  • false: The operation failed.

true

RuleName

string

The name of the alert rule.

test123

RuleId

string

The ID of the alert rule.

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.
412 DryRunOperation %s. dryRun Pre-Verification Results
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.