创建报警器
Headers
Authorization: OAuth the-session-uuidBody
{
"params": {
"name": "VM CPU Alarm",
"comparisonOperator": "LessThanOrEqualTo",
"period": 60.0,
"namespace": "ZStack/VM",
"metricName": "org.zstack.zwatch.datatype.Metric@53fa9b19",
"threshold": 60.0,
"repeatInterval": 1800.0,
"enableRecovery": true,
"labels": [
{
"key": "VMUuid",
"value": "ca6b4ad7a0e446c6a8c4f52d93215f6e",
"op": "Equal"
}
],
"actions": [
{
"actionUuid": "19b7cfaf6134408897d95588b01308fe",
"actionType": "sns"
}
],
"repeatCount": -1.0,
"type": "Any"
"enableRecovery": true
},
"systemTags": [],
"userTags": []
}上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"name":"VM CPU Alarm","comparisonOperator":"LessThanOrEqualTo","period":60.0,"namespace":"ZStack/VM","metricName":"org.zstack.zwatch.datatype.Metric@53fa9b19","threshold":60.0,"repeatInterval":1800.0,"labels":[{"key":"VMUuid","value":"61f6b705fcb944df8138ea6b52b0b4a6","op":"Equal"}],"actions":[{"actionUuid":"699541db497e4d3e9c49020c2dad8d6c","actionType":"sns"}],"repeatCount":-1.0,"type":"Any","enableRecovery":true}}' http://localhost:8080/zstack/v1/zwatch/alarms参数列表
名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
name | String | body(包含在params结构中) | 资源名称 |
| 2.3 |
description (可选) | String | body(包含在params结构中) | 资源的详细描述 |
| 2.3 |
comparisonOperator | String | body(包含在params结构中) | 阈值比较符 |
| 2.3 |
period(可选) | Integer | body(包含在params结构中) | 阈值持续时间 |
| 2.3 |
namespace | String | body(包含在params结构中) | 名字空间 |
| 2.3 |
metricName | String | body(包含在params结构中) | 监控项名 |
| 2.3 |
threshold | Double | body(包含在params结构中) | 阈值 |
| 2.3 |
repeatInterval (可选) | Integer | body(包含在params结构中) | 报警重复时间 |
| 2.3 |
labels (可选) | List | body(包含在params结构中) | 标签列表 |
| 2.3 |
actions (可选) | List | body(包含在params结构中) | 报警动作列表 |
| 2.3 |
resourceUuid (可选) | String | body(包含在params结构中) |
|
| 2.3 |
repeatCount (可选) | Integer | body(包含在params结构中) | 报警重复次数 |
| 3.3.0 |
type (可选) | String | body(包含在params结构中) | 报警器类型 |
| 3.3.0 |
systemTags (可选) | List | body | 系统标签 |
| 2.3 |
userTags (可选) | List | body | 用户标签 |
| 2.3 |
enableRecovery | Boolean | body(包含在params结构中) | 开启恢复通知 |
| 3.4.0 |
emergencyLevel (可选) | String | body(包含在params结构中) | 报警等级 |
| 3.8.0 |
API返回
返回示例
{
"inventory": {
"uuid": "6ff094db7e8b4640880751c5a17e7b63",
"name": "VM CPU Alarm",
"comparisonOperator": "LessThanOrEqualTo",
"period": 60.0,
"namespace": "ZStack/VM",
"metricName": "org.zstack.zwatch.datatype.Metric@c2e79f0",
"threshold": 30.0,
"repeatInterval": 1800.0,
"repeatCount": -1.0,
"status": "Alarm",
"state": "Enabled",
"enableRecovery": true,
"createDate": "Jul 6, 2018 1:51:02 PM",
"lastOpDate": "Jul 6, 2018 1:51:02 PM",
"labels": [
{
"uuid": "cccd980c3bb84f4486d96a960eb08edb",
"key": "VMUuid",
"operator": "=",
"value": "f486fd81583747459d8a6cd47f9228e5"
}
],
"actions": [
{
"alarmUuid": "8a6a98e3cc484388a746d725265886b3",
"actionType": "sns",
"actionUuid": "86a2b51fbc7f406c906711081852fa49"
}
]
}
}| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 2.3 |
| inventory | AlarmInventory | 详情参考inventory | 2.3 |
error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 2.3 |
| description | String | 错误的概要描述 | 2.3 |
| details | String | 错误的详细信息 | 2.3 |
| elaboration | String | 保留字段,默认为null | 2.3 |
| opaque | LinkedHashMap | 保留字段,默认为null | 2.3 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 2.3 |
inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 2.3 |
| name | String | 资源名称 | 2.3 |
| description | String | 资源的详细描述 | 2.3 |
| period | Integer | 阈值持续时间 | 2.3 |
| namespace | String | 名字空间 | 2.3 |
| metricName | String | 监控项名称 | 2.3 |
| threshold | Double | 阈值 | 2.3 |
| repeatInterval | Integer | 报警重复时间 | 2.3 |
| enableRecovery | Boolean | 开启恢复通知 | 3.4.0 |
| createDate | Timestamp | 创建时间 | 2.3 |
| lastOpDate | Timestamp | 最后一次修改时间 | 2.3 |
| comparisonOperator | ComparisonOperator | 详情参考comparisonOperator | 2.3 |
| status | AlarmStatus | 详情参考status | 2.3 |
| labels | List | 详情参考labels | 2.3 |
| actions | List | 详情参考actions | 2.3 |
comparisonOperator
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| name | String | 资源名称 | 2.3 |
| ordinal | int | 2.3 |
status
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| OK | AlarmStatus | 监控中 | 2.3 |
| Alarm | AlarmStatus | 已触发 | 2.3 |
| InsufficientData | AlarmStatus | 数据不足 | 2.3 |
labels
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 2.3 |
| key | String | 标签键 | 2.3 |
| operator | String | 比较符 | 2.3 |
| value | String | 标签值 | 2.3 |
actions
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| alarmUuid | String | 报警器UUID | 2.3 |
| actionType | String | 报警动作类型 | 2.3 |
| actionUuid | String | 报警动作UUID | 2.3 |
SDK示例
Java SDK
CreateAlarmAction action = new CreateAlarmAction();
action.name = "VM CPU Alarm";
action.comparisonOperator = "LessThanOrEqualTo";
action.period = 60.0;
action.namespace = "ZStack/VM";
action.metricName = "org.zstack.zwatch.datatype.Metric@c2e79f0";
action.threshold = 60.0;
action.repeatInterval = 1800.0;
action.labels = asList([key:VMUuid, value:45821a26f579447fa77bfb82b1b0268e, op:Equal]);
action.actions = asList([actionUuid:8e06ec09862c46c3aaf9fc6337815ffb, actionType:sns]);
action.repeatCount = -1.0;
action.type = "Any";
action.enableRecovery = true;
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
CreateAlarmAction.Result res = action.call();Python SDK
CreateAlarmAction action = CreateAlarmAction()
action.name = "VM CPU Alarm"
action.comparisonOperator = "LessThanOrEqualTo"
action.period = 60.0
action.namespace = "ZStack/VM"
action.metricName = "org.zstack.zwatch.datatype.Metric@c2e79f0"
action.threshold = 60.0
action.repeatInterval = 1800.0
action.labels = [[key:VMUuid, value:7dd44bfe750f42859528b27ef90f1412, op:Equal]]
action.actions = [[actionUuid:b1acb139666140d09f4f93b8dd96f49f, actionType:sns]]
action.repeatCount = -1.0
action.type = "Any"
action.enableRecovery = true
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
CreateAlarmAction.Result res = action.call()