All Documents
Current Document

Content is empty

If you don't find the content you expect, please try another search term

Documentation

CreateAlarmPolicy

Last updated:2026-03-18 14:12:49

CreateAlarmPolicy

Call the CreateAlarmPolicy API to configure an alarm policy under the specified account.


Description

Field

Value

API Name

CreateAlarmPolicy

Request Method

POST

Endpoint

monitor.api.ksyun.com

VPC Internal Endpoint

monitor.internal.api.ksyun.com

Version

2022-01-01


Request Parameters

All requests must include the Common Request Parameters. The table below lists only the API-specific parameters.

Parameter

Required

Type

Description

Action

Yes

String

Fixed value: CreateAlarmPolicy.

Version

Yes

String

Fixed value: 2022-01-01.

PolicyName

Yes

String

Name of the alarm policy.

ProductType

Yes

Integer

Cloud service category. See Cloud Service Categories for valid values.

PolicyType

Yes

Integer

Policy type.

  • 0: Standard policy.

  • 1: Default policy.

ResourceBindType

No

Integer

Resource binding type for the policy.

  • 1: All resources.

  • 2: By project group.

  • 3: Manually selected instances.

ProjectId

No

Integer

Project group ID. Required when ResourceBindType = 2.

InstanceIds

No

Array

List of instance IDs. Required when ResourceBindType = 3.

TriggerRules

Yes

Array of TriggerRuleObject

Rules that define when an alarm is triggered. See TriggerRule sub-table below.

UserNotice

No

Array of UserNoticeObject

Alarm notification recipients and delivery methods. See UserNotice sub-table below.

URLNotice

No

String[]

Webhook callback URLs for alarm notifications. Up to 5 URLs can be added.

TriggerRuleObject

Parameter

Required

Type

Description

Period

Yes

String

Statistical period in minutes. Examples: 1m (1 minute), 5m (5 minutes), 60m (1 hour).

Method

Yes

String

Statistical aggregation method. Supported values: avg, max, min, sum.

Compare

Yes

String

Comparison operator. Supported values: >, <, =.

TriggerValue

Yes

String

Threshold value that triggers the alarm.

ItemName

Yes

String

Display name of the monitoring metric. Example: CPU Utilization.

ItemKey

Yes

String

Identifier key of the monitoring metric. Example: cpu.utilizition.total.

Units

Yes

String

Unit of the monitoring metric. Example: %.

Points

Yes

Integer

Number of consecutive statistical periods that must breach the threshold before an alarm is triggered.

EffectBT

No

String

Start time of the policy's effective window. Format: HH:mm. Example: 12:00.

EffectET

No

String

End time of the policy's effective window. Format: HH:mm. Example: 23:00.

Interval

Yes

Integer

Interval between repeated alarm notifications, in minutes. Examples: 5, 10, 30.

MaxCount

Yes

Integer

Maximum number of alarm notifications to send. Valid range: 15.

UserNoticeObject

Parameter

Required

Type

Description

ContactWay

Yes

Integer

Alarm notification delivery method. 1: Email only. 2: SMS only. 3: Email and SMS.

ContactFlag

Yes

Integer

Type of alarm contact. 1: Contact group. 2: Individual contact.

ContactId

Yes

Integer

ID of the contact or contact group. See Get Contacts and Get Contact Groups for details.


Response Parameters

Field

Type

Description

requestId

String

Unique request ID.

data.policyId

Integer

The ID of the newly created alarm policy.


Request Examples

Example 1: Create an Alarm Policy for Specific Instances

Request

Replace ${region} with the appropriate region code. See: Region Reference. Replace ${CommonParams} with the appropriate common parameters. See: Common Parameters.

curl -X POST 'https://monitor.${region}.api.ksyun.com/?Action=CreateAlarmPolicy&Version=2022-01-01' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'host: monitor.api.ksyun.com' \
-H 'cache-control: no-cache' \
-H ${CommonParams} \
-d '{
  "PolicyName": "qa",
  "ProductType": 0,
  "PolicyType": 0,
  "ResourceBindType": 3,
  "InstanceIds": [
    "XXXX-XXXX-XXXXXXXXXXXXX01",
    "XXXX-XXXX-XXXXXXXXXXXXX02",
  ],
  "TriggerRules": [
    {
      "RuleId": 0,
      "ItemKey": "system.cpu.load",
      "ItemName": "CPU15分钟平均负载",
      "Method": "avg",
      "Period": "1m",
      "Compare": ">",
      "TriggerValue": "1",
      "Units": "",
      "DisplayUnits": "",
      "Points": 1,
      "EffectBT": "00:00",
      "EffectET": "23:59",
      "Interval": 5,
      "MaxCount": 5
    }
  ],
  "UserNotice": [
    {
      "ContactWay": 3,
      "ContactFlag": 2,
      "ContactId": 4423
    }
  ],
  "URLNotice": [
    "https://monitor.console.ksyun.com/callback/notify"
  ]
}'
Parameter Notes for This Example

Parameter

Value in Example

Explanation

PolicyName

qa

Policy name.

ProductType

0

Cloud service category code. See Cloud Service Categories.

PolicyType

0

Standard policy (non-default).

ResourceBindType

3

Manually selected instances — InstanceIds is required.

InstanceIds

Two instance UUIDs

The specific instances this policy applies to.

TriggerRules[0].ItemKey

system.cpu.load

Monitors the 15-minute average CPU load.

TriggerRules[0].Method

avg

Uses the average aggregation method.

TriggerRules[0].Period

1m

1-minute statistical period.

TriggerRules[0].Compare

>

Triggers when the metric value exceeds the threshold.

TriggerRules[0].TriggerValue

1

Alarm fires when the 15-minute avg CPU load exceeds 1.

TriggerRules[0].Points

1

Triggers after 1 consecutive breach period.

TriggerRules[0].EffectBT / EffectET

00:0023:59

Policy is active 24 hours a day.

TriggerRules[0].Interval

5

Repeat alarm notification every 5 minutes.

TriggerRules[0].MaxCount

5

Send a maximum of 5 alarm notifications.

UserNotice[0].ContactWay

3

Notify via both Email and SMS.

UserNotice[0].ContactFlag

2

Contact type is an individual contact.

UserNotice[0].ContactId

4423

ID of the individual contact to notify.

URLNotice[0]

Webhook URL

Alarm callback URL for webhook notification.

Successful Response

JSON Format

{
    "requestId": "af0f9264-dbd4-4b41-aef7-b9b40b36d1a0",
    "data": {
        "policyId": 26562
    }
}

XML Format

<RequestID>53df9d17-9bd6-4e3c-a9be-fda6ae02d4dd</RequestID>
<Data>
    <PolicyId>26565</PolicyId>
</Data>
Error Response

JSON Format

{
    "requestId": "af0f9264-dbd4-4b41-aef7-b9b40b36d1a0",
    "error": {
        "type": "sender",
        "code": "InvalidParameterValue",
        "message": "Invalid `ProductType` parameter value."
    }
}

Error Codes

The table below lists only the error codes specific to this API's business logic. For all other error codes, refer to Common Error Codes.


On this page
Pure ModeNormal Mode

Pure Mode

Click to preview the document content in full screen
Feedback