CreateAlarm

API Request

URLs
POST zstack/v1/zwatch/alarms
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "name": "VM CPU Alarm",
    "comparisonOperator": "LessThanOrEqualTo",
    "period": 60.0,
    "namespace": "ZStack/VM",
    "metricName": "org.zstack.zwatch.datatype.Metric@c2e79f0",
    "threshold": 60.0,
    "repeatInterval": 1800.0,
    "enableRecovery": true,
    "labels": [
      {
        "key": "VMUuid",
        "value": "c38c7d80b66b4db0a607f80c9e8676a0",
        "op": "Equal"
      }
    ],
    "actions": [
      {
        "actionUuid": "0d0f8958cdb04b1294fb04169c06a096",
        "actionType": "sns"
      }
    ],
    "repeatCount": -1.0,
    "type": "Any"
  },
  "systemTags": [],
  "userTags": []
}
Note: In the preceding sample, both systemTags and userTags are optional. These two fields can be included in the body structure.
Curl Sample
curl -H "Content-Type: application/json;charset=UTF-8" \
-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@565e1ebe","threshold":60.0,"repeatInterval":1800.0,"enableRecovery":true,"labels":[{"key":"VMUuid","value":"85b0dc413b5040d18d6726f6ae515c42","op":"Equal"}],"actions":[{"actionUuid":"eb00cb48ff0148cbb5358cad4f6f94a0","actionType":"sns"}]"repeatCount":-1.0,"type":"Any"}}' http://localhost:8080/zstack/v1/zwatch/alarms
Request Parameters
Name Type Location Description Optional Value Starting Version
name String body (contained in the params structure) The resource name. 2.3
description String body (contained in the params structure) Optional. The detailed description of the resource. 2.3
comparisonOperator String body (contained in the params structure) The threshold comparison operator.
  • GreaterThanOrEqualTo
  • GreaterThan
  • LessThan
  • LessThanOrEqualTo
2.3
period Integer body (contained in the params structure) The threshold duration. 2.3
namespace String body (contained in the params structure) The namespace. 2.3
metricName String body (contained in the params structure) The metric name. 2.3
threshold Double body (contained in the params structure) The threshold. 2.3
repeatInterval Integer body (contained in the params structure) Optional. The alarm repeat interval. 2.3
labels List body (contained in the params structure) Optional. The label list. 2.3
actions List body (contained in the params structure) Optional. The alarm action list. 2.3
resourceUuid String body (contained in the params structure) Optional. 2.3
repeatCount Integer body (contained in the params structure) Optional. The alarm repeat count. 3.3.0
type String body (contained in the params structure) Optional. The alarm type. 3.3.0
systemTags List body Optional. The system tags. 2.3
userTags List body Optional. The user tags. 2.3
enableRecovery Boolean body (contained in the params structure) Whether to enable the recovery notification. 3.4.0
emergencyLevel String body (contained in the params structure) Optional. The alarm emergency level.
  • Emergent
  • Important
  • Normal
3.8.0

API Response

Sample Response
{
  "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": "\u003d",
        "value": "f486fd81583747459d8a6cd47f9228e5"
      }
    ],
    "actions": [
      {
        "alarmUuid": "8a6a98e3cc484388a746d725265886b3",
        "actionType": "sns",
        "actionUuid": "86a2b51fbc7f406c906711081852fa49"
      }
    ]
  }
}
Name Type Description Starting Version
error ErrorCode The error code. If not null, the operation fails, or vice versa. For more information, see error. 2.3
inventory AlarmInventory See inventory. 2.3
#error
Name Type Description Starting Version
code String The error code, which is a numbered or alphanumeric code that specifies an error. For example, SYS.1000, HOST.1001. 2.3
description String The brief description of the error. 2.3
details String The details about the error. 2.3
elaboration String The reserved field. Default value: null. 2.3
opaque LinkedHashMap The reserved field. Default value: null. 2.3
cause ErrorCode The root error, which is the associated root cause of the current error. If no root error exists, this parameter is null. 2.3
#inventory
Name Type Description Starting Version
uuid String The resource UUID. 2.3
name String Th resource name. 2.3
description String The detailed description of the resource. 2.3
period Integer The threshold duration. 2.3
namespace String The namespace. 2.3
metricName String The metric name. 2.3
threshold Double The threshold. 2.3
repeatInterval Integer The alarm repeat interval. 2.3
enableRecovery Boolean Whether to enable the recovery notification. 3.4.0
createDate Timestamp The creation date. 2.3
lastOpDate Timestamp The last operation date. 2.3
comparisonOperator ComparisonOperator See comparisonOperator. 2.3
status AlarmStatus See status. 2.3
labels List See labels. 2.3
actions List See actions. 2.3
#comparisonOperator
Name Type Description Starting Version
name String The resource name. 2.3
ordinal int 2.3
#status
Name Type Description Starting Version
OK AlarmStatus The alarm is in normal status. 2.3
Alarm AlarmStatus The alarm is triggered. 2.3
InsufficientData AlarmStatus The data is insufficient. 2.3
#labels
Name Type Description Starting Version
uuid String The resource UUID. 2.3
key String The label key. 2.3
operator String The comparison operator. 2.3
value String The label value. 2.3
#actions
Name Type Description Starting Version
alarmUuid String The alarm UUID. 2.3
actionType String The action type. 2.3
actionUuid String The action UUID. 2.3

SDK Sample

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()