createLogAlarm
Updated at:2025-11-03
Description
To create alert tasks for specific logstores, the following guidelines shall be complied with:
- More than one alert task can be created for each logstore
- The query statement does not support pure search statements
match ..., but can support query statementsselect ...and query statements with search conditionsmatch ...| select ... - When using query statements with search conditions in alert tasks, index is not required to be enabled
- Pushing metrics requires selecting a field from the query statement results. The field name for pushing can be adjusted using aliases in the query statement
- Different alert tasks need to be bound to metrics with different names
Request
- Request syntax
Http
1POST /v1/alarm HTTP/1.1
2Host: bls-log.{region}.baidubce.com
3Authorization: authorization string
- Request headers
No additional headers are required beyond the standard request headers.
- Request parameters
| Parameter name | Types | Required or not | Parameter location | Description |
|---|---|---|---|---|
| alarmName | String | yes | body | Alert task name, at most 80 characters, including letters, digits, - and _ |
| project | String | no | body | Project name, default |
| logStoreName | String | yes | body | Logstore name |
| alarmConfig | AlarmConfig | yes | body | Alert task configuration |
AlarmConfig structure:
| Parameter name | Types | Required or not | Parameter location | Description |
|---|---|---|---|---|
| alarmQuery | String | yes | body | Query statement |
| alarmTimeRange | Int | yes | body | Query time range, unit: minute, range: 1-1440 |
| frequency | Int | yes | body | Metric pushing period, unit: minute, range: 1-1440; it is recommended to be the same as the query statement time range |
| metric | Metric | yes | body | Push metric information |
Metric structure:
| Parameter name | Types | Required or not | Parameter location | Description |
|---|---|---|---|---|
| metricName | String | yes | body | Push metric name, 3-50 characters, including letters, digits, - and _ |
| dimensions | LIST[Dimension] | no | body | Dimension Information |
Dimension structure:
| Parameter name | Types | Required or not | Parameter location | Description |
|---|---|---|---|---|
| name | String | yes | body | Dimension name, consisting of 50 characters at most, including letters, digits, hyphens and underscores |
Response
- Response headers
No additional headers are required beyond the standard response headers.
- Response parameters
| Parameter name | Types | Description |
|---|---|---|
| alarmID | String | Alert task ID |
Error code
Apart from standard error codes, the following codes may be returned:
| Error code | Error message | Description | HTTP status code |
|---|---|---|---|
| LogStoreNotFound | LogStore [logStoreName] not exists | Logstore not exist | 404 |
| Invalid request parameter | [Metric] composed of English letters, digits, hyphens and underscores, length: 3-50 | Metric name inconsistent with regulations | 400 |
Note: [logStoreName] in error message may be replaced with a specific name.
Example
- Request example
Http
1POST /v1/alarm 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 "alarmName": "alarm1",
7 "project": "default",
8 "logStoreName": "storeAlarm",
9 "alarmConfig": {
10 "alarmQuery": "select count(error) as errCount, error group by error",
11 "alarmTimeRange": 10,
12 "frequency": 10,
13 "metric": {
14 "metricName": "errCount",
15 "dimensions": [
16 {
17 "name": "error"
18 }
19 ]
20 }
21 }
22}
- Response example
Http
1HTTP/1.1 201
2Content-Type: application/json; charset=utf-8
3{
4 "alarmID":"alarm-xxxxxxx"
5}
