Create Alarm

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@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": []
}

In the above example, the systemTags and userTags fields can be omitted. They are listed to indicate that the body can contain these two fields.

Curl Example

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

Parameter List

Name

Type

Location

Description

Allowed Values

Starting Version

name

String

body (contained in the params structure)

The resource name.

 

2.3

description (Optional)

String

body (contained in the params structure)

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

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

Integer

body (contained in the params structure)

The alarm repeat interval.

 

2.3

labels (Optional)

List

body (contained in the params structure)

The label list.

 

2.3

actions (Optional)

List

body (contained in the params structure)

The alarm action list.

 

2.3

resourceUuid (Optional)

String

body (contained in the params structure)

 

 

2.3

repeatCount (Optional)

Integer

body (contained in the params structure)

The alarm repeat count.

 

3.3.0

type (Optional)

String

body (contained in the params structure)

The alarm type.

 

3.3.0

systemTags (Optional)

List

body

System tags.

 

2.3

userTags (Optional)

List

body

User tags.

 

2.3

enableRecovery

Boolean

body (contained in the params structure)

Whether to enable recovery notification.

 

3.4.0

emergencyLevel (Optional)

String

body (contained in the params structure)

The alarm level.

  • Emergent
  • Important
  • Normal

3.8.0

API Response

Response Example

{
  "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"
      }
    ]
  }
}
NameTypeDescriptionStarting Version
errorErrorCodeThe error code. If not null, the operation failed. This field is null when the operation succeeds. See error for details.2.3
inventoryAlarmInventorySee inventory for details.2.3

error

NameTypeDescriptionStarting Version
codeStringThe error code number. A globally unique identifier for the error, e.g., SYS.1000, HOST.1001.2.3
descriptionStringA brief description of the error.2.3
detailsStringThe detailed error information.2.3
elaborationStringA reserved field. Default is null.2.3
opaqueLinkedHashMapA reserved field. Default is null.2.3
causeErrorCodeThe root error. The source error that caused the current error. This field is null if there is no root cause.2.3

inventory

NameTypeDescriptionStarting Version
uuidStringThe UUID of the resource. Uniquely identifies the resource.2.3
nameStringThe resource name.2.3
descriptionStringThe detailed description of the resource.2.3
periodIntegerThe threshold duration.2.3
namespaceStringThe namespace.2.3
metricNameStringThe metric name.2.3
thresholdDoubleThe threshold.2.3
repeatIntervalIntegerThe alarm repeat interval.2.3
enableRecoveryBooleanWhether to enable recovery notification.3.4.0
createDateTimestampThe creation time.2.3
lastOpDateTimestampThe last modification time.2.3
comparisonOperatorComparisonOperatorSee comparisonOperator for details.2.3
statusAlarmStatusSee status for details.2.3
labelsListSee labels for details.2.3
actionsListSee actions for details.2.3

comparisonOperator

NameTypeDescriptionStarting Version
nameStringThe resource name.2.3
ordinalint 2.3

status

NameTypeDescriptionStarting Version
OKAlarmStatusMonitoring.2.3
AlarmAlarmStatusTriggered.2.3
InsufficientDataAlarmStatusInsufficient data.2.3

labels

NameTypeDescriptionStarting Version
uuidStringThe UUID of the resource. Uniquely identifies the resource.2.3
keyStringThe label key.2.3
operatorStringThe comparison operator.2.3
valueStringThe label value.2.3

actions

NameTypeDescriptionStarting Version
alarmUuidStringThe alarm UUID.2.3
actionTypeStringThe alarm action type.2.3
actionUuidStringThe alarm action UUID.2.3

SDK Examples

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