CreateAlarmPolicy
Updated at:2025-11-03
Description
Create an alarm policy to send alarm notification when alarm conditions are satisfied.
Request
- Request syntax
Text
1POST /v1/alarm/policy HTTP/1.1
2Host: <Endpoint>
3Authorization: <Authorization String>
4Content-Type: application/json; charset=utf-8
5{
6 "name": <PolicyName>,
7}
- Request headers
No additional headers are required beyond the standard request headers.
- Request parameters
| Parameter name | Types | Required or not | Parameter location | Description |
|---|---|---|---|---|
| name | String | Yes | RequestBody | Alarm policy name, unique |
| objects | List<LogStore> | No | RequestBody | List of monitor objects. Fill in this field when all logstores share the target logstore. |
| targets | List<Target> | Yes | RequestBody | List of execution statements |
| triggerConditions | List<TriggerCondition> | Yes | RequestBody | List of trigger conditions |
| groups | List<String> | No | RequestBody | Group trigger |
| schedule | Schedule | Yes | RequestBody | Execution cycle |
| pendingCount | Int | Yes | RequestBody | Continuous trigger threshold, number of consecutive times the threshold is triggered before an alarm is raised |
| repeatIntervalMinute | Int | No | RequestBody | Repeat alarm interval, unit: minutes, default value: 0, which means repeat alarm is disabled |
| recoverWithoutNotice | Bool | No | RequestBody | Whether to notify after recovery, true: no notification, false: notification, defaulting to false |
| state | String | No | RequestBody | Policy activation status. ENABLED: Enabled; DISABLED: Disabled |
| noticeState | String | No | RequestBody | Notification activation status, ENABLED: Enabled; DISABLED: Disabled |
| notices | List<Notice> | Yes | RequestBody | Alarm notification template, reference: BCM Notification Template API |
| noticeRawLogs | List<NoticeRawLog> | No | RequestBody | Whether to include original logs in alarm notifications |
Each LogStore element structure in the objects array is as follows:
| Parameter name | Types | Required or not | Description |
|---|---|---|---|
| project | String | No | Logstore project, defaulting to "default" |
| logStoreName | String | Yes | Logstore name |
The element structure of each target in targets array is as follows:
| Parameter name | Types | Required or not | Description |
|---|---|---|---|
| query | String | Yes | Execution statement |
| startTimeOffsetMinute | Int | Yes | Query start time offset, value range: [-1440, 0) |
| endTimeOffsetMinute | Int | Yes | Value range: (startTimeOffsetMinute, 0] |
| object | LogStore | No | Fill in this field when each execution statement specifies a logstore individually |
Each TriggerCondition element structure in the triggerConditions array is as follows:
| Parameter name | Types | Required or not | Description |
|---|---|---|---|
| level | String | Yes | Alarm level, required. Options: INFO, WARN, and CRITICAL |
| condition | String | Yes | Trigger condition expression |
Schedule element structure is as follows:
| Parameter name | Types | Required or not | Description |
|---|---|---|---|
| intervalMinute | Int | No | Fixed interval, unit: minutes, value range [1, 1440] |
| fixTimeMinute | Int | No | Specified time, minutes of the day, value range [0, 1440) |
| dayOfWeek | Int | No | Fixed time frequency; 0: Daily. 1~7 represents Monday to Sunday in a week |
Notice element structure is as follows:
| Parameter name | Types | Required or not | Description |
|---|---|---|---|
| id | String | Yes | BCM alarm template ID |
The element structure of NoticeRawLog is as follows:
| Parameter name | Types | Required or not | Description |
|---|---|---|---|
| type | String | Yes | Configuration type, REF: Associated execution statement, CUSTOM: Custom search statement |
| refTarget | String | No | If type=REF, it represents the referenced execution statement sequence number, counting from 0 |
| customTarget | Target | No | If type=CUSTOM, fill in the custom execution statement |
| columns | List<String> | No | List of field names displayed in the original logs. If not filled, all fields will be displayed |
| limit | Int | Yes | Number of logs displayed, maximum: 5 |
Response
- Response headers
No additional headers are required beyond the standard response headers.
- Response parameters
| Field | Types | Description |
|---|---|---|
| success | Boolean | Whether the request succeeded |
| code | String | Request code, OK for success, or a specific error code for failure |
| message | String | Empty for request success, or a specific error message for request failure |
Error code
Apart from standard error codes, the following codes may be returned:
| Error code | Error message | Description | HTTP status code |
|---|---|---|---|
| InvalidParameter | Request param invalid: [msg] | Invalid parameter exception | 400 |
Example
- Request example
Text
1POST /v1/alarm/policy HTTP/1.1
2Host: bls-log.bj.baidubce.com
3Authorization:bce-auth-v1/18717522d39411e9b721df098b0b908c/2019-09-10T07:00:20Z/1800/content-type;host;x-bce-date;x-bce-request-id/6a7cb6c9ac7ec156c805e55e7d0bcfc443b47feee97cf099c1c0d93a0b4c8304
4Content-Type: application/json; charset=utf-8
5{
6 // Alarm policy name, unique under the same user, required
7 "name": "policy-name",
8
9 // List of monitor objects, optional. When all logstores share the target logstore, fill in this field
10 "objects": [
11 {
12 "project": "default", // Logstore project, default
13 "logStoreName": "test-logstore-52" // Logstore name
14 },
15 ],
16
17 // List of execution statements, required
18 "targets": [
19 {
20 // Execution statement, required
21 "query": "select sum(age) as age",
22 // Query start time offset, required, value range: [-1440, 0)
23 "startTimeOffsetMinute": -1440,
24 // Query end time offset, required, value range: (startTimeOffsetMinute, 0]
25 "endTimeOffsetMinute": 0,
26
27 // Target logstore, optional. When each execution statement specifies a logstore separately, fill in this field
28 "object": {
29 "logStoreName": "test-logstore-52" // Logstore name
30 }
31 }
32 ],
33
34 // List of trigger conditions, required
35 "triggerConditions": [
36 {
37 // Alarm level, required, options:
38 // INFO - Notification,
39 // WARN - Warning
40 // CRITICAL - Critical
41 "level": "WARN",
42
43 // Trigger condition expression, required
44 "condition": "$1.age > 1"
45 }
46 ],
47
48 // Group trigger, optional
49 "groups": ["$1.age", "$1.salary"],
50
51 // Execution cycle, required. Either fixed interval or specified time must be set, but not both
52 "schedule": {
53 // Fixed interval, unit: minutes, value range [1, 1440]
54 "intervalMinute": 1,
55
56 // Specified time, minutes of the day, value range [0, 1440)
57 "fixTimeMinute": 120, // In the example, 120 represents the 120th minute of the day, i.e., 2:00 AM
58 // Fixed time frequency; 0: Daily 1~7 represents a specific day in a week
59 "dayOfWeek": 0
60 },
61
62 // Continuous trigger threshold, number of consecutive times the threshold is triggered before an alarm is raised, required
63 "pendingCount": 1,
64
65 // Repeat alarm interval, unit: minutes, default value: 0, which means repeat alarm is disabled
66 "repeatIntervalMinute": 5,
67
68 // Whether to notify after recovery, true: no notification, false: notification, default
69 "recoverWithoutNotice": true,
70
71 // Policy activation status, options:
72 // ENABLED - Enabled
73 // DISABLED - Disabled
74 "state": "ENABLED",
75
76 // Notification activation status, options:
77 // ENABLED - Enabled
78 // DISABLED - Disabled
79 "noticeState": "ENABLED",
80
81 // Alarm notification template list, required
82 "notices": [
83 {
84 // BCM alarm template ID, required
85 "id": "testNotice"
86 }
87 ],
88
89 // Whether to include original logs in alarm notifications, optional
90 "noticeRawLogs" : [
91 {
92 // Configuration type, required
93 // REF - Associated execution statement
94 // CUSTOM - Custom search statement
95 "type" : "CUSTOM",
96
97 // If type=REF, required, indicating the referenced execution statement sequence number, counting from 0
98 "refTarget" : 1,
99
100 // If type=CUSTOM, fill in the custom execution statement
101 "customTarget": {
102 // Execution statement, required
103 "query": "select sum(age) as age",
104 // Query start time offset, required, value range: [-1440, 0)
105 "startTimeOffsetMinute": -1440,
106 // Query end time offset, required, value range: (startTimeOffsetMinute, 0]
107 "endTimeOffsetMinute": 0,
108
109 // Target logstore, optional. When each execution statement specifies a logstore separately, fill in this field
110 "object": {
111 "logStoreName": "test-logstore-52" // Logstore name
112 }
113 }
114
115 // List of field names displayed in the original logs, optional. If not filled, all fields will be displayed.
116 "columns": ["requestid", "status"],
117
118 // Number of logs displayed, maximum: 5, required
119 "limit" : 4,
120 }
121 ]
122}
- Response example
Text
1HTTP/1.1 201
2Content-Type: application/json; charset=utf-8
3X-Bce-Request-Id: 2eeba101-4cc7-4cfe-b5ac-a3be8d060e33
4Date: Fri, 10 Apr 2020 04:42:37 GMT
5{
6 "success": true,
7 "code": "OK",
8 "message": ""
9}
