Event Subscription

SubscribeEvent

API Request

URLs
POST zstack/v1/zwatch/events/subscriptions
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "namespace": "ZStack/VM",
    "eventName": "VMUuid",
    "actions": [
      {
        "actionUuid": "2fbeae18082445d09c890fa076ff9fd9",
        "actionType": "sns"
      }
    ],
    "labels": [
      {
        "key": "VMUuid",
        "value": "0c60949d81964f23a0d860b30472c51b",
        "op": "Equal"
      }
    ]
  },
  "systemTags": [],
  "userTags": []
}
Note: In the above example, the systemTags and userTags fields can be omitted. They are listed here to indicate that the body can contain these two fields.
Curl Example
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"namespace":"ZStack/VM","eventName":"VMUuid","actions":[{"actionUuid":"c7b1b7e054494aeab843a9c7371cdfc4","actionType":"sns"}],"labels":[{"key":"VMUuid","value":"47056270f2ea45409a419f1165f83945","op":"Equal"}]}}' \
http://localhost:8080/zstack/v1/zwatch/events/subscriptions
Parameter List
Name Type Location Description Allowed Values Starting Version
namespace String body (contained in the params structure) Namespace. 2.3
eventName String body (contained in the params structure) Event name. 2.3
actions (Optional) List body (contained in the params structure) Event actions. 2.3
labels (Optional) List body (contained in the params structure) Event labels. 2.3
resourceUuid (Optional) String body (contained in the params structure) Optional. The resource UUID. 2.3
systemTags (Optional) List body System tags. 2.3
userTags (Optional) List body User tags. 2.3
name (Optional) String body (contained in the params structure) Resource name. 3.0.0
emergencyLevel (Optional) String body (contained in the params structure) Alarm level.
  • Emergent
  • Important
  • Normal
3.8.0
tagUuids (Optional) List body (contained in the params structure) List of tag UUIDs. 3.8.0

API Response

On success, this API returns an empty JSON structure {}. On failure, the returned JSON structure contains an error field. For example:
{
"error": {
    "code": "SYS.1001",
    "description": "A message or a operation timeout",
    "details": "Create VM on KVM timeout after 300s"
}
}

SDK Examples

Java SDK
SubscribeEventAction action = new SubscribeEventAction();
action.namespace = "ZStack/VM";
action.eventName = "VMUuid";
action.actions = asList([actionUuid:08a502ad6e944ceb8c70f523b69385e3, actionType:sns]);
action.labels = asList([key:VMUuid, value:896391b873dc41288c0841b5fe8cb71b, op:Equal]);
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
SubscribeEventAction.Result res = action.call();
Python SDK
SubscribeEventAction action = SubscribeEventAction()
action.namespace = "ZStack/VM"
action.eventName = "VMUuid"
action.actions = [[actionUuid:393df28f2bab49aba01fc229dae849c8, actionType:sns]]
action.labels = [[key:VMUuid, value:abd2e73d08d248b6be73e31eb6a97e82, op:Equal]]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
SubscribeEventAction.Result res = action.call()

UnsubscribeEvent

API Request

URLs
DELETE zstack/v1/zwatch/events/subscriptions/{uuid}
Headers
Authorization: OAuth the-session-uuid
Curl Example
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X DELETE http://localhost:8080/zstack/v1/zwatch/events/subscriptions/298e2e2506163851a268907ed8ea7995
Parameter List
Name Type Location Description Allowed Values Starting Version
uuid String url The UUID of the resource. Uniquely identifies the resource 2.3
deleteMode (Optional) String body Optional. The delete mode. 2.3
systemTags (Optional) List body System tags 2.3
userTags (Optional) List body User tags 2.3

API Response

This API returns an empty JSON structure {} on success. On failure, the returned JSON structure contains an error field. For example:
{
"error": {
    "code": "SYS.1001",
    "description": "A message or a operation timeout",
    "details": "Create VM on KVM timeout after 300s"
}
}

SDK Examples

Java SDK
UnsubscribeEventAction action = new UnsubscribeEventAction();
action.uuid = "298e2e2506163851a268907ed8ea7995";
action.deleteMode = "Permissive";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
UnsubscribeEventAction.Result res = action.call();
Python SDK
UnsubscribeEventAction action = UnsubscribeEventAction()
action.uuid = "298e2e2506163851a268907ed8ea7995"
action.deleteMode = "Permissive"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
UnsubscribeEventAction.Result res = action.call()

QueryEventSubscription

API Request

URLs
GET zstack/v1/zwatch/events/subscriptions
GET zstack/v1/zwatch/events/subscriptions/{uuid}
Headers
Authorization: OAuth the-session-uuid
Curl Example
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/zwatch/events/subscriptions?q=name=test
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X GET http://localhost:8080/zstack/v1/zwatch/events/subscriptions/57618e9763ce3b7e990870c3a7ae8c53

Queryable Fields

Run the CLI command line tool, enter QueryEventSubscription and press Tab to view all queryable fields and the resource names available for cross-table queries.

API Response

Response Example
{
  "inventories": [
    {
      "uuid": "9404fe697a6b4d7dbac98065af20dc57",
      "namespace": "ZStack/VM",
      "eventName": "org.zstack.zwatch.datatype.EventFamily@80723ca",
      "state": "Enabled",
      "actions": [
        {
          "subscriptionUuid": "650cf6a269284671a42f93631c87dfec",
          "actionType": "sns",
          "actionUuid": "fe296dcbc31c4afa9f76494b1930c8cc"
        }
      ],
      "labels": [
        {
          "uuid": "d29fe54ca47540a9b20b308429f21434",
          "key": "DestinationHostUuid",
          "operator": "Equal",
          "value": "733509c8c5684c678ffe99f59d4aba21"
        }
      ],
      "lastOpDate": "Jul 6, 2018 1:51:00 PM",
      "createDate": "Jul 6, 2018 1:51:00 PM"
    }
  ]
}
Name Type Description Starting Version
error ErrorCode The error code. If not null, the operation failed. This field is null on success. See error 2.3.1
inventories List See inventories 2.3.1
#error
Name Type Description Starting Version
code String The error code number. A globally unique identifier for the error, such as SYS.1000, HOST.1001 2.3.1
description String A brief description of the error 2.3.1
details String The detailed error information 2.3.1
elaboration String Reserved field. Default is null 2.3.1
opaque LinkedHashMap Reserved field. Default is null 2.3.1
cause ErrorCode The root error. The source error that caused the current error. This field is null if there is no root error 2.3.1
#inventories
Name Type Description Starting Version
uuid String The UUID of the resource. Uniquely identifies the resource 2.3.1
name String The resource name 3.0.0
namespace String The namespace 2.3.1
eventName String The event name 2.3.1
lastOpDate Timestamp The last modification time 2.3.1
createDate Timestamp The creation time 2.3.1
state EventSubscriptionState See state 2.3.1
actions List See actions 2.3.1
labels List See labels 2.3.1
#state
Name Type Description Starting Version
name String The resource name 2.3.1
ordinal int The ordinal number. 2.3.1
#actions
Name Type Description Starting Version
subscriptionUuid String The event subscription UUID 2.3.1
actionType String The action type 2.3.1
actionUuid String The action UUID 2.3.1
#labels
Name Type Description Starting Version
uuid String The UUID of the resource. Uniquely identifies the resource 2.3.1
key String The label name 2.3.1
value String The label value 2.3.1
operator Operator See operator 2.3.1
#operator
Name Type Description Starting Version
op String The op. 2.3.1
name String The resource name 2.3.1
ordinal int The ordinal number. 2.3.1

SDK Examples

Java SDK
QueryEventSubscriptionAction action = new QueryEventSubscriptionAction();
action.conditions = asList("name=test");
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
QueryEventSubscriptionAction.Result res = action.call();
Python SDK
QueryEventSubscriptionAction action = QueryEventSubscriptionAction()
action.conditions = ["name=test"]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
QueryEventSubscriptionAction.Result res = action.call()

UpdateEventSubscriptionLabel

API Request

URLs
PUT zstack/v1/zwatch/events/subscriptions/labels/{uuid}/actions
Headers
Authorization: OAuth the-session-uuid
Body
{
  "updateEventSubscriptionLabel": {
    "key": "VMUuid",
    "value": "42c233c17c6e4907b7be1f11a41f3a17",
    "operator": "Equal"
  },
  "systemTags": [],
  "userTags": []
}
Note: In the above example, the systemTags and userTags fields are optional. They are listed to indicate that the body can contain these two fields.
Curl Example
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"updateEventSubscriptionLabel":{"key":"VMUuid","value":"228fc2c5041248df9b0d317f6f7a8585","operator":"Equal"}}' http://localhost:8080/zstack/v1/zwatch/events/subscriptions/labels/cfb859d412933a1da57ae99e2aa442ce/actions
Parameter List
Name Type Location Description Allowed Values Starting Version
uuid String url The UUID of the original event subscription label. Uniquely identifies the resource 3.9.0
key String body (contained in the updateEventSubscriptionLabel structure) The new name of the label 3.9.0
value String body (contained in the updateEventSubscriptionLabel structure) The new value of the label 3.9.0
operator String body (contained in the updateEventSubscriptionLabel structure) The new operator of the label
  • Regex
  • Equal
3.9.0
systemTags (Optional) List body Optional. The system tags. 3.9.0
userTags (Optional) List body Optional. The user tags. 3.9.0

API Response

Response Example
{
  "inventory": {
    "uuid": "d937a1c6d9de3f2285b0cb23316624a8",
    "key": "VMUuid",
    "operator": "Equal",
    "value": "19cf33283b484ff6b73a6d98e1d762f5"
  }
}
Name Type Description Starting Version
error ErrorCode The error code. If not null, the operation failed. This field is null on success. See error 3.9.0
inventory EventSubscriptionLabelInventory See inventory 3.9.0
#error
Name Type Description Starting Version
code String The error code number. A globally unique identifier for the error, such as SYS.1000, HOST.1001 3.9.0
description String A brief description of the error 3.9.0
details String The detailed error information 3.9.0
elaboration String Reserved field. Default is null 3.9.0
opaque LinkedHashMap Reserved field. Default is null 3.9.0
cause ErrorCode The root error. The source error that caused the current error. This field is null if there is no root error 3.9.0
#inventory
Name Type Description Starting Version
uuid String The UUID of the resource. Uniquely identifies the resource 3.9.0
key String The label name 3.9.0
value String The label value 3.9.0
operator Operator See operator 3.9.0
#operator
Name Type Description Starting Version
op String The op. 3.9.0
name String The resource name 3.9.0
ordinal int The ordinal number. 3.9.0

SDK Examples

Java SDK
UpdateEventSubscriptionLabelAction action = new UpdateEventSubscriptionLabelAction();
action.uuid = "cfb859d412933a1da57ae99e2aa442ce";
action.key = "VMUuid";
action.value = "9d7099dd361049aaaf801ca6b17b2858";
action.operator = "Equal";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
UpdateEventSubscriptionLabelAction.Result res = action.call();
Python SDK
UpdateEventSubscriptionLabelAction action = UpdateEventSubscriptionLabelAction()
action.uuid = "cfb859d412933a1da57ae99e2aa442ce"
action.key = "VMUuid"
action.value = "27e59f9fe7ed46118a2f6b8a383ce494"
action.operator = "Equal"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
UpdateEventSubscriptionLabelAction.Result res = action.call()
API Reference | ZStack ZSphere · ZVF | ZStack Resource Center