Files
doc-exports/docs/ces/api-ref/CreateAlarmTemplate.html
qiujiandong1 e9265fb6b0 CES API Update -20250521 version
Reviewed-by: Ziuzko, Alevtina <alevtina.ziuzko@t-systems.com>
Co-authored-by: qiujiandong1 <qiujiandong1@huawei.com>
Co-committed-by: qiujiandong1 <qiujiandong1@huawei.com>
2025-12-05 10:48:24 +00:00

58 KiB

Creating a Custom Alarm Template

Function

This API is used to create a custom alarm template.

URI

POST /v2/{project_id}/alarm-templates

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID.

For details about how to obtain the project ID, see Obtaining a Project ID.

Minimum: 1

Maximum: 64

Regular expression matching: ^[a-zA-Z0-9-]{1,64}$

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token. It is a response to the API for obtaining a user token. This API is the only one that does not require authentication. After a response is returned, the value of X-Subject-Token in the response header is the token.

Minimum: 1

Maximum: 16384

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

template_name

Yes

String

Alarm template name. It must start with a letter and can contain letters, digits, underscores (_), hyphens (-), parentheses, and periods (.). Fuzzy match is supported.

Minimum: 1

Maximum: 128

Regular expression matching:

^([\u4E00-\u9FFF]|[a-z]|[A-Z]|[0-9]|_|-|\(|\)|\.|\s)+$

template_type

No

Integer

Type of a custom alarm template.

The value can be:

  • 0: metric template

  • 2: event template

template_description

No

String

Supplementary information about an alarm template. The description can contain 0 to 256 characters and is left blank by default.

policies

Yes

Array of Policies objects

Alarm policies in an alarm template.

Array length: 1 to 50

Table 4 Policies

Parameter

Mandatory

Type

Description

namespace

Yes

String

Namespace.

Namespace of a service. For details about the namespace of each service, see Service Namespaces. The namespace must be in the service.item format and contain 3 to 32 characters. service and item must start with a letter and can contain only letters, digits, and underscores (_).

Minimum: 3

Maximum: 32

dimension_name

No

String

Resource dimension, which must start with a letter. A dimension allows a maximum of 32 characters can only contain digits, letters, underscores (_), and hyphens (-). If there are multiple dimensions, use commas (,) to separate them. DimensionName in event alarm templates must be left blank.

metric_name

Yes

String

Metric name of a resource. For details about the metrics of each service, see Service Metric Names. The value must start with a letter and can only contain digits, letters, 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.

Regular expression matching: ^([A-Za-z]){1}([0-9A-Za-z]|_|-)*$

period

Yes

Integer

Interval (seconds) for checking whether the alarm rule conditions are met.

0: default value. For example, this value can be used for event alarms.

1: original aggregation period of a metric. For example, if the original aggregation period of an RDS metric is 60s, its data point is calculated every 60 seconds. For details about the original aggregation period of each cloud service metric, see Services Interconnected with Cloud Eye.

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 1 hour.

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

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

The value can be:

  • 0

  • 1

  • 300

  • 1200

  • 3600

  • 14400

  • 86400

filter

Yes

String

Data aggregation method. The value can be:

  • average: average value of metric data within an aggregation period.
  • max: maximum value of metric data in an aggregation period.
  • min: minimum value of metric data within an aggregation period.
  • sum: sum of metric data within an aggregation period.
  • variance: variance value of metric data within an aggregation period.

comparison_operator

Yes

String

Operator of an alarm threshold.

Regular expression matching: ^(>|<|>=|<=|=|!=)$

value

No

Number

Alarm threshold.

Minimum: 0

Maximum: Number.MAX_VALUE (1.7976931348623156E108)

unit

No

String

Data unit. The value can contain a maximum of 32 characters. You can set this parameter based on your service needs.

Minimum: 0

Maximum: 32

count

Yes

Integer

Number of consecutive alarm triggering times. 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.

alarm_level

No

Integer

Alarm severity, which can be 1 (critical), 2 (major), 3 (minor), or 4 (warning). The default value is 2.

suppress_duration

Yes

Integer

Alarm suppression period, in seconds. When the period is 0, only one alarm is generated.

The value can be:

  • 0

  • 300

  • 600

  • 900

  • 1800

  • 3600

  • 10800

  • 21600

  • 43200

  • 86400

Response Parameters

Status code: 201

Table 5 Response body parameters

Parameter

Type

Description

template_id

String

ID of an alarm template. The ID starts with at and is followed by letters, digits, or a combination of both. The value can contain a maximum of 64 characters.

Status code: 400

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Status code customized by each cloud service when a request error occurs.

Minimum: 0

Maximum: 256

error_msg

String

Request error message.

Minimum: 0

Maximum: 256

request_id

String

Request ID.

Minimum: 0

Maximum: 256

Status code: 401

Table 7 Response body parameters

Parameter

Type

Description

error_code

String

Status code customized by each cloud service when a request error occurs.

Minimum: 0

Maximum: 256

error_msg

String

Request error message.

Minimum: 0

Maximum: 256

request_id

String

Request ID.

Minimum: 0

Maximum: 256

Status code: 403

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Status code customized by each cloud service when a request error occurs.

Minimum: 0

Maximum: 256

error_msg

String

Request error message.

Minimum: 0

Maximum: 256

request_id

String

Request ID.

Minimum: 0

Maximum: 256

Status code: 500

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Status code customized by each cloud service when a request error occurs.

Minimum: 0

Maximum: 256

error_msg

String

Request error message.

Minimum: 0

Maximum: 256

request_id

String

Request ID.

Minimum: 0

Maximum: 256

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
  } ],
 "template_type": 0
}

Creating an event template whose template_name is my_event_template, metric_name is rebootServer, count is 1, and alarm_level is 2

{
  "template_name" : "my_event_template",
  "template_description" : "hello world",
  "policies" : [ {
    "namespace" : "SYS.ECS",
    "dimension_name" : "",
    "metric_name" : "rebootServer",
    "period" : 0,
    "filter" : "average",
    "comparison_operator" : ">=",
    "value" : 1,
    "unit" : "count",
    "count" : 1,
    "alarm_level" : 2,
    "suppress_duration" : 0
  } ],
 "template_type": 2
}

Example Responses

Status code: 201

Created

{
  "template_id" : "at1628592157541dB1klWgY6"
}

Status Codes

Status Code

Description

201

Created

400

Parameter verification failed.

401

Authentication failed.

403

Authentication failed.

500

Failed to complete the request because of an internal server error.

Error Codes

See Error Codes.