Updated on 2023-05-06 GMT+08:00

Creating an Alarm Rule

Function

This API is used to create an alarm rule.

URI

POST /v2/{project_id}/alarms

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the tenant ID.

Minimum: 1

Maximum: 64

Regex Pattern: ^[a-zA-Z0-9-]{1,64}$

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

Content-Type

Yes

String

Specifies the MIME type of a request body. The default type is application/json; charset=UTF-8.

Default: application/json; charset=UTF-8

Minimum: 1

Maximum: 64

X-Auth-Token

Yes

String

Specifies the user token.

Minimum: 1

Maximum: 16384

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Specifies the name of an alarm rule. The name can contain 1 to 128 characters, including only letters, digits, underscores (_), and hyphens (-).

description

No

String

Provides supplementary information about the alarm rule. The description can contain 0 to 256 characters.

namespace

Yes

String

Specifies the namespace of a service. For details about the namespace of each service, see the Namespace column.

resource_group_id

No

String

Specifies the resource group ID. This parameter is mandatory when Monitoring Scope is set to Resource Groups.

resources

Yes

Array<Array<Dimension>>

Specifies the resource list. This parameter is mandatory when Monitored Scope is set to Specified Resources.

policies

Yes

Array of Policy objects

Alarm Policies

type

Yes

String

Specifies the alarm rule type.

Enumeration values:

  • EVENT.SYS

  • EVENT.CUSTOM

  • DNSHealthCheck

  • RESOURCE_GROUP

  • MULTI_INSTANCE

  • ALL_INSTANCE

alarm_notifications

No

Array of Notification objects

Specifies the action to be triggered by an alarm.

ok_notifications

No

Array of Notification objects

Specifies the action to be triggered after the alarm is cleared.

notification_begin_time

No

String

Specifies the time when alarm notifications are enabled.

notification_end_time

No

String

Specifies the time when alarm notifications are disabled.

enterprise_project_id

No

String

Specifies the enterprise project ID.

enabled

Yes

Boolean

Specifies whether an alarm rule is enabled.

notification_enabled

Yes

Boolean

Specifies whether to enable alarm notifications.

alarm_template_id

No

String

Specifies the ID of the alarm template associated with the alarm rule. If this parameter is specified, the policy associated with the alarm rule changes accordingly with the alarm template policy.

Table 4 Dimension

Parameter

Mandatory

Type

Description

name

Yes

String

Resource dimension. For example, the dimension of an ECS is instance_id. A maximum of four dimensions are supported. For the metric dimension of each resource, see Service metric dimension.

Regex Pattern: ^([a-z]|[A-Z]){1}([a-z]|[A-Z]|[0-9]|_|-){1,32}$

value

No

String

Specifies the value of a resource dimension, which is the resource instance ID, for example, 4270ff17-aba3-4138-89fa-820594c39755.

Regex Pattern: ^((([a-z]|[A-Z]|[0-9]){1}([a-z]|[A-Z]|[0-9]|_|-|\.)*)|\*){1,256}$

Table 5 Policy

Parameter

Mandatory

Type

Description

metric_name

Yes

String

Specifies the metric name of a resource. The name must start with a letter and contain only letter, digits, and underscores (_) . The length ranges from 1 to 64 characters. For example, cpu_util of an ECS indicates the CPU usage of the ECS. mongo001_command_ps in DDS indicates the command execution frequency. For details about the metric name of each service, see Service metric name.

period

Yes

Integer

Specifies the monitoring period of a metric, in seconds. The default value is 0. For example, for an event alarm, set this parameter to 0. 1 indicates the original monitoring period of the metric. For example, if the original period of an RDS metric is 60s, the RDS metric is calculated every 60 seconds as a data point. For details about the original period of each cloud service metric, see the Namespace column. 300 indicates that the metric is calculated every 5 minutes as a data point.

Minimum: 0

Maximum: 86400

Enumeration values:

  • 0

  • 1

  • 300

  • 1200

  • 3600

  • 14400

  • 86400

filter

Yes

String

Specifies the aggregation method. The value can be average, min, max, or sum.

comparison_operator

Yes

String

Specifies the threshold operator, which can be >, <, >=, <=, =, or ><.

value

Yes

Number

Specifies the threshold.

unit

No

String

Specifies the unit.

count

Yes

Integer

Specifies the number of counts that the threshold is met.

suppress_duration

No

Integer

Specifies the alarm suppression time, in seconds. This field corresponds to the last field of the alarm policy when an alarm rule is created on the Cloud Eye console. This field is used to avoid frequent alarms. 0 indicates that the alarm is not suppressed and an alarm is generated when the condition is met. 300 indicates that an alarm is generated every 5 minutes after the alarm triggering condition is met.

Minimum: 0

Maximum: 86400

Enumeration values:

  • 0

  • 300

  • 600

  • 900

  • 1800

  • 3600

  • 10800

  • 21600

  • 43200

  • 86400

level

No

Integer

Specifies the alarm severity, which can be: 1 (critical), 2 (major), 3 (minor) or 4 (informational).

Table 6 Notification

Parameter

Mandatory

Type

Description

type

Yes

String

Specifies the notification type. notification indicates that notifications are sent through Simple Message Notification (SMN).

Regex Pattern: ^(notification|autoscaling|ecsRecovery|contact|contactGroup|iecAction)$

notification_list

Yes

Array of strings

Specifies the list of objects to be notified if the alarm status changes. The value of topicUrn can be obtained from SMN. For details, see section "Querying Topics". When type is set to notification, notification_list cannot be left blank. Note: If alarm_action_enabled is set to true, alarm_actions, ok_actions, or both of them must be specified. If alarm_actions and ok_actions coexist, their notification_list values must be the same.

Response Parameters

Status code: 201

Table 7 Response body parameters

Parameter

Type

Description

alarm_id

String

Specifies the alarm rule ID, which starts with al and is followed by a 22-digit string consisting of letters and digits.

Status code: 400

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Specifies the status codes customized by each cloud service when a request error occurs.

Minimum: 0

Maximum: 256

error_msg

String

Specifies the request error message.

Minimum: 0

Maximum: 256

request_id

String

Specifies the request ID.

Minimum: 0

Maximum: 256

Status code: 500

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Specifies the status codes customized by each cloud service when a request error occurs.

Minimum: 0

Maximum: 256

error_msg

String

Specifies the request error message.

Minimum: 0

Maximum: 256

request_id

String

Specifies the request ID.

Minimum: 0

Maximum: 256

Example Requests

{
  "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

System error.

Error Codes

See Error Codes.