在线文档

Document
PD3007 ZStack V3.0.1 开发手册 平台运维

其它文件格式:aid:1515,cn_name: 没有找到文档 PD3007, 请手工处理   电子书  


开发手册

版权声明

版权所有©上海云轴信息科技有限公司 2018。保留一切权利。

非经本公司书面许可,任何单位和个人不得擅自摘抄、复制本文档内容的部分或全部,并不得以任何形式传播。

商标说明

ZStack商标和其他云轴商标均为上海云轴信息科技有限公司的商标。

本文档提及的其他所有商标或注册商标,由各自的所有人拥有。

注意

您购买的产品、服务或特性等应受上海云轴公司商业合同和条款的约束,本文档中描述的全部或部分产品、服务或特性可能不在您的购买或使用范围之内。除非合同另有约定,上海云轴公司对本文档内容不做任何明示或暗示的声明或保证。

由于产品版本升级或其他原因,本文档内容会不定期进行更新。除非另有约定,本文档仅作为使用指导,本文档中的所有陈述、信息和建议不构成任何明示或暗示的担保。

引言

产品版本

目前与本文档相对应的产品版本为:ZStack 2.3.1

读者对象

本文档详述了ZStack 2.3.1 RESTful API的使用规范,并提供所有API的详细定义。本文档主要适用于以下读者:

  • 架构设计师
  • 开发工程师
  • 测试工程师
  • 项目实施人员
  • 对ZStack有兴趣研究的相关人员

版本更新

2.3.1

2018/04/03主要更新:

  1. 网络拓扑
  2. 新版菜单导航、新版首页
  3. ZWatch:全新监控报警系统
  4. ZStack定制版ISO新增:基于CentOS 7.4深度定制版本
  5. 亲和组
  6. 增强vCenter接管功能:接管vCenter云盘、基于vCenter云路由网络提供网络服务
  7. 一个云主机加载多个ISO
  8. 多种策略创建云主机
  9. 一个二层网络可用于创建多个三层网络
  10. 操作日志/审计全新改版
  11. HTTPS安全访问UI管理界面
  12. 内部访问业务流量的负载均衡
  13. 优化自定义UI
  14. 多个场景新增进度条、操作助手和帮助文档,优化UI交互
  15. 优化部分业务逻辑

2.3.0

2018/02/08主要更新:

  1. 专有网络VPC
  2. 混合云灾备(混合云版支持)
  3. 大屏监控
  4. 用户自定义UI
  5. ImageStore类型镜像服务器支持Ceph类型主存储
  6. 支持vSwitch
  7. 支持vCenter资源同步
  8. ESXi云主机支持扁平网络
  9. 云主机更换操作系统
  10. 跨NFS存储数据迁移
  11. 虚拟IP支持QoS
  12. 支持AD认证
  13. 云主机自定义MAC地址
  14. 强化浏览器上传镜像功能
  15. 新增云盘镜像资源
  16. 数据云盘扩容
  17. 数据云盘规格支持QoS
  18. 停止NeverStop状态的云主机
  19. 开放云路由公网IP,并支持同一虚拟IP多网络服务复用
  20. 支持USB设备透传,强化外接设备透传功能
  21. 增加VDI SPICE流量优化选项
  22. 支持修改已设置的存储网络
  23. 支持设置VXLAN对普通账户的配额
  24. 支持ImageStore类型镜像服务器间的数据同步
  25. 管理节点数据库自动备份到远程服务器
  26. 多个场景新增进度条、操作助手和帮助文档,优化UI交互
  27. 优化部分业务逻辑

2.2

2017/10/16主要更新:

  1. 公有网络创建云主机
  2. 自定义DHCP模式
  3. 新增系统网络
  4. 云主机根云盘扩容
  5. 浏览器添加镜像(目前支持ImageStore类型镜像服务器)
  6. 管理节点高可用:多网络配置
  7. 跨Ceph存储数据迁移
  8. 增强Ceph存储功能
  9. 增强VDI功能
  10. LDAP自定义过滤规则
  11. 增强裸机管理
  12. 单集群支持多类型主存储(目前支持本地存储+NFS/SMP类型)
  13. 更换License支持本地上传
  14. 共享存储指定存储网络,增强云主机高可用
  15. 多个场景新增进度条、操作助手和帮助文档,优化UI交互
  16. 优化部分业务逻辑

2.1

2017/08/14主要更新:

  1. VDI
  2. 裸机管理
  3. GPU透传
  4. 智能报警
  5. 集群挂载多个主存储
  6. 新版定时器
  7. 静态路由
  8. User Data导入
  9. 云路由加载多个公有网络
  10. 增量升级
  11. 优化部分业务逻辑

系列索引

ZStack 2.3.1 开发手册系列索引如下:

  • 《ZStack 2.3.1 开发手册 云资源池》
  • 《ZStack 2.3.1 开发手册 硬件设施》
  • 《ZStack 2.3.1 开发手册 网络资源》
  • 《ZStack 2.3.1 开发手册 网络服务》
  • 《ZStack 2.3.1 开发手册 vCenter》
  • 《ZStack 2.3.1 开发手册 平台运维》
  • 《ZStack 2.3.1 开发手册 平台管理》
  • 《ZStack 2.3.1 开发手册 设置》
  • 《ZStack 2.3.1 开发手册 系统全局相关》

API规范概述

ZStack 2.3.1提供原生RESTful支持。您可以通过REST定义的架构设计原则和约束条件,并使用支持HTTP的编程语言进行开发。

HTTP方法 (HTTP Verbs)

当前API支持如下操作资源的方法:

|方法名|描述| |---|--| |GET| 获取资源信息。

  • 所有的查询API以及读API均使用该方法。

    | |POST| 创建一个资源。

    | |PUT|修改一个资源。- 所有对资源的修改操作,以及类RPC调用的操作,例如启动虚拟机,均使用该方法。

| |DELETE|删除一个资源。|

Parent topic: API规范概述

传参方式

URL、Query String、HTTP body三种方式均可用于传参。每种方式可以单独使用,也可以混合使用,具体使用哪种传参方式由具体API决定。

URL传参

当对某具体资源进行操作时,资源的UUID通过编码到URL的方式进行传参。

例如启动一个UUID为 f97143d60f1042c9badd9a1336d3c105的虚拟机,URL格式为:

zstack/v1/vm-instances/f97143d60f1042c9badd9a1336d3c105/actions

这里UUID编码到URL路径当中。

Query String传参

所有使用HTTP GET方法的API均使用Query String传参。

例如查询所有状态为Running的虚拟机, URL格式为:

zstack/v1/vm-instances?condition=state=Running

HTTP Body传参

当使用POST方法创建一个资源,或PUT方法修改一个资源时,除通过URL传参的部分外,剩余参数均通过HTTP Body传参。

例如在指定物理机上启动一个虚拟机:

``` PUT zstack/v1/vm-instances/f97143d60f1042c9badd9a1336d3c105/actions

{ "startVmInstance": { "hostUuid": "8aef7e3a53b34eedaa05027a919156d9" } } ```

这里虚拟机的UUID通过URL传参,参数hostUuid则通过HTTP Body传递。

Parent topic: API规范概述

HTTP Headers

当前API使用如下自定义HTTP Headers:

Authorization

除了少数API外(例如登录API),使用ZStack API前都需要一个会话(session),在调用API时通过Authorization HTTP Header传递会话UUID。该Header的格式为:

Authorization: OAuth 会话UUID

举例:

Authorization: OAuth 34cbfddd470a47d8bdb0727cd2182618

Note: OAuth和会话UUID之间用空格分隔。

X-Job-UUID

对于异步API,可以通过X-Job-UUID HTTP Header来指定该API Job的UUID,例如:

X-Job-UUID: d825b1a26f4e474b8c59306081920ff2

如果未指定该HTTP Header,ZStack会自动为API Job生成一个UUID。

Note:

X-Job-UUID必须为一个v4版本的UUID(即随机UUID)字符串去掉连接符-。ZStack会验证X-Job-UUID格式的合法性,并对非法的字符串返回一个400 Bad Request的错误。

X-Web-Hook

对于异步API,可以通过X-Web-Hook HTTP Header指定一个回调URL用于接收API 返回。通过使用回调URL的方法,调用者可以避免使用轮询去查询一个异步API的执行结果。举例:

X-Web-Hook: http://localhost:5000/api-callback

X-Job-Success

当使用了X-Web-Hook回调的方式获取异步API结果时,ZStack推送给回调URL的HTTP Post请求中会包含X-Job-Success HTTP Header指明该异步API的执行结果是成功还是失败。例如:

X-Job-Success: true

当值为true时执行成功,为false时执行失败。

Parent topic: API规范概述

HTTP返回码 (HTTP Status Code)

ZStack使用如下返回码:

|返回码|意义| |---|--| |200|API执行成功。| |202|API请求已被ZStack接受,用户需要通过轮询或Web Hook的方式获取API结果。该返回码只在调用异步API时出现。| |400|API请求未包含必要的参数或包含了非法的参数。具体信息可以从HTTP Response Body获得。| |404|URL不存在,通常是指定了错误的API URL。如果访问的URL是异步API返回的轮询地址,表示该轮询地址已经过期。| |405|API调用使用了错误的HTTP方法,例如在创建一个资源的时候用了GET方法而不是POST方法。| |500| ZStack RESTful终端遭遇了一个内部错误。| |503|API所执行的操作引发了一个错误,例如资源不足无法创建虚拟机。错误的具体信息可以从HTTP Response Body。|

Parent topic: API规范概述

API种类

ZStack的API分为同步API和异步API两种:

同步API

所有使用GET方法的API都是同步API,调用方收到的HTTP Response中直接包含了API的结果。例如:

``` GET zstack/v1/zones/f3fa7671894a40f6a73f5bfc7d90c126

{ "inventory": { "uuid": "f3fa7671894a40f6a73f5bfc7d90c126", "name": "zone1", "description": "test", "state": "Enabled", "type": "zstack", "createDate": "Jan 6, 2017 3:51:16 AM", "lastOpDate": "Jan 6, 2017 3:51:16 AM" } } ```

异步API

除了登录相关的API外,所有不使用GET方法的API都为异步API。用户调用一个异步API成功后会收到202返回码以及 Body中包含的一个轮询地址(location字段),用户需要周期性的GET该轮询地址以获得API的执行结果。例如:

``` Status Code: 202

Body:

{ "location": "http://localhost:8989/v1/api-jobs/967a26b7431c49c0b1d50d709ef1aef3" } ```

通常情况下GET一个轮询地址可以得到四种返回:

  1. 202返回码表示该API仍在处理中,用户需要继续轮询。
  2. 200返回码表示API执行成功,Body中包含API结果。
  3. 503返回码表示API执行失败,Body中包含错误码。
  4. 404返回码,则表示轮询地址已经过期,产生这种结果的原因可能是用户访问了一个错误的轮询地址,或者太久没有访问该轮询地址(例如超过2天没有访问),该轮询地址已经被删除。

异步API也可以用Web Hook的方式获得结果,具体方法见后面章节。

Parent topic: API规范概述

API操作

跟所有的RESTful API类似,绝大多数ZStack API执行的是CRUD(Create, Read, Update, Delete)操作,以及类RPC操作。

创建资源

所有资源的创建都使用POST方法,参数通过HTTP Body传递,例如创建一个虚拟机:

``` POST zstack/v1/vm-instances

Authorization: OAuth 0c234e29a2ad4ff4b0d97d4f3b47c6cf

{ "params": { "l3NetworkUuids": ["37a701c7fe4a40758da15593aedd8aff"], "defaultL3NetworkUuid": "37a701c7fe4a40758da15593aedd8aff", "dataDiskOfferingUuids": [], "name": "TestVm", "description": "Test", "systemTags": [], "instanceOfferingUuid": "dd53f94b58924510b0122e40799a4114", "type": "UserVm", "imageUuid": "cc7b56780879409f98c1f992b75a12b0" } } ```

查询资源

资源的查询使用GET方法,查询条件通过Query String传参,例如查询集群cluster1中名字不等于 web-vm的虚拟机:

``` GET zstack/v1/vm-instances?condition=name!=web-vm&condition=cluster.name=cluster1

Authorization: OAuth 0c234e29a2ad4ff4b0d97d4f3b47c6cf ```

如果已知资源的UUID,要直接获取该资源的信息,直接使用GET方法不加任何查询条件,例如:

``` GET zstack/v1/vm-instances/56f0fd314a2647ffb4f9565f6d05858e

Authorization: OAuth 0c234e29a2ad4ff4b0d97d4f3b47c6cf ```

返回UUID为56f0fd314a2647ffb4f9565f6d05858e虚拟机的信息。

删除资源

删除资源使用DELETE方法,被删除资源的UUID编码在URL中,例如:

``` DELETE zstack/v1/vm-instances/56f0fd314a2647ffb4f9565f6d05858e

Authorization: OAuth 0c234e29a2ad4ff4b0d97d4f3b47c6cf ```

删除UUID为56f0fd314a2647ffb4f9565f6d05858e的虚拟机。

修改资源与类RPC操作

但由于IaaS本身业务的性质,一部分操作更类似于RPC(远程调用)而非CRUD操作,例如启动虚拟机。根据RESTful API的一些最佳实践,ZStack将这些操作都归为资源的actions子资源,例如启动虚拟机、 停止虚拟机都是对虚拟机的actions子资源进行操作。举个例子:

启动虚拟机:

``` PUT zstack/v1/vm-instances/d46841bd4ebd47f8bf0bed85c3bdf0db/actions

{ "startVmInstance": {} } ```

停止虚拟机:

``` PUT zstack/v1/vm-instances/d46841bd4ebd47f8bf0bed85c3bdf0db/actions

{ "stopVmInstance": {} } ```

在上面的例子中,两个操作都访问的是相同的URL/v1/vminstances/d46841bd4ebd47f8bf0bed85c3bdf0db/actions, 具体的操作类型由包含在Body中的字段名表示,例如stopVmInstance,如果该API包含额外参数,则包含在操作字段名对应的map中。

资源操作的具体字段名和例子参考每个API的详细文档。

Parent topic: API规范概述

基本流程示例

在下例中,我们会创建一个Zone,以展示API使用的基本流程:

登录

使用API的第一步是登录以获取一个Session UUID,以供后续API调用使用。

``` PUT zstack/v1/accounts/login

body:

{ "logInByAccount": { "password": "b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86", "accountName": "admin" } } ```

这里的密码是用sha512哈希后的结果。

API返回如下:

``` status code: 200

body:

{ "inventory": { "uuid": "00d038b699b74e76a01705918d48d939", "accountUuid": "36c27e8ff05c4780bf6d2fa65700f22e", "userUuid": "36c27e8ff05c4780bf6d2fa65700f22e", "expiredDate": "Jan 1, 2017 11:31:06 AM", "createDate": "Jan 1, 2017 9:31:06 AM" } } ```

返回内容中包含账户UUID等其他字段,我们需要的session UUID包含在字段uuid中:00d038b699b74e76a01705918d48d939

创建Zone

``` POST zstack/v1/zones

headers:

Authorization: OAuth 00d038b699b74e76a01705918d48d939

body:

{ "params": { "name": "Zone1", "description": "Test" } } ```

由于创建Zone操作是一个异步API,API返回不是直接的结果,而是一个轮询地址:

``` status code: 202

body:

{ "location": "http://localhost:8989/v1/api-jobs/d0345d3ddcae485f8170572b15a2b581" } ```

用户需要周期性的轮询API结果:

``` GET http://localhost:8989/v1/api-jobs/d0345d3ddcae485f8170572b15a2b581

Authorization: OAuth 00d038b699b74e76a01705918d48d939 ```

如果API还未执行完成,上述GET操作得到的仍然是202返回码和上述轮询地址。当操作完成时,得到的结果如下:

``` status code: 200

body:

{ "inventory": { "uuid": "f52fe55b64094ceb99b3893a238c4931", "name": "Zone1", "description": "Test", "state": "Enabled", "type": "zstack", "createDate": "Jan 1, 2017 9:31:07 AM", "lastOpDate": "Jan 1, 2017 9:31:07 AM" } } ```

查询Zone

要获取创建的Zone的信息,可以用GET查询:

``` GET zstack/v1/zones/f52fe55b64094ceb99b3893a238c4931

Authorization: OAuth 00d038b699b74e76a01705918d48d939 ```

返回:

``` status code: 200

body:

{ "inventory": { "uuid": "f52fe55b64094ceb99b3893a238c4931", "name": "Zone1", "description": "Test", "state": "Enabled", "type": "zstack", "createDate": "Jan 1, 2017 9:31:07 AM", "lastOpDate": "Jan 1, 2017 9:31:07 AM" } } ```

登出

当所有API调用完毕,我们需要对已登录的session进行登出操作:

DELETE zstack/v1/accounts/sessions/00d038b699b74e76a01705918d48d939

返回

status code: 200

Parent topic: API规范概述

Webhook

对于异步API使用轮询的方式查询操作结果是一种低效的方式,为此ZStack提供Webhook的方式主动推送异步API结果给调用者。

要使用Webhook功能,调用者只需在HTTP Headers中指定X-Job-UUID和X-Web-Hook即可。以上面创建Zone为例,使用Webhook的API版本为:

``` POST zstack/v1/zones

headers:

Authorization: OAuth 00d038b699b74e76a01705918d48d939 X-Job-UUID: d0345d3ddcae485f8170572b15a2b581 X-Web-Hook: http://127.0.0.1:8989/rest-webhook

body:

{ "params": { "name": "Zone1", "description": "Test" } } ```

API返回仍然是202返回码和一个轮询地址,但调用者无需再轮询。API执行成功后,结果会被推送到

http://127.0.0.1:8989/rest-webhook

``` POST http://127.0.0.1:8989/rest-webhook

headers:

X-Job-Success: true X-Job-UUID: d0345d3ddcae485f8170572b15a2b581

body:

{ "inventory": { "uuid": "f52fe55b64094ceb99b3893a238c4931", "name": "Zone1", "description": "Test", "state": "Enabled", "type": "zstack", "createDate": "Jan 1, 2017 9:31:07 AM", "lastOpDate": "Jan 1, 2017 9:31:07 AM" } } ```

推送的结果之中,X-Job-Success指明了API执行成功与否,X-Job-UUID包含值跟API调用时的X-Job-UUID相同,调用者可以对应结果和API。

Parent topic: API规范概述

查询API

用户可以用GET方法对一个资源进行查询,并且可以像MySQL一样指定多个查询条件、排序方式、选择字段、以及进行跨表查询等等。

支持超过400万个单项查询条件,以及400万阶乘的组合查询条件。

单表查询

例如:

GET zstack/v1/vm-instances?q=name=vm1

查询名字为vm1的虚拟机。

例如:

GET zstack/v1/vm-instances?q=name=vm1&q=state=Running

查询名字为vm1并且状态为Running的虚拟机。

这两个例子都是对虚拟机资源本身查询,反应到数据库层面还属于单表查询。

跨表查询

我们可以通过.进行跨表查询。

例如:

GET zstack/v1/vm-instances?q=vmNics.ip=192.168.10.100

查询IP地址为192.168.10.100的虚拟机,这里对虚拟机和网卡两张表进行了跨表查询。

例如:

GET zstack/v1/vm-instances?q=host.managementIp=10.10.20.3

查询IP为10.10.20.3上运行的所有虚拟机。这里对虚拟机和物理机两张表进行了跨表查询。

所有资源的查询API都支持下列参数

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |q (可选)|List|query|见查询条件。省略该字段将返回所有记录,返回记录数的上限受限于limit字段| |0.6| |limit (可选)|Integer|query|最多返回的记录数,类似MySQL的limit,默认值1000| |0.6| |start (可选)|Integer|query|起始查询记录位置,类似MySQL的offset。跟limit配合使用可以实现分页| |0.6| |count (可选)|Boolean|query|计数查询,相当于MySQL中的count()函数。当设置成true时,API只返回的是满足查询条件的记录数| |0.6| |groupBy (可选)|String|query|以字段分组,相当于MySQL中的group by关键字。例如groupBy=type| |1.9| |replyWithCount (可选)|Boolean|query|见分页查询| |0.6| |sort (可选)|String|query|以字段排序,等同于MySQL中的sort by关键字,例如sort=+ip。必须跟+或者-配合使用,+表示升序,-表示降序,后面跟排序字段名|`+`字段名,`-`字段名|0.6| |sortDirection (可选)|String|query|字段排序方向,必须跟sortBy配合使用|ascdesc|0.6| |fields (可选)|List|query|指定返回的字段,等同于MySQL中的select字段功能。例如fields=name,uuid,则只返回满足条件记录的name和uuid字段| |0.6|

查询条件

的查询条件类似于MySQL数据库。

例如:

uuid=bfa67f956afb430890aa49db14b85153 totalCapacity>2000 vmInstanceUuid not null

Note:

  • 字段名、查询操作符、匹配值三者之间不能有任何空格
  • 例如uuid = 25506342d1384c07b7342373a57475b9就是一个错误的查询条件,必须写为uuid=25506342d1384c07b7342373a57475b9

多个查询条件之间是关系。总共支持10个查询操作符:

  1. =: 等于,例如:

    vmInstanceUuid=c4981689088b40f98d2ade2548c323da

  2. !=: 不等于,例如:

    vmInstanceUuid!=c4981689088b40f98d2ade2548c323da

  3. >: 大于

  4. <: 小于
  5. >=: 大于等于
  6. <=: 小于等于
  7. ?=: in操作符,测试字段值是否在一个集合。集合中的值以,分隔。例如测试uuid是否属于某个集合:

    uuid?=25506342d1384c07b7342373a57475b9,bc58d68090ac42358c0cb0fe72e3287f

  8. !?=: not int操作符,测试字段值是否不属于一个集合。集合中的值以,分隔,例如测试name是否不等于VM1和VM2:

    name!?=VM1,VM2

  9. ~=: 字符串模糊匹配,相当于MySQL中的like操作。使用%匹配一个或多个字符,使用_匹配一个字符。 例如查询一个名字是以IntelCore开头的:

    name~=IntelCore%

  10. 或者查询一个名字是以IntelCore开头,以7结尾,中间模糊匹配一个字符:

    name~=IntelCore_7

    这样名字是IntelCoreI7IntelCoreM7的记录都会匹配上。

  11. !~=: 模糊匹配非操作。查询一个字段不能模糊匹配到某个字符串,匹配条件与~=相同。

  12. is null: 字段为null:

    name is null

  13. not null: 字段不为null:

    name not null

分页查询

startlimitreplyWithCount三个字段可以配合使用实现分页查询。

  • start指定起始查询位置。
  • limit指定查询返回的最大记录数。
  • replyWithCount被设置成true后,查询返回中会包含满足查询条件的记录总数,跟start值比较就可以得知还需几次分页。

例如:

总共有1000记录满足查询条件,使用如下组合:

start=0 limit=100 replyWithCount=true

则API返回将包含头100条记录,以及total字段等于1000,表示总共满足条件的记录为1000。

获取资源可查询字段

由于支持的查询条件数非常巨大,我们无法在文档中枚举所有的查询条件。

用户可以使用命令行工具-cli的自动补全功能来查看一个资源可查询的字段以及可跨表查询的字段。

  • 以查询虚拟机为例,在-cli里输入QueryVmInstance并按Tab键补全,可以看到提示页面:

    ```

    • >>>QueryVmInstance [Query Conditions:] allVolumes. cluster. host. image. instanceOffering. rootVolume. vmNics. zone.

    systemTag= userTag= allocatorStrategy= clusterUuid= cpuNum= cpuSpeed= createDate= defaultL3NetworkUuid= description= groupBy= hostUuid= hypervisorType= imageUuid= instanceOfferingUuid= lastHostUuid= lastOpDate= memorySize= name= platform= rootVolumeUuid= state= type= uuid= zoneUuid=

    [Parameters:] count= fields= limit= replyWithCount= sortBy= sortDirection= start= timeout=
    ```

  • 这里中间行:

    __systemTag__= __userTag__= allocatorStrategy= clusterUuid= cpuNum= cpuSpeed= createDate= defaultL3NetworkUuid= description= groupBy= hostUuid= hypervisorType= imageUuid= instanceOfferingUuid= lastHostUuid= lastOpDate= memorySize= name= platform= rootVolumeUuid= state= type= uuid= zoneUuid=

    __systemTag____userTag__两个特殊查询条件外,其余均为虚拟机表的原生字段,用户可以在API的查询条件里面指定它们,并且可以在fields参数中指定这些字段来过滤其它不希望API返回的字段。

    例如:

    GET zstack/v1/vm-instances?q=cpuNum>5

    返回CPU数量多于5的虚拟机。

    GET zstack/v1/vm-instances?q=hypervisorType=KVM&fields=uuid&fields=name

    返回虚拟化类型为KVM的虚拟机,由于在fields指定了uuid和name两个字段,API返回中只会包含虚拟机的name和uuid。

    Note:

    只有资源的原生字段可以被fields选取,__userTag____systemTag__以及下面讲到的跨表字段均不能出现在fields参数中。

  • 提示的第一行:

    ```

    allVolumes. cluster. host. image. instanceOffering. rootVolume. vmNics. zone. ```

    指明了虚拟机资源可以跟哪些资源做跨表查询,例如:allVolumes代表云盘,cluster代表集群,vmNics代表网卡等。

    如需查看这些资源的具体字段,只需输入资源名加.号,并按Tab键补全。

    例如:

    ```

    • >>>QueryVmInstance vmNics. [Query Conditions:] vmNics.eip. vmNics.l3Network. vmNics.loadBalancerListener. vmNics.portForwarding. vmNics.securityGroup. vmNics.vmInstance.

    vmNics.systemTag= vmNics.userTag= vmNics.createDate= vmNics.deviceId= vmNics.gateway= vmNics.ip= vmNics.l3NetworkUuid= vmNics.lastOpDate= vmNics.mac= vmNics.metaData= vmNics.netmask= vmNics.uuid= vmNics.vmInstanceUuid=
    ```

    这里我们输入了资源vmNics并用.号表示我们要做一个跨表查询,Tab键为我们补全了vmNics资源的原生字段以及可跨表查询的其它资源。

    • 例如vmNics.ip表示网卡的原生字段ip

GET zstack/v1/vm-instances?q=vmNics.ip=192.168.0.100

    进行了一个跨表查询,条件是网卡表的**ip**字段,返回的结果是**ip**为*192.168.0.100*的虚拟机。  -   网卡资源同样可以跟其它资源进行跨表查询,例如**vmNics.eip**。      将网卡表和EIP表进行跨表:      ```     GET zstack/v1/vm-instances?q=vmNics.eip.ip=192.168.0.100     ```      进行了跨3表查询,返回的是EIP为*192.168.0.100*的虚拟机。 
  • 通过资源间连续跨表,一个资源几乎跟系统中多个有逻辑关系的资源进行跨表,例如:

    ```

    • >>>QueryVmInstance zone.cluster.l2Network.l3Network. [Query Conditions:] zone.cluster.l2Network.l3Network.ipRanges. zone.cluster.l2Network.l3Network.l2Network. zone.cluster.l2Network.l3Network.networkServices. zone.cluster.l2Network.l3Network.serviceProvider. zone.cluster.l2Network.l3Network.vmNic. zone.cluster.l2Network.l3Network.zone.

    zone.cluster.l2Network.l3Network.systemTag= zone.cluster.l2Network.l3Network.userTag= zone.cluster.l2Network.l3Network.createDate= zone.cluster.l2Network.l3Network.description= zone.cluster.l2Network.l3Network.dnsDomain= zone.cluster.l2Network.l3Network.l2NetworkUuid= zone.cluster.l2Network.l3Network.lastOpDate= zone.cluster.l2Network.l3Network.name= zone.cluster.l2Network.l3Network.state= zone.cluster.l2Network.l3Network.system= zone.cluster.l2Network.l3Network.type= zone.cluster.l2Network.l3Network.uuid= zone.cluster.l2Network.l3Network.zoneUuid= ```

    分别跟zone, cluster, l2Network, l3Network多个资源进行跨表。

    Note:

    • 由于一个资源的逻辑关系存在环路,例如以虚拟机为主体可以跟网卡进行跨表,例如QueryVmInstance vmNics.,同时以网卡为查询主体也可以跟虚拟机进行跨表QueryVmNic vmInstance.,这样就会存在环路路径。
    • 例如 QueryVmInstance vmNics.vmInstance.name=vm1通过跨表查询了name=vm1的虚拟机,它的实际效果跟QueryVmInstance name=vm1完全等同。这里的跨表是无意义的,只会生产复杂的SQL语句导致低效的数据库查询。在使用中应该避免这种环路跨表查询。
  • __systemTag____userTag__是两个特殊的查询条件,允许用户通过tag查询资源。

    例如:

    QueryVmInstance __systemTag__=staticIp:10.10.1.20

    查询具有staticIp:10.10.1.20这个tag的虚拟机。

Parent topic: API规范概述

ZWatch相关接口

获取报警器历史记录(GetAlarmData)

API请求

URLs

GET zstack/v1/zwatch/alarm-histories

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/zwatch/alarm-histories?startTime=1.519829177E9&endTime=1.519915577E9&limit=200.0

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |startTime (可选)|Long|query|起始时间| |2.3| |endTime (可选)|Long|query|结束时间| |2.3| |limit (可选)|Integer|query|返回记录条数数量| |2.3| |labels (可选)|List|query|标签列表,用于过滤结果| |2.3| |systemTags (可选)|List|query|系统标签| |2.3| |userTags (可选)|List|query|用户标签| |2.3|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

GetAlarmDataAction action = new GetAlarmDataAction(); action.startTime = 1.519829177E9; action.endTime = 1.519915577E9; action.limit = 200.0; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; GetAlarmDataAction.Result res = action.call();

Python SDK

GetAlarmDataAction action = GetAlarmDataAction() action.startTime = 1.519829177E9 action.endTime = 1.519915577E9 action.limit = 200.0 action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" GetAlarmDataAction.Result res = action.call()

Parent topic: ZWatch相关接口

获取所有事件元数据(GetAllEventMetadata)

API请求

URLs

GET zstack/v1/zwatch/events/meta-data

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/zwatch/events/meta-data

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |systemTags (可选)|List|query|系统标签| |0.6| |userTags (可选)|List|query|用户标签| |0.6|

API返回

返回示例

{ "events": [ { "namespace": "ZStack/VM", "name": "org.zstack.zwatch.datatype.EventFamily@2169502b", "labelNames": [ "HAProcess", "Error" ] } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |events|List|详情参考events|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#events

|名字|类型|描述|起始版本| |--|--|--|----| |namespace|String|名字空间|2.3| |name|String|资源名称|2.3| |labelNames|List|标签名|2.3|

SDK示例

Java SDK

GetAllEventMetadataAction action = new GetAllEventMetadataAction(); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; GetAllEventMetadataAction.Result res = action.call();

Python SDK

GetAllEventMetadataAction action = GetAllEventMetadataAction() action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" GetAllEventMetadataAction.Result res = action.call()

Parent topic: ZWatch相关接口

获取所有监控项元数据(GetAllMetricMetadata)

API请求

URLs

GET zstack/v1/zwatch/metrics/meta-data

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/zwatch/metrics/meta-data

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |systemTags (可选)|List|query|系统标签| |2.3| |userTags (可选)|List|query|用户标签| |2.3|

API返回

返回示例

{ "metrics": [ { "namespace": "ZStack/VM", "name": "org.zstack.zwatch.datatype.Metric@5fd63d14", "labelNames": [ "VMUuid", "CPUNum" ] } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |metrics|List|详情参考metrics|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#metrics

|名字|类型|描述|起始版本| |--|--|--|----| |namespace|String|名字空间|2.3| |name|String|资源名称|2.3| |labelNames|List|标签名|2.3|

SDK示例

Java SDK

GetAllMetricMetadataAction action = new GetAllMetricMetadataAction(); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; GetAllMetricMetadataAction.Result res = action.call();

Python SDK

GetAllMetricMetadataAction action = GetAllMetricMetadataAction() action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" GetAllMetricMetadataAction.Result res = action.call()

Parent topic: ZWatch相关接口

获取审计数据(GetAuditData)

API请求

URLs

GET zstack/v1/zwatch/audits

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/zwatch/audits?startTime=1.51982917649E12&limit=50.0

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |startTime (可选)|Long|query|起始时间| |2.3| |endTime (可选)|Long|query|结束时间| |2.3| |limit (可选)|Integer|query|最大返回条数| |2.3| |labels (可选)|List|query|过滤标签列表| |2.3| |systemTags (可选)|List|query|系统标签| |2.3| |userTags (可选)|List|query|用户标签| |2.3|

API返回

返回示例

{ "audits": [ { "resourceUuid": "b1ca3fab6ebc4302ad9249d5402cb06c", "resourceType": "VmInstanceVO", "apiName": "org.zstack.header.vm.APISetVmRDPMsg", "operatorAccountUuid": "36c27e8ff05c4780bf6d2fa65700f22e", "duration": 22.0, "requestUuid": "d78093c0b2fb3850b3ce563b3a0b029d", "responseUuid": "08cf3fd2c4614811b4acc0620e20a98e", "sessionUuid": "05e5c663eb794faab5c5606c38103a17", "responseDump": "{\"success\":true}", "time": 1.512037844556E12 } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |audits|List|详情参考audits|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#audits

|名字|类型|描述|起始版本| |--|--|--|----| |resourceUuid|String|资源UUID|2.3| |resourceType|String|资源类型|2.3| |apiName|String|API名称|2.3| |error|String|错误详情|2.3| |operatorAccountUuid|String|发起API账号UUID|2.3| |duration|long|API耗时|2.3| |requestUuid|String|API请求UUID|2.3| |responseUuid|String|API返回UUID|2.3| |sessionUuid|String|会话UUID|2.3| |requestDump|String|API请求JSON存档|2.3| |responseDump|String|API返回JSON存档|2.3| |time|long|记录生成时间|2.3|

SDK示例

Java SDK

GetAuditDataAction action = new GetAuditDataAction(); action.startTime = 1.519829176639E12; action.limit = 50.0; action.conditions = asList("VMUuid=e427d5d818e9480abc6b79808fa74193"); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; GetAuditDataAction.Result res = action.call();

Python SDK

GetAuditDataAction action = GetAuditDataAction() action.startTime = 1.51982917664E12 action.limit = 50.0 action.conditions = [VMUuid=6fdc58a389624a099df364a4644a20b1] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" GetAuditDataAction.Result res = action.call()

Parent topic: ZWatch相关接口

获取事件(GetEventData)

API请求

URLs

GET zstack/v1/zwatch/events

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/zwatch/events?startTime=1.519829187122E12&limit=10.0

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |startTime (可选)|Long|query|起始时间| |2.3| |endTime (可选)|Long|query|结束时间| |2.3| |limit (可选)|Integer|query|最大返回条数| |2.3| |labels (可选)|List|query|过滤标签列表| |2.3| |latest (可选)|boolean|query|是否只返回最近一条记录| |2.3| |systemTags (可选)|List|query|系统标签| |2.3| |userTags (可选)|List|query|用户标签| |2.3|

API返回

返回示例

{ "events": [ { "namespace": "ZStack/VM", "name": "org.zstack.zwatch.datatype.EventFamily@2ab88a0a", "labels": {}, "emergencyLevel": "Normal", "resourceId": "e268c834341843229eb2617977fec4a3", "resourceName": "VmInstanceVO", "time": 1.519829187154E12 } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |events|List|详情参考events|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#events

|名字|类型|描述|起始版本| |--|--|--|----| |namespace|String|名字空间|2.3| |name|String|事件名|2.3| |labels|Map|标签|2.3| |resourceId|String|产生事件资源的ID(如果为ZStack资源则为资源UUID)|2.3| |resourceName|String|资源名称|2.3| |error|String|如果事件代表错误,该字段为错误详情|2.3| |time|long|事件产生时间|2.3| |emergencyLevel|EmergencyLevel|详情参考emergencyLevel|2.3|

#emergencyLevel

|名字|类型|描述|起始版本| |--|--|--|----| |name|String|资源名称|0.6| |ordinal|int| |0.6|

SDK示例

Java SDK

GetEventDataAction action = new GetEventDataAction(); action.startTime = 1.519829187242E12; action.limit = 10.0; action.conditions = asList("HostUuid=c732a54b784c48c2bba96538bf571c3e"); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; GetEventDataAction.Result res = action.call();

Python SDK

GetEventDataAction action = GetEventDataAction() action.startTime = 1.519829187243E12 action.limit = 10.0 action.conditions = [HostUuid=bbd9c4a2618f42a78f726f0336086a81] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" GetEventDataAction.Result res = action.call()

Parent topic: ZWatch相关接口

获取监控数据(GetMetricData)

API请求

URLs

GET zstack/v1/zwatch/metrics

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/zwatch/metrics?namespace=ZStack/VM&metricName=CPUIdleUtilization&startTime=1.519829245921E12&period=30.0

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |namespace|String|query|名字空间| |2.3| |metricName|String|query|监控项| |2.3| |startTime (可选)|Long|query|起始时间| |2.3| |endTime (可选)|Long|query|结束时间| |2.3| |period (可选)|Integer|query|数据精度| |2.3| |labels (可选)|List|query|过滤标签| |2.3| |systemTags (可选)|List|query|系统标签| |2.3| |userTags (可选)|List|query|用户标签| |2.3| |functions (可选)|List|query|函数列表| |2.3|

API返回

返回示例

{ "data": [ { "value": 101.02, "time": 1.519829245957E12, "labels": { "VMUuid": "9304ab73d9b84852ad1d5061fd4760a5" } } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |data|List|详情参考data|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#data

|名字|类型|描述|起始版本| |--|--|--|----| |value|double|监控值|0.6| |time|long|记录生成时间|0.6| |labels|Map|标签|0.6|

SDK示例

Java SDK

GetMetricDataAction action = new GetMetricDataAction(); action.namespace = "ZStack/VM"; action.metricName = "CPUIdleUtilization"; action.startTime = 1.519829246005E12; action.period = 30.0; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; GetMetricDataAction.Result res = action.call();

Python SDK

GetMetricDataAction action = GetMetricDataAction() action.namespace = "ZStack/VM" action.metricName = "CPUIdleUtilization" action.startTime = 1.519829246005E12 action.period = 30.0 action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" GetMetricDataAction.Result res = action.call()

Parent topic: ZWatch相关接口

获取监控项标签值(GetMetricLabelValue)

API请求

URLs

GET zstack/v1/zwatch/metrics/label-values

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/zwatch/metrics/label-values?namespace=ZStack/VM&metricName=CPUIdleUtilization&labelNames=CPUNum&filterLabels=VMUuid=e47f7145f4cd4fca8e2856038ecdf3e1

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |namespace|String|query|名字空间名称| |2.3| |metricName|String|query| | |2.3| |labelNames|List|query|要获取值得标签名列表| |2.3| |filterLabels (可选)|List|query|标签过滤器列表,例如可以指定标签HostUuid=e47f7145f4cd4fca8e2856038ecdf3e1来选择特定物理机的,labelNames中指定标签的值| |2.3| |systemTags (可选)|List|query|系统标签| |2.3| |userTags (可选)|List|query|用户标签| |2.3|

API返回

返回示例

{ "labels": [ { "VMUuid": "e47f7145f4cd4fca8e2856038ecdf3e1", "CPUNum": "1" } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |labels|List|标签值|0.6| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|0.6|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

SDK示例

Java SDK

GetMetricLabelValueAction action = new GetMetricLabelValueAction(); action.namespace = "ZStack/VM"; action.metricName = "CPUIdleUtilization"; action.labelNames = asList("CPUNum"); action.filterLabels = asList("VMUuid=e47f7145f4cd4fca8e2856038ecdf3e1"); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; GetMetricLabelValueAction.Result res = action.call();

Python SDK

GetMetricLabelValueAction action = GetMetricLabelValueAction() action.namespace = "ZStack/VM" action.metricName = "CPUIdleUtilization" action.labelNames = [CPUNum] action.filterLabels = [VMUuid=e47f7145f4cd4fca8e2856038ecdf3e1] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" GetMetricLabelValueAction.Result res = action.call()

Parent topic: ZWatch相关接口

添加自定义监控数据(PutMetricData)

API请求

URLs

POST zstack/v1/zwatch/metrics

Headers

Authorization: OAuth the-session-uuid

Body

{ "params": { "namespace": "MyNameSpace", "data": [ { "metricName": "UserDefinedName", "value": 100.01, "labels": { "label1": "value1" } } ] }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{"namespace":"MyNameSpace","data":[{"metricName":"UserDefinedName","value":100.01,"labels":{"label1":"value1"}}]}}' \ http://localhost:8080/zstack/v1/zwatch/metrics

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |namespace|String|body(包含在params结构中)|自定义名字空间名称| |2.3| |data|List|body(包含在params结构中)|数据| |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

PutMetricDataAction action = new PutMetricDataAction(); action.namespace = "MyNameSpace"; action.data = asList([metricName:UserDefinedName, value:100.01, labels:[label1:value1]]); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; PutMetricDataAction.Result res = action.call();

Python SDK

PutMetricDataAction action = PutMetricDataAction() action.namespace = "MyNameSpace" action.data = [[metricName:UserDefinedName, value:100.01, labels:[label1:value1]]] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" PutMetricDataAction.Result res = action.call()

Parent topic: ZWatch相关接口

通知服务相关接口

创建Email终端(CreateSNSEmailEndpoint)

API请求

URLs

POST zstack/v1/sns/application-endpoints/emails

Headers

Authorization: OAuth the-session-uuid

Body

{ "params": { "email": "example@zstack.io", "name": "email", "platformUuid": "5efc525948a537e39a91290c57d6d37b" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{"email":"example@zstack.io","name":"email","platformUuid":"5efc525948a537e39a91290c57d6d37b"}}' \ http://localhost:8080/zstack/v1/sns/application-endpoints/emails

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |email|String|body(包含在params结构中)|email地址| |2.3| |name|String|body(包含在params结构中)|资源名称| |2.3| |description (可选)|String|body(包含在params结构中)|资源的详细描述| |2.3| |platformUuid (可选)|String|body(包含在params结构中)|应用平台UUID| |2.3| |resourceUuid (可选)|String|body(包含在params结构中)| | |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

返回示例

{ "inventory": { "name": "example", "uuid": "917fe66f76b241f0843dfbd6be685fc1", "description": "description example", "type": "Email", "state": "Enabled", "platformUuid": "4eb0ceebf95b452585ebeacd647d9f35", "createDate": "Feb 28, 2018 9:47:36 AM", "lastOpDate": "Feb 28, 2018 9:47:36 AM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventory|SNSApplicationEndpointInventory|详情参考inventory|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |name|String|资源名称|2.3| |uuid|String|资源的UUID,唯一标示该资源|2.3| |description|String|资源的详细描述|2.3| |type|String|类型|2.3| |platformUuid|String|应用平台UUID|2.3| |createDate|Timestamp|创建时间|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3|

SDK示例

Java SDK

CreateSNSEmailEndpointAction action = new CreateSNSEmailEndpointAction(); action.email = "example@zstack.io"; action.name = "email"; action.platformUuid = "5efc525948a537e39a91290c57d6d37b"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; CreateSNSEmailEndpointAction.Result res = action.call();

Python SDK

CreateSNSEmailEndpointAction action = CreateSNSEmailEndpointAction() action.email = "example@zstack.io" action.name = "email" action.platformUuid = "5efc525948a537e39a91290c57d6d37b" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" CreateSNSEmailEndpointAction.Result res = action.call()

Parent topic: 通知服务相关接口

创建SNS主题(CreateSNSTopic)

API请求

URLs

POST zstack/v1/sns/topics

Headers

Authorization: OAuth the-session-uuid

Body

{ "params": { "name": "api topic" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{"name":"api topic"}}' \ http://localhost:8080/zstack/v1/sns/topics

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |name|String|body(包含在params结构中)|资源名称| |2.3| |description (可选)|String|body(包含在params结构中)|资源的详细描述| |2.3| |resourceUuid (可选)|String|body(包含在params结构中)| | |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

返回示例

{ "inventory": { "uuid": "a3a307316bb543e786b6dcac39847642", "name": "new name", "state": "Enabled", "createDate": "Feb 28, 2018 9:46:35 AM", "lastOpDate": "Feb 28, 2018 9:46:35 AM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventory|SNSTopicInventory|详情参考inventory|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.3| |name|String|资源名称|2.3| |description|String|资源的详细描述|2.3| |state|String|状态|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3| |createDate|Timestamp|创建时间|2.3|

SDK示例

Java SDK

CreateSNSTopicAction action = new CreateSNSTopicAction(); action.name = "api topic"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; CreateSNSTopicAction.Result res = action.call();

Python SDK

CreateSNSTopicAction action = CreateSNSTopicAction() action.name = "api topic" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" CreateSNSTopicAction.Result res = action.call()

Parent topic: 通知服务相关接口

删除SNS主题(DeleteSNSTopic)

API请求

URLs

DELETE zstack/v1/sns/topics/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X DELETE http://localhost:8080/zstack/v1/sns/topics/2e5e362e1a7836618d6cce49fba21e78?

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.3| |deleteMode (可选)|String|body| | |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

DeleteSNSTopicAction action = new DeleteSNSTopicAction(); action.uuid = "2e5e362e1a7836618d6cce49fba21e78"; action.deleteMode = "Permissive"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; DeleteSNSTopicAction.Result res = action.call();

Python SDK

DeleteSNSTopicAction action = DeleteSNSTopicAction() action.uuid = "2e5e362e1a7836618d6cce49fba21e78" action.deleteMode = "Permissive" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" DeleteSNSTopicAction.Result res = action.call()

Parent topic: 通知服务相关接口

查询SNS主题(QuerySNSTopic)

API请求

URLs

GET zstack/v1/sns/topics GET zstack/v1/sns/topics/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/topics?q=name=api

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/topics/b47d348c8c4a3559af1b09f31f7c26eb

可查询字段

运行zstack-cli命令行工具,输入QuerySNSTopic并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例

{ "inventories": [ { "uuid": "ccbec7ca092e40e0bfdfbd98563cb6da", "name": "new name", "state": "Enabled", "createDate": "Feb 28, 2018 9:47:31 AM", "lastOpDate": "Feb 28, 2018 9:47:31 AM" } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventories|List|详情参考inventories|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventories

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.3| |name|String|资源名称|2.3| |description|String|资源的详细描述|2.3| |state|String|状态|2.3| |createDate|Timestamp|创建时间|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3|

SDK示例

Java SDK

QuerySNSTopicAction action = new QuerySNSTopicAction(); action.conditions = asList("name=api"); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; QuerySNSTopicAction.Result res = action.call();

Python SDK

QuerySNSTopicAction action = QuerySNSTopicAction() action.conditions = ["name=api"] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" QuerySNSTopicAction.Result res = action.call()

Parent topic: 通知服务相关接口

更新SNS主题(UpdateSNSTopic)

API请求

URLs

PUT zstack/v1/sns/topics/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{ "updateSNSTopic": { "name": "new name" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"updateSNSTopic":{"name":"new name"}}' \ http://localhost:8080/zstack/v1/sns/topics/3e7550bf8ead3f02b366df6e499dc285/actions

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.3| |name (可选)|String|body(包含在updateSNSTopic结构中)|资源名称| |2.3| |description (可选)|String|body(包含在updateSNSTopic结构中)|资源的详细描述| |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|应用标签| |2.3|

API返回

返回示例

{ "inventory": { "uuid": "c3c748d9e08e4e61a03228ca0e6f2eef", "name": "new name", "state": "Enabled", "createDate": "Feb 28, 2018 9:47:49 AM", "lastOpDate": "Feb 28, 2018 9:47:49 AM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventory|SNSTopicInventory|详情参考inventory|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.3| |name|String|资源名称|2.3| |description|String|资源的详细描述|2.3| |state|String|状态|2.3| |createDate|Timestamp|创建时间|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3|

SDK示例

Java SDK

UpdateSNSTopicAction action = new UpdateSNSTopicAction(); action.uuid = "3e7550bf8ead3f02b366df6e499dc285"; action.name = "new name"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; UpdateSNSTopicAction.Result res = action.call();

Python SDK

UpdateSNSTopicAction action = UpdateSNSTopicAction() action.uuid = "3e7550bf8ead3f02b366df6e499dc285" action.name = "new name" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" UpdateSNSTopicAction.Result res = action.call()

Parent topic: 通知服务相关接口

更改SNS主题状态(ChangeSNSTopicState)

API请求

URLs

PUT zstack/v1/zwatch/topics/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{ "changeSNSTopicState": { "stateEvent": "disable" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"changeSNSTopicState":{"stateEvent":"disable"}}' \ http://localhost:8080/zstack/v1/zwatch/topics/89f0adcff110385a8a8fa2568a744ab5/actions

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.3| |stateEvent|String|body(包含在changeSNSTopicState结构中)|状态事件| - enable - disable

|2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

返回示例

{ "inventory": { "uuid": "00f71b1cd92144d68d2f7d0aa3e2e77a", "name": "new name", "state": "Enabled", "createDate": "Feb 28, 2018 9:47:02 AM", "lastOpDate": "Feb 28, 2018 9:47:02 AM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventory|SNSTopicInventory|详情参考inventory|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.3| |name|String|资源名称|2.3| |description|String|资源的详细描述|2.3| |state|String|状态|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3| |createDate|Timestamp|创建时间|2.3|

SDK示例

Java SDK

ChangeSNSTopicStateAction action = new ChangeSNSTopicStateAction(); action.uuid = "89f0adcff110385a8a8fa2568a744ab5"; action.stateEvent = "disable"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; ChangeSNSTopicStateAction.Result res = action.call();

Python SDK

ChangeSNSTopicStateAction action = ChangeSNSTopicStateAction() action.uuid = "89f0adcff110385a8a8fa2568a744ab5" action.stateEvent = "disable" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" ChangeSNSTopicStateAction.Result res = action.call()

Parent topic: 通知服务相关接口

订阅SNS主题(SubscribeSNSTopic)

API请求

URLs

POST zstack/v1/sns/topics/{topicUuid}/endpoints/{endpointUuid}

Headers

Authorization: OAuth the-session-uuid

Body

{ "params": {}, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{}}' \ http://localhost:8080/zstack/v1/sns/topics/755ac6aea82f3365a66b86258c55189e/endpoints/c1f5c1e23ff13001b249c18253984741

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |topicUuid|String|url|应用主题UUID| |2.3| |endpointUuid|String|url|终端UUID| |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

SubscribeSNSTopicAction action = new SubscribeSNSTopicAction(); action.topicUuid = "755ac6aea82f3365a66b86258c55189e"; action.endpointUuid = "c1f5c1e23ff13001b249c18253984741"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; SubscribeSNSTopicAction.Result res = action.call();

Python SDK

SubscribeSNSTopicAction action = SubscribeSNSTopicAction() action.topicUuid = "755ac6aea82f3365a66b86258c55189e" action.endpointUuid = "c1f5c1e23ff13001b249c18253984741" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" SubscribeSNSTopicAction.Result res = action.call()

Parent topic: 通知服务相关接口

退订SNS主题(UnsubscribeSNSTopic)

API请求

URLs

DELETE zstack/v1/sns/topics/{topicUuid}/endpoints/{endpointUuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X DELETE http://localhost:8080/zstack/v1/sns/topics/bd6c49ad623a3740880ca6d3ed3bb793/endpoints/36d6eb53f7c23fbca1ac72008940efc8?

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |topicUuid|String|url|主题UUID| |2.3| |endpointUuid|String|url|终端UUID| |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

UnsubscribeSNSTopicAction action = new UnsubscribeSNSTopicAction(); action.topicUuid = "bd6c49ad623a3740880ca6d3ed3bb793"; action.endpointUuid = "36d6eb53f7c23fbca1ac72008940efc8"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; UnsubscribeSNSTopicAction.Result res = action.call();

Python SDK

UnsubscribeSNSTopicAction action = UnsubscribeSNSTopicAction() action.topicUuid = "bd6c49ad623a3740880ca6d3ed3bb793" action.endpointUuid = "36d6eb53f7c23fbca1ac72008940efc8" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" UnsubscribeSNSTopicAction.Result res = action.call()

Parent topic: 通知服务相关接口

更改SNS应用平台状态(ChangeSNSApplicationPlatformState)

API请求

URLs

PUT zstack/v1/sns/application-platforms/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{ "changeSNSApplicationPlatformState": { "stateEvent": "enable" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"changeSNSApplicationPlatformState":{"stateEvent":"enable"}}' \ http://localhost:8080/zstack/v1/sns/application-platforms/bf16a9b0315a3942afb8b7f29e1287eb/actions

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.3| |stateEvent|String|body(包含在changeSNSApplicationPlatformState结构中)|状态事件| - enable - disable

|2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

返回示例

{ "inventory": { "uuid": "cce6611ab37f4e16b4e95a08d31838b1", "name": "email platform", "description": "example description", "state": "Enabled", "type": "Email", "createDate": "Feb 28, 2018 9:45:19 AM", "lastOpDate": "Feb 28, 2018 9:45:19 AM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventory|SNSApplicationPlatformInventory|详情参考inventory|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.3| |name|String|资源名称|2.3| |description|String|资源的详细描述|2.3| |type|String|类型|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3| |createDate|Timestamp|创建时间|2.3|

SDK示例

Java SDK

ChangeSNSApplicationPlatformStateAction action = new ChangeSNSApplicationPlatformStateAction(); action.uuid = "bf16a9b0315a3942afb8b7f29e1287eb"; action.stateEvent = "enable"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; ChangeSNSApplicationPlatformStateAction.Result res = action.call();

Python SDK

ChangeSNSApplicationPlatformStateAction action = ChangeSNSApplicationPlatformStateAction() action.uuid = "bf16a9b0315a3942afb8b7f29e1287eb" action.stateEvent = "enable" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" ChangeSNSApplicationPlatformStateAction.Result res = action.call()

Parent topic: 通知服务相关接口

查询SNS应用终端(QuerySNSApplicationEndpoint)

API请求

URLs

GET zstack/v1/sns/application-endpoints GET zstack/v1/sns/application-endpoints/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-endpoints?q=name=http

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-endpoints/b8a4be12db8237a1a42f897402afd4e8

可查询字段

运行zstack-cli命令行工具,输入QuerySNSApplicationEndpoint并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

QuerySNSApplicationEndpointAction action = new QuerySNSApplicationEndpointAction(); action.conditions = asList("name=http"); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; QuerySNSApplicationEndpointAction.Result res = action.call();

Python SDK

QuerySNSApplicationEndpointAction action = QuerySNSApplicationEndpointAction() action.conditions = ["name=http"] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" QuerySNSApplicationEndpointAction.Result res = action.call()

Parent topic: 通知服务相关接口

更新SNS应用主题(UpdateSNSApplicationEndpoint)

API请求

URLs

PUT zstack/v1/sns/application-endpoints/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{ "updateSNSApplicationEndpoint": { "name": "new name" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"updateSNSApplicationEndpoint":{"name":"new name"}}' \ http://localhost:8080/zstack/v1/sns/application-endpoints/7d6155384f4e3cdaa6e877ecec59318c/actions

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.3| |name (可选)|String|body(包含在updateSNSApplicationEndpoint结构中)|资源名称| |2.3| |description (可选)|String|body(包含在updateSNSApplicationEndpoint结构中)|资源的详细描述| |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

返回示例

{ "inventory": { "name": "example", "uuid": "917fe66f76b241f0843dfbd6be685fc1", "description": "description example", "type": "Email", "state": "Enabled", "platformUuid": "4eb0ceebf95b452585ebeacd647d9f35", "createDate": "Feb 28, 2018 9:46:19 AM", "lastOpDate": "Feb 28, 2018 9:46:19 AM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventory|SNSApplicationEndpointInventory|详情参考inventory|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |name|String|资源名称|2.3| |uuid|String|资源的UUID,唯一标示该资源|2.3| |description|String|资源的详细描述|2.3| |type|String|类型|2.3| |platformUuid|String|应用平台UUID|2.3| |createDate|Timestamp|创建时间|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3|

SDK示例

Java SDK

UpdateSNSApplicationEndpointAction action = new UpdateSNSApplicationEndpointAction(); action.uuid = "7d6155384f4e3cdaa6e877ecec59318c"; action.name = "new name"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; UpdateSNSApplicationEndpointAction.Result res = action.call();

Python SDK

UpdateSNSApplicationEndpointAction action = UpdateSNSApplicationEndpointAction() action.uuid = "7d6155384f4e3cdaa6e877ecec59318c" action.name = "new name" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" UpdateSNSApplicationEndpointAction.Result res = action.call()

Parent topic: 通知服务相关接口

创建钉钉终端(CreateSNSDingTalkEndpoint)

API请求

URLs

POST zstack/v1/sns/application-endpoints/ding-talk

Headers

Authorization: OAuth the-session-uuid

Body

{ "params": { "url": "http://dingding-robot-url", "atAll": false, "atPersonPhoneNumbers": [ "18900002222", "13377778888" ], "name": "dinding" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{"url":"http://dingding-robot-url","atAll":false,"atPersonPhoneNumbers":["18900002222","13377778888"],"name":"dinding"}}' \ http://localhost:8080/zstack/v1/sns/application-endpoints/ding-talk

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |url|String|body(包含在params结构中)|钉钉机器人URL| |2.3| |atAll (可选)|Boolean|body(包含在params结构中)|是否消息@所有人| |2.3| |atPersonPhoneNumbers (可选)|List|body(包含在params结构中)|要@用户的电话号码| |2.3| |name|String|body(包含在params结构中)|资源名称| |2.3| |description (可选)|String|body(包含在params结构中)|资源的详细描述| |2.3| |resourceUuid (可选)|String|body(包含在params结构中)| | |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3| |platformUuid (可选)|String|body(包含在params结构中)| | |2.3|

API返回

返回示例

{ "inventory": { "url": "http://dingding-url", "atAll": false, "atPersonPhoneNumbers": [ "18900001111" ], "name": "example", "uuid": "917fe66f76b241f0843dfbd6be685fc1", "description": "description example", "type": "Email", "platformUuid": "4eb0ceebf95b452585ebeacd647d9f35", "createDate": "Feb 28, 2018 9:47:10 AM", "lastOpDate": "Feb 28, 2018 9:47:10 AM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventory|SNSDingTalkEndpointInventory|详情参考inventory|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |url|String|钉钉机器人URL|2.3| |atAll|boolean|是否@所有人|2.3| |atPersonPhoneNumbers|List|@用户的电话号码|2.3| |name|String|资源名称|2.3| |uuid|String|资源的UUID,唯一标示该资源|2.3| |description|String|资源的详细描述|2.3| |type|String|终端类型|2.3| |platformUuid|String|应用平台UUID|2.3| |createDate|Timestamp|创建时间|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3|

SDK示例

Java SDK

CreateSNSDingTalkEndpointAction action = new CreateSNSDingTalkEndpointAction(); action.url = "http://dingding-robot-url"; action.atAll = false; action.atPersonPhoneNumbers = asList("18900002222","13377778888"); action.name = "dinding"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; CreateSNSDingTalkEndpointAction.Result res = action.call();

Python SDK

CreateSNSDingTalkEndpointAction action = CreateSNSDingTalkEndpointAction() action.url = "http://dingding-robot-url" action.atAll = false action.atPersonPhoneNumbers = [18900002222, 13377778888] action.name = "dinding" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" CreateSNSDingTalkEndpointAction.Result res = action.call()

Parent topic: 通知服务相关接口

查询钉钉终端(QuerySNSDingTalkEndpoint)

API请求

URLs

GET zstack/v1/sns/application-endpoints/ding-talk GET zstack/v1/sns/application-endpoints/ding-talk/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-endpoints/ding-talk?q=url=http://dingding-url

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-endpoints/ding-talk/69658f91a1f130e0986fbfb19de1b3c9

可查询字段

运行zstack-cli命令行工具,输入QuerySNSDingTalkEndpoint并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

QuerySNSDingTalkEndpointAction action = new QuerySNSDingTalkEndpointAction(); action.conditions = asList("url=http://dingding-url"); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; QuerySNSDingTalkEndpointAction.Result res = action.call();

Python SDK

QuerySNSDingTalkEndpointAction action = QuerySNSDingTalkEndpointAction() action.conditions = ["url=http://dingding-url"] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" QuerySNSDingTalkEndpointAction.Result res = action.call()

Parent topic: 通知服务相关接口

创建SNS邮件平台(CreateSNSEmailPlatform)

API请求

URLs

POST zstack/v1/sns/application-platforms/email

Headers

Authorization: OAuth the-session-uuid

Body

{ "params": { "smtpServer": "email.zstack.io", "smtpPort": 20.0, "username": "example@zstack.io", "password": "password", "name": "email platform" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{"smtpServer":"email.zstack.io","smtpPort":20.0,"username":"example@zstack.io","password":"password","name":"email platform"}}' \ http://localhost:8080/zstack/v1/sns/application-platforms/email

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |smtpServer|String|body(包含在params结构中)|SMTP服务器地址| |2.3| |smtpPort|Integer|body(包含在params结构中)|SMTP端口| |2.3| |username (可选)|String|body(包含在params结构中)|用户名| |2.3| |password (可选)|String|body(包含在params结构中)|密码| |2.3| |name|String|body(包含在params结构中)|资源名称| |2.3| |description (可选)|String|body(包含在params结构中)|资源的详细描述| |2.3| |resourceUuid (可选)|String|body(包含在params结构中)| | |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

返回示例

{ "inventory": { "uuid": "f6122105d8994b498e6184efcf03bb64", "name": "email platform", "description": "example description", "state": "Enabled", "type": "Email", "createDate": "Feb 28, 2018 9:47:35 AM", "lastOpDate": "Feb 28, 2018 9:47:35 AM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventory|SNSApplicationPlatformInventory|详情参考inventory|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.3| |name|String|资源名称|2.3| |description|String|资源的详细描述|2.3| |type|String|类型|2.3| |createDate|Timestamp|创建时间|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3|

SDK示例

Java SDK

CreateSNSEmailPlatformAction action = new CreateSNSEmailPlatformAction(); action.smtpServer = "email.zstack.io"; action.smtpPort = 20.0; action.username = "example@zstack.io"; action.password = "password"; action.name = "email platform"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; CreateSNSEmailPlatformAction.Result res = action.call();

Python SDK

CreateSNSEmailPlatformAction action = CreateSNSEmailPlatformAction() action.smtpServer = "email.zstack.io" action.smtpPort = 20.0 action.username = "example@zstack.io" action.password = "password" action.name = "email platform" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" CreateSNSEmailPlatformAction.Result res = action.call()

Parent topic: 通知服务相关接口

查询SNS邮件平台(QuerySNSEmailPlatform)

API请求

URLs

GET zstack/v1/sns/application-platforms/email GET zstack/v1/sns/application-platforms/email/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-platforms/email?q=name=email

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-platforms/email/fe6d6cd0fbf53a4eaa772f326972d765

可查询字段

运行zstack-cli命令行工具,输入QuerySNSEmailPlatform并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

QuerySNSEmailPlatformAction action = new QuerySNSEmailPlatformAction(); action.conditions = asList("name=email"); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; QuerySNSEmailPlatformAction.Result res = action.call();

Python SDK

QuerySNSEmailPlatformAction action = QuerySNSEmailPlatformAction() action.conditions = ["name=email"] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" QuerySNSEmailPlatformAction.Result res = action.call()

Parent topic: 通知服务相关接口

验证SNS邮件平台(ValidateSNSEmailPlatform)

API请求

URLs

PUT zstack/v1/sns/application-platforms/email/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{ "validateSNSEmailPlatform": {}, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"validateSNSEmailPlatform":{}}' \ http://localhost:8080/zstack/v1/sns/application-platforms/email/ee6f4b67dc7e3b298353a6fe2b5d0a6f/actions

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

ValidateSNSEmailPlatformAction action = new ValidateSNSEmailPlatformAction(); action.uuid = "ee6f4b67dc7e3b298353a6fe2b5d0a6f"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; ValidateSNSEmailPlatformAction.Result res = action.call();

Python SDK

ValidateSNSEmailPlatformAction action = ValidateSNSEmailPlatformAction() action.uuid = "ee6f4b67dc7e3b298353a6fe2b5d0a6f" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" ValidateSNSEmailPlatformAction.Result res = action.call()

Parent topic: 通知服务相关接口

查询SNS邮件终端(QuerySNSEmailEndpoint)

API请求

URLs

GET zstack/v1/sns/application-endpoints/emails GET zstack/v1/sns/application-endpoints/emails/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-endpoints/emails?q=email=test@zstack.io

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-endpoints/emails/bbae379b811f3d18a422d73557ece1b1

可查询字段

运行zstack-cli命令行工具,输入QuerySNSEmailEndpoint并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

QuerySNSEmailEndpointAction action = new QuerySNSEmailEndpointAction(); action.conditions = asList("email=test@zstack.io"); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; QuerySNSEmailEndpointAction.Result res = action.call();

Python SDK

QuerySNSEmailEndpointAction action = QuerySNSEmailEndpointAction() action.conditions = ["email=test@zstack.io"] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" QuerySNSEmailEndpointAction.Result res = action.call()

Parent topic: 通知服务相关接口

添加钉钉用户(AddSNSDingTalkAtPerson)

API请求

URLs

POST zstack/v1/sns/application-endpoints/ding-talk/at-persons

Headers

Authorization: OAuth the-session-uuid

Body

{ "params": { "phoneNumber": "18099997777", "endpointUuid": "5b9b95ca0cda3ab4bb51b5a4e1965305" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{"phoneNumber":"18099997777","endpointUuid":"5b9b95ca0cda3ab4bb51b5a4e1965305"}}' \ http://localhost:8080/zstack/v1/sns/application-endpoints/ding-talk/at-persons

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |phoneNumber|String|body(包含在params结构中)|用户电话号码(钉钉用户以电话注册)| |2.3| |endpointUuid|String|body(包含在params结构中)|钉钉终端UUID| |2.3| |resourceUuid (可选)|String|body(包含在params结构中)| | |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

返回示例

{ "inventory": { "uuid": "a72aa83b023744828f52adf83d850ed7", "phoneNumber": "18988887777", "endpointUuid": "ad5dc331264c4bcbbe56ee2523cde7a2" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventory|SNSDingTalkAtPersonInventory|详情参考inventory|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.3| |phoneNumber|String|用户电话号码|2.3| |endpointUuid|String|钉钉终端UUID|2.3|

SDK示例

Java SDK

AddSNSDingTalkAtPersonAction action = new AddSNSDingTalkAtPersonAction(); action.phoneNumber = "18099997777"; action.endpointUuid = "5b9b95ca0cda3ab4bb51b5a4e1965305"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; AddSNSDingTalkAtPersonAction.Result res = action.call();

Python SDK

AddSNSDingTalkAtPersonAction action = AddSNSDingTalkAtPersonAction() action.phoneNumber = "18099997777" action.endpointUuid = "5b9b95ca0cda3ab4bb51b5a4e1965305" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" AddSNSDingTalkAtPersonAction.Result res = action.call()

Parent topic: 通知服务相关接口

删除钉钉用户(RemoveSNSDingTalkAtPerson)

API请求

URLs

DELETE zstack/v1/sns/application-endpoints/ding-talk/{endpointUuid}/at-persons/{phoneNumber}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X DELETE http://localhost:8080/zstack/v1/sns/application-endpoints/ding-talk/696e69a1023f323ca147be82ed7f13cd/at-persons/18988887777?

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |deleteMode (可选)|String|body| | |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3| |endpointUuid|String|url|钉钉接收端UUID| |2.3| |phoneNumber|String|url|要删除的atPerson的电话| |2.3|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

RemoveSNSDingTalkAtPersonAction action = new RemoveSNSDingTalkAtPersonAction(); action.endpointUuid = "696e69a1023f323ca147be82ed7f13cd"; action.phoneNumber = "18988887777"; action.deleteMode = "Permissive"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; RemoveSNSDingTalkAtPersonAction.Result res = action.call();

Python SDK

RemoveSNSDingTalkAtPersonAction action = RemoveSNSDingTalkAtPersonAction() action.endpointUuid = "696e69a1023f323ca147be82ed7f13cd" action.phoneNumber = "18988887777" action.deleteMode = "Permissive" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" RemoveSNSDingTalkAtPersonAction.Result res = action.call()

Parent topic: 通知服务相关接口

创建SNS HTTP终端(CreateSNSHttpEndpoint)

API请求

URLs

POST zstack/v1/sns/application-endpoints/http

Headers

Authorization: OAuth the-session-uuid

Body

{ "params": { "url": "http://127.0.0.1:6666/test-url", "username": "username", "password": "password", "name": "http" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{"url":"http://127.0.0.1:6666/test-url","username":"username","password":"password","name":"http"}}' \ http://localhost:8080/zstack/v1/sns/application-endpoints/http

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |url|String|body(包含在params结构中)|HTTP URL| |2.3| |username (可选)|String|body(包含在params结构中)|用户名| |2.3| |password (可选)|String|body(包含在params结构中)|密码| |2.3| |name|String|body(包含在params结构中)|资源名称| |2.3| |description (可选)|String|body(包含在params结构中)|资源的详细描述| |2.3| |resourceUuid (可选)|String|body(包含在params结构中)| | |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3| |platformUuid (可选)|String|body(包含在params结构中)| | |0.6|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

CreateSNSHttpEndpointAction action = new CreateSNSHttpEndpointAction(); action.url = "http://127.0.0.1:6666/test-url"; action.username = "username"; action.password = "password"; action.name = "http"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; CreateSNSHttpEndpointAction.Result res = action.call();

Python SDK

CreateSNSHttpEndpointAction action = CreateSNSHttpEndpointAction() action.url = "http://127.0.0.1:6666/test-url" action.username = "username" action.password = "password" action.name = "http" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" CreateSNSHttpEndpointAction.Result res = action.call()

Parent topic: 通知服务相关接口

查询SNS HTTP终端(QuerySNSHttpEndpoint)

API请求

URLs

GET zstack/v1/sns/application-endpoints/http GET zstack/v1/sns/application-endpoints/http/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-endpoints/http?q=url=http://url

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-endpoints/http/cbd9163bb4683e10b8a5025621e36862

可查询字段

运行zstack-cli命令行工具,输入QuerySNSHttpEndpoint并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

QuerySNSHttpEndpointAction action = new QuerySNSHttpEndpointAction(); action.conditions = asList("url=http://url"); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; QuerySNSHttpEndpointAction.Result res = action.call();

Python SDK

QuerySNSHttpEndpointAction action = QuerySNSHttpEndpointAction() action.conditions = ["url=http://url"] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" QuerySNSHttpEndpointAction.Result res = action.call()

Parent topic: 通知服务相关接口

创建SNS监控模板(CreateSNSTextTemplate)

API请求

URLs

POST zstack/v1/zwatch/alarms/sns/text-templates

Headers

Authorization: OAuth the-session-uuid

Body

{ "params": { "name": "email template", "applicationPlatformType": "Email", "template": "Alarm ${ALARM_NAME} changes status to ${ALARM_CURRENT_STATUS}", "defaultTemplate": true }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{"name":"email template","applicationPlatformType":"Email","template":"Alarm ${ALARM_NAME} changes status to ${ALARM_CURRENT_STATUS}","defaultTemplate":true}}' \ http://localhost:8080/zstack/v1/zwatch/alarms/sns/text-templates

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |name|String|body(包含在params结构中)|资源名称| |2.3| |description (可选)|String|body(包含在params结构中)|资源的详细描述| |2.3| |applicationPlatformType|String|body(包含在params结构中)|SNS应用平台类型| |2.3| |template|String|body(包含在params结构中)|模板文本| |2.3| |defaultTemplate (可选)|Boolean|body(包含在params结构中)|是否作为默认模板| |2.3| |resourceUuid (可选)|String|body(包含在params结构中)| | |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

返回示例

{ "inventory": { "uuid": "481ad663bc1f496d8d0b09fce26177f7", "name": "email template", "applicationPlatformType": "Email", "template": "Alarm ${ALARM_NAME} changes status to ${ALARM_CURRENT_STATUS}", "defaultTemplate": false, "createDate": "Feb 28, 2018 9:47:06 AM", "lastOpDate": "Feb 28, 2018 9:47:06 AM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventory|SNSTextTemplateInventory|详情参考inventory|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.3| |name|String|资源名称|2.3| |description|String|资源的详细描述|2.3| |applicationPlatformType|String|应用平台类型|2.3| |template|String|模板文本|2.3| |defaultTemplate|Boolean|是否为默认模板|2.3| |createDate|Timestamp|创建时间|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3|

SDK示例

Java SDK

CreateSNSTextTemplateAction action = new CreateSNSTextTemplateAction(); action.name = "email template"; action.applicationPlatformType = "Email"; action.template = "Alarm ${ALARM_NAME} changes status to ${ALARM_CURRENT_STATUS}"; action.defaultTemplate = true; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; CreateSNSTextTemplateAction.Result res = action.call();

Python SDK

CreateSNSTextTemplateAction action = CreateSNSTextTemplateAction() action.name = "email template" action.applicationPlatformType = "Email" action.template = "Alarm ${ALARM_NAME} changes status to ${ALARM_CURRENT_STATUS}" action.defaultTemplate = true action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" CreateSNSTextTemplateAction.Result res = action.call()

Parent topic: 通知服务相关接口

查询SNS应用平台(QuerySNSApplicationPlatform)

API请求

URLs

GET zstack/v1/sns/application-platforms GET zstack/v1/sns/application-platforms/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-platforms?q=state=Enabled

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/sns/application-platforms/b9a635c9ff7c3544a232cad5b9a4aaf7

可查询字段

运行zstack-cli命令行工具,输入QuerySNSApplicationPlatform并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例

{ "inventories": [ { "uuid": "c418160d00ff407986dde8bd10a7f0c4", "name": "email platform", "description": "example description", "state": "Enabled", "type": "Email", "createDate": "Feb 28, 2018 9:46:58 AM", "lastOpDate": "Feb 28, 2018 9:46:58 AM" } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventories|List|详情参考inventories|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventories

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.3| |name|String|资源名称|2.3| |description|String|资源的详细描述|2.3| |type|String|类型|2.3| |createDate|Timestamp|创建时间|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3|

SDK示例

Java SDK

QuerySNSApplicationPlatformAction action = new QuerySNSApplicationPlatformAction(); action.conditions = asList("state=Enabled"); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; QuerySNSApplicationPlatformAction.Result res = action.call();

Python SDK

QuerySNSApplicationPlatformAction action = QuerySNSApplicationPlatformAction() action.conditions = ["state=Enabled"] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" QuerySNSApplicationPlatformAction.Result res = action.call()

Parent topic: 通知服务相关接口

更新SNS应用平台(UpdateSNSApplicationPlatform)

API请求

URLs

PUT zstack/v1/sns/application-platforms/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{ "updateSNSApplicationPlatform": { "name": "new name" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"updateSNSApplicationPlatform":{"name":"new name"}}' \ http://localhost:8080/zstack/v1/sns/application-platforms/577aff1dcbe932798fd615e88813c7ce/actions

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.3| |name (可选)|String|body(包含在updateSNSApplicationPlatform结构中)|资源名称| |2.3| |description (可选)|String|body(包含在updateSNSApplicationPlatform结构中)|资源的详细描述| |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|应用标签| |2.3|

API返回

返回示例

{ "inventory": { "uuid": "f0f61510039d48709f4bb7804588bb4f", "name": "email platform", "description": "example description", "state": "Enabled", "type": "Email", "createDate": "Feb 28, 2018 9:47:13 AM", "lastOpDate": "Feb 28, 2018 9:47:13 AM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.3| |inventory|SNSApplicationPlatformInventory|详情参考inventory|2.3|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.3| |name|String|资源名称|2.3| |description|String|资源的详细描述|2.3| |type|String|类型|2.3| |createDate|Timestamp|创建时间|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3|

SDK示例

Java SDK

UpdateSNSApplicationPlatformAction action = new UpdateSNSApplicationPlatformAction(); action.uuid = "577aff1dcbe932798fd615e88813c7ce"; action.name = "new name"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; UpdateSNSApplicationPlatformAction.Result res = action.call();

Python SDK

UpdateSNSApplicationPlatformAction action = UpdateSNSApplicationPlatformAction() action.uuid = "577aff1dcbe932798fd615e88813c7ce" action.name = "new name" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" UpdateSNSApplicationPlatformAction.Result res = action.call()

Parent topic: 通知服务相关接口

删除SNS应用平台(DeleteSNSApplicationPlatform)

API请求

URLs

DELETE zstack/v1/sns/application-platforms/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X DELETE http://localhost:8080/zstack/v1/sns/application-platforms/992bf9e24f6f3f25866956f8079ffadc?

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.3| |deleteMode (可选)|String|body| | |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

DeleteSNSApplicationPlatformAction action = new DeleteSNSApplicationPlatformAction(); action.uuid = "992bf9e24f6f3f25866956f8079ffadc"; action.deleteMode = "Permissive"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; DeleteSNSApplicationPlatformAction.Result res = action.call();

Python SDK

DeleteSNSApplicationPlatformAction action = DeleteSNSApplicationPlatformAction() action.uuid = "992bf9e24f6f3f25866956f8079ffadc" action.deleteMode = "Permissive" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" DeleteSNSApplicationPlatformAction.Result res = action.call()

Parent topic: 通知服务相关接口

删除SNS应用终端(DeleteSNSApplicationEndpoint)

API请求

URLs

DELETE zstack/v1/sns/application-endpoints/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X DELETE http://localhost:8080/zstack/v1/sns/application-endpoints/f068da2f92f7354cbc9054a6c14989ea?

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.3| |deleteMode (可选)|String|body| | |2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

DeleteSNSApplicationEndpointAction action = new DeleteSNSApplicationEndpointAction(); action.uuid = "f068da2f92f7354cbc9054a6c14989ea"; action.deleteMode = "Permissive"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; DeleteSNSApplicationEndpointAction.Result res = action.call();

Python SDK

DeleteSNSApplicationEndpointAction action = DeleteSNSApplicationEndpointAction() action.uuid = "f068da2f92f7354cbc9054a6c14989ea" action.deleteMode = "Permissive" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" DeleteSNSApplicationEndpointAction.Result res = action.call()

Parent topic: 通知服务相关接口

更改SNS应用终端状态(ChangeSNSApplicationEndpointState)

API请求

URLs

PUT zstack/v1/sns/application-endpoints/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{ "changeSNSApplicationEndpointState": { "stateEvent": "disable" }, "systemTags": [], "userTags": [] }

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"changeSNSApplicationEndpointState":{"stateEvent":"disable"}}' \ http://localhost:8080/zstack/v1/sns/application-endpoints/1485ef44ea5234ee83d80d3a15937e19/actions

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.3| |stateEvent|String|body(包含在changeSNSApplicationEndpointState结构中)|状态事件| - enable - disable

|2.3| |systemTags (可选)|List|body|系统标签| |2.3| |userTags (可选)|List|body|用户标签| |2.3|

API返回

返回示例

{ "inventory": { "name": "example", "uuid": "917fe66f76b241f0843dfbd6be685fc1", "description": "description example", "type": "Email", "state": "Enabled", "platformUuid": "4eb0ceebf95b452585ebeacd647d9f35", "createDate": "Feb 28, 2018 9:47:32 AM", "lastOpDate": "Feb 28, 2018 9:47:32 AM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|0.6| |inventory|SNSApplicationEndpointInventory|详情参考inventory|0.6|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.3| |name|String|资源名称|2.3| |description|String|资源的详细描述|2.3| |type|String|类型|2.3| |platformUuid|String|应用平台UUID|2.3| |lastOpDate|Timestamp|最后一次修改时间|2.3| |createDate|Timestamp|创建时间|2.3|

SDK示例

Java SDK

ChangeSNSApplicationEndpointStateAction action = new ChangeSNSApplicationEndpointStateAction(); action.uuid = "1485ef44ea5234ee83d80d3a15937e19"; action.stateEvent = "disable"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; ChangeSNSApplicationEndpointStateAction.Result res = action.call();

Python SDK

ChangeSNSApplicationEndpointStateAction action = ChangeSNSApplicationEndpointStateAction() action.uuid = "1485ef44ea5234ee83d80d3a15937e19" action.stateEvent = "disable" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" ChangeSNSApplicationEndpointStateAction.Result res = action.call()

Parent topic: 通知服务相关接口

智能报警相关接口

创建Email媒体(CreateEmailMedia)

API请求

URLs

POST zstack/v1/media/emails

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{"smtpServer":"smtp.xxx.com","smtpPort":25.0,"username":"sender@xxx.com","password":"password","name":"email"}}' \ http://localhost:8080/zstack/v1/media/emails

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |smtpServer|String|body(包含在params结构中)| | |2.1| |smtpPort|Integer|body(包含在params结构中)| | |2.1| |username (可选)|String|body(包含在params结构中)| | |2.1| |password (可选)|String|body(包含在params结构中)| | |2.1| |name|String|body(包含在params结构中)|资源名称| |2.1| |description (可选)|String|body(包含在params结构中)|资源的详细描述| |2.1| |resourceUuid (可选)|String|body(包含在params结构中)| | |2.1| |systemTags (可选)|List|body| | |2.1| |userTags (可选)|List|body| | |2.1|

API返回

返回示例

{ "inventory": { "smtpServer": "test.smtp.com", "smtpPort": 25.0, "username": "test", "password": "password", "uuid": "930d049da7f6401c9c391796a897e4b7", "name": "email", "type": "Email", "state": "Enabled", "lastOpDate": "Jul 8, 2017 7:47:34 PM", "createDate": "Jul 8, 2017 7:47:34 PM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventory|MediaInventory|详情参考inventory|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.1| |name|String|资源名称|2.1| |description|String|资源的详细描述|2.1| |type|String|媒体类型,Email|2.1| |state|String|媒体状态:- Enabled - Disabled

|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1| |createDate|Timestamp|创建时间|2.1|

SDK示例

Java SDK

CreateEmailMediaAction action = new CreateEmailMediaAction(); action.smtpServer = "smtp.xxx.com"; action.smtpPort = 25.0; action.username = "sender@xxx.com"; action.password = "password"; action.name = "email"; action.sessionId = "38aa8dee97fa435abd99b92825c871c3"; CreateEmailMediaAction.Result res = action.call();

Python SDK

CreateEmailMediaAction action = CreateEmailMediaAction() action.smtpServer = "smtp.xxx.com" action.smtpPort = 25.0 action.username = "sender@xxx.com" action.password = "password" action.name = "email" action.sessionId = "ded6ff1e9a264ad0b7671008e0b4aab3" CreateEmailMediaAction.Result res = action.call()

Parent topic: 智能报警相关接口

查询Email媒体(QueryEmailMedia)

API请求

URLs

GET zstack/v1/media/emails GET zstack/v1/media/emails/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/media/emails?q=name=test

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X GET http://localhost:8080/zstack/v1/media/emails/5f08c556bd143cada4c4b6d3a29f12db

可查询字段

运行**zstack-cli**命令行工具,输入**QueryEmailMedia**并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例

{ "inventories": [ { "uuid": "b040a14d9a193dc39e71869193bd0374", "name": "notification", "type": "Notification", "state": "Enabled", "lastOpDate": "Nov 14, 2017 10:20:57 PM", "createDate": "Nov 14, 2017 10:20:57 PM" } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventories|List|详情参考inventories|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventories

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.1| |name|String|资源名称|2.1| |description|String|资源的详细描述|2.1| |type|String|媒体类型,Email|2.1| |state|String|媒体状态,Enabled/Disabled|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1| |createDate|Timestamp|创建时间|2.1|

SDK示例

Java SDK

QueryEmailMediaAction action = new QueryEmailMediaAction(); action.conditions = asList("name=test"); action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; QueryEmailMediaAction.Result res = action.call();

Python SDK

QueryEmailMediaAction action = QueryEmailMediaAction() action.conditions = ["name=test"] action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" QueryEmailMediaAction.Result res = action.call()

Parent topic: 智能报警相关接口

更新Email媒体(UpdateEmailMedia)

API请求

URLs

PUT zstack/v1/media/emails/{uuid}

Headers

Authorization: OAuth the-session-uuid

Body

{ "updateEmailMedia": { "smtpServer": "test.stmp.com", "smtpPort": 25.0, "username": "test", "password": "password" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 2ad8521d762f429784426aaa50c00f05" \ -X PUT -d '{"updateEmailMedia":{"smtpServer":"test.stmp.com","smtpPort":25.0,"username":"test","password":"password"}}' \ http://localhost:8080/zstack/v1/media/emails/25e0eddca54f31ccb709291490f38274

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.1| |smtpServer (可选)|String|body(包含在updateEmailMedia结构中)|smtp服务器地址| |2.1| |smtpPort (可选)|Integer|body(包含在updateEmailMedia结构中)|smtp服务器端口| |2.1| |username (可选)|String|body(包含在updateEmailMedia结构中)|smtp用户名| |2.1| |password (可选)|String|body(包含在updateEmailMedia结构中)|smtp密码| |2.1| |systemTags (可选)|List|body| | |2.1| |userTags (可选)|List|body| | |2.1| |name (可选)|String|body(包含在updateEmailMedia结构中)|资源名称| |2.1| |description (可选)|String|body(包含在updateEmailMedia结构中)|资源的详细描述| |2.1|

API返回

返回示例

{ "inventory": { "smtpServer": "test.smtp.com", "smtpPort": 25.0, "username": "test", "password": "password", "uuid": "3768a61d81504f3782142b82ef8d0cbd", "name": "email", "type": "Email", "state": "Enabled", "lastOpDate": "Sep 22, 2017 12:24:42 PM", "createDate": "Sep 22, 2017 12:24:42 PM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败,操作成功时该字段为null。 详情参考error|2.1| |inventory|EmailMediaInventory|详情参考inventory|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |smtpServer|String|SMTP服务器地址|2.1| |smtpPort|Integer|SMTP服务器端口|2.1| |username|String|SMTP用户名|2.1| |password|String|SMTP密码|2.1| |uuid|String|资源的UUID,唯一标示该资源|2.1| |name|String|资源名称|2.1| |description|String|资源的详细描述|2.1| |type|String|类型,为Email|2.1| |state|String|状态:- Enabled - Disable

|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1| |createDate|Timestamp|创建时间|2.1|

SDK示例

Java SDK

UpdateEmailMediaAction action = new UpdateEmailMediaAction(); action.uuid = "901310f4f8664340b4886ba3508e6db8"; action.smtpServer = "test.stmp.com"; action.smtpPort = 25.0; action.username = "test"; action.password = "password"; action.sessionId = "e836cec799db4a5f857a440ca69ea411"; UpdateEmailMediaAction.Result res = action.call();

Python SDK

UpdateEmailMediaAction action = UpdateEmailMediaAction() action.uuid = "d3b96e60704b445080cf67f9aa9932e4" action.smtpServer = "test.stmp.com" action.smtpPort = 25.0 action.username = "test" action.password = "password" action.sessionId = "6af160697eec43428e2fd2a413ddc7c3" UpdateEmailMediaAction.Result res = action.call()

Parent topic: 智能报警相关接口

删除媒体(DeleteMedia)

API请求

URLs

DELETE zstack/v1/media/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 328f60a127dd48c0a0b70707cf5cab44" \ -X DELETE http://localhost:8080/zstack/v1/media/7607ce161f014d91b212530a8572f818?

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.1| |deleteMode (可选)|String|body| | |2.1| |systemTags (可选)|List|body| | |2.1| |userTags (可选)|List|body| | |2.1|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

DeleteMediaAction action = new DeleteMediaAction(); action.uuid = "f88e6c2a53b14b3e964b9243bb7e511f"; action.deleteMode = "Permissive"; action.sessionId = "f4b41d032b164b5092e917663dae5b53"; DeleteMediaAction.Result res = action.call();

Python SDK

DeleteMediaAction action = DeleteMediaAction() action.uuid = "59ce5b99d57f49ee829bc8e6b9db278f" action.deleteMode = "Permissive" action.sessionId = "3136ad8c0ed34805939e604164c9448e" DeleteMediaAction.Result res = action.call()

Parent topic: 智能报警相关接口

查询媒体(QueryMedia)

API请求

URLs

GET zstack/v1/media GET zstack/v1/media/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth f84708095feb40a594269218f81c4cab" \ -X GET http://localhost:8080/zstack/v1/media?q=name=notification

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b2419d63a12749db81729b79f4e2d968" \ -X GET http://localhost:8080/zstack/v1/media/529f71d137b54f01b7cd7958f42b228a

可查询字段

运行zstack-cli命令行工具,输入QueryMedia并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例

{ "inventories": [ { "uuid": "f6feb6c40a1d439085d766b4c79de950", "name": "notification", "type": "Notification", "state": "Enabled", "lastOpDate": "Jul 8, 2017 7:47:48 PM", "createDate": "Jul 8, 2017 7:47:48 PM" } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventories|List|详情参考inventories|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventories

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.1| |name|String|资源名称|2.1| |description|String|资源的详细描述|2.1| |type|String|媒体类型,Email|2.1| |state|String|媒体状态:- Enabled - Disabled

|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1| |createDate|Timestamp|创建时间|2.1|

SDK示例

Java SDK

QueryMediaAction action = new QueryMediaAction(); action.conditions = asList("name=notification"); action.sessionId = "4560d41afa4945c4811cb46636d34bc2"; QueryMediaAction.Result res = action.call();

Python SDK

QueryMediaAction action = QueryMediaAction() action.conditions = ["name=notification"] action.sessionId = "b86885c3ac0e4c709c687a6beb300274" QueryMediaAction.Result res = action.call()

Parent topic: 智能报警相关接口

改变媒体状态(ChangeMediaState)

API请求

URLs

PUT zstack/v1/media/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{ "changeMediaState": { "stateEvent": "disable" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"changeMediaState":{"stateEvent":"disable"}}' \ http://localhost:8080/zstack/v1/media/7550bc3186143de4883aefef12ada85a/actions

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.1| |stateEvent|String|body(包含在changeMediaState结构中)|状态事件:- enable - disable

| - enable - disable

|2.1| |systemTags (可选)|List|body| | |2.1| |userTags (可选)|List|body| | |2.1|

API返回

返回示例

{ "inventory": { "uuid": "8864025e13ef474f8a10194fc410e558", "name": "notification", "type": "Notification", "state": "Enabled", "lastOpDate": "Jul 8, 2017 7:47:19 PM", "createDate": "Jul 8, 2017 7:47:19 PM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。详情参考error|2.1| |inventory|MediaInventory|详情参考inventory|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.1| |name|String|资源名称|2.1| |description|String|资源的详细描述|2.1| |type|String|媒体类型,Email|2.1| |state|String|媒体状态:- Enabled - Disabled

|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1| |createDate|Timestamp|创建时间|2.1|

SDK示例

Java SDK

ChangeMediaStateAction action = new ChangeMediaStateAction(); action.uuid = "cac75f3de0c840cda3e2b8180a30dc71"; action.stateEvent = "disable"; action.sessionId = "3992b3a2b5d8474ca1e5a73dfdf971b8"; ChangeMediaStateAction.Result res = action.call();

Python SDK

ChangeMediaStateAction action = ChangeMediaStateAction() action.uuid = "f7e6320f43114bfab5cbf2d65488b7b9" action.stateEvent = "disable" action.sessionId = "401dadfb32fd4dd7918fb3c6e8471ea8" ChangeMediaStateAction.Result res = action.call()

Parent topic: 智能报警相关接口

创建Email报警动作(CreateEmailMonitorTriggerAction)

API请求

URLs

POST zstack/v1/monitoring/trigger-actions/emails

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{"email":"test@zstack.io","mediaUuid":"19fe27b78d4b3d18a405ac4aa488962b","name":"email","triggerUuids":["8e36dbdf7012306bb2394a5a2a7c3ee1","65792914f877346a95d083a63a76b867"]}}' \ http://localhost:8080/zstack/v1/monitoring/trigger-actions/emails

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |email|String|body|email地址| |2.1| |mediaUuid|String|body|包含SMTP信息的Email媒体UUID| |2.1| |name|String|body|资源名称| |2.1| |description (可选)|String|body|资源的详细描述| |2.1| |triggerUuids (可选)|List|body| | |2.1| |resourceUuid (可选)|String|body| | |2.1| |systemTags (可选)|List|body| | |2.1| |userTags (可选)|List|body| | |2.1|

API返回

返回示例

``` { "inventory": { "uuid": "e5743d970f1e4000a768182dceb0aac5", "name": "email", "state": "Enabled", "mediaUuids": [ "0422d4e2fcb64672b422aba479efd221" ], "createDate": "Jul 8, 2017 7:47:55 PM", "lastOpDate": "Jul 8, 2017 7:47:55 PM" } }

```

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventory|MonitorTriggerActionInventory|详情参考inventory|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.1| |name|String|资源名称|2.1| |description|String|资源的详细描述|2.1| |postScript|String|保留字段|2.1| |state|String|状态:- Enabled - Disabled

|2.1| |mediaUuids|List|媒体UUIDs|2.1| |createDate|Timestamp|创建时间|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1|

SDK示例

Java SDK

CreateEmailMonitorTriggerActionAction action = new CreateEmailMonitorTriggerActionAction(); action.email = "test@zstack.io"; action.mediaUuid = "88b7d20e2e434b37bb0ad983a073813b"; action.name = "email"; action.triggerUuids = asList("f90e7d753ac54f488fa8197519020ebc","69fe0e256ea64dd59b2551ddc9c885c0"); action.sessionId = "850cb5be9f5d453c86e6bfdf0b0c9ff6"; CreateEmailMonitorTriggerActionAction.Result res = action.call();

Python SDK

CreateEmailMonitorTriggerActionAction action = CreateEmailMonitorTriggerActionAction() action.email = "test@zstack.io" action.mediaUuid = "a0ab2efa6bb942b397731271dcc11afa" action.name = "email" action.triggerUuids = [ac5d207a18264b4aac834847ba734bd0, 9ba546dfba874a27b81dab14c512606a] action.sessionId = "54a1582c3076453fbdbddb31dcafc461" CreateEmailMonitorTriggerActionAction.Result res = action.call()

Parent topic: 智能报警相关接口

查询Email报警动作(QueryEmailTriggerAction)

API请求

URLs

GET zstack/v1/monitoring/trigger-actions/emails GET zstack/v1/monitoring/trigger-actions/emails/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 8a6aa7cf8d5c430ebbbfc9493a7579fb" \ -X GET http://localhost:8080/zstack/v1/monitoring/trigger-actions/emails?q=name=email

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 61a70fb350ac4691b754b39cb33058dd" \ -X GET http://localhost:8080/zstack/v1/monitoring/trigger-actions/emails/cb1d4e39ae524433aa57077c30c5683b

可查询字段

运行zstack-cli命令行工具,输入QueryEmailTriggerAction并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例

{ "inventories": [ { "uuid": "eb47cd93e4744bf180e40b7e56ed8be7", "name": "email", "state": "Enabled", "mediaUuids": [ "2504fa60cd0742949d759599e2f012a2" ], "createDate": "Jul 8, 2017 7:48:07 PM", "lastOpDate": "Jul 8, 2017 7:48:07 PM" } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventories|List|详情参考inventories|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventories

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.1| |name|String|资源名称|2.1| |description|String|资源的详细描述|2.1| |postScript|String|保留字段|2.1| |state|String|状态:- Enabled - Disabled

|2.1| |mediaUuids|List|媒体UUIDs|2.1| |createDate|Timestamp|创建时间|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1|

SDK示例

Java SDK

QueryEmailTriggerActionAction action = new QueryEmailTriggerActionAction(); action.conditions = asList("name=email"); action.sessionId = "dcb937ec363a4ab290dcf19b8f6fd73d"; QueryEmailTriggerActionAction.Result res = action.call();

Python SDK

QueryEmailTriggerActionAction action = QueryEmailTriggerActionAction() action.conditions = ["name=email"] action.sessionId = "68c7ef9c188d402f987d40db1464756f" QueryEmailTriggerActionAction.Result res = action.call()

Parent topic: 智能报警相关接口

更新Email报警动作(UpdateEmailMonitorTriggerAction)

API请求

URLs

PUT zstack/v1/monitoring/trigger-actions/emails/{uuid}

Headers

Authorization: OAuth the-session-uuid

Body

{ "updateEmailMonitorTriggerAction": { "name": "email", "email": "test@zstack.io", "mediaUuid": "1dec357a8f0333e0864d0fb1b08a14b0" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"updateEmailMonitorTriggerAction":{"name":"email","email":"test@zstack.io","mediaUuid":"1dec357a8f0333e0864d0fb1b08a14b0"}}' \ http://localhost:8080/zstack/v1/monitoring/trigger-actions/emails/6ae00e51630f32edb9bf545ac26794de

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.1| |name (可选)|String|body(包含在updateEmailMonitorTriggerAction结构中)|资源名称| |2.1| |email (可选)|String|body(包含在updateEmailMonitorTriggerAction结构中)|email地址| |2.1| |mediaUuid (可选)|String|body(包含在updateEmailMonitorTriggerAction结构中)|包含SMTP信息的Email媒体UUID| |2.1| |description (可选)|String|body(包含在updateEmailMonitorTriggerAction结构中)|资源的详细描述| |2.1| |systemTags (可选)|List|body| | |2.1| |userTags (可选)|List|body| | |2.1|

API返回

返回示例

{ "inventory": { "uuid": "d6d3cf58f29f3616800725c7b0da941a", "name": "email", "state": "Enabled", "createDate": "Nov 14, 2017 10:20:57 PM", "lastOpDate": "Nov 14, 2017 10:20:57 PM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventory|MonitorTriggerActionInventory|详情参考inventory|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.1| |name|String|资源名称|2.1| |description|String|资源的详细描述|2.1| |postScript|String|保留字段|2.1| |state|String|状态:- Enabled - Disabled

|2.1| |mediaUuids|List|媒体UUIDs|2.1| |createDate|Timestamp|创建时间|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1|

SDK示例

Java SDK

UpdateEmailMonitorTriggerActionAction action = new UpdateEmailMonitorTriggerActionAction(); action.uuid = "6ae00e51630f32edb9bf545ac26794de"; action.name = "email"; action.email = "test@zstack.io"; action.mediaUuid = "1dec357a8f0333e0864d0fb1b08a14b0"; action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"; UpdateEmailMonitorTriggerActionAction.Result res = action.call();

Python SDK

UpdateEmailMonitorTriggerActionAction action = UpdateEmailMonitorTriggerActionAction() action.uuid = "6ae00e51630f32edb9bf545ac26794de" action.name = "email" action.email = "test@zstack.io" action.mediaUuid = "1dec357a8f0333e0864d0fb1b08a14b0" action.sessionId = "b86c9016b4f24953a9edefb53ca0678c" UpdateEmailMonitorTriggerActionAction.Result res = action.call()

Parent topic: 智能报警相关接口

创建报警器(CreateMonitorTrigger)

API请求

URLs

POST zstack/v1/monitoring/triggers

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST -d '{"params":{"name":"trigger","expression":"vm.cpu.util{} \u003e 80","duration":60.0,"targetResourceUuid":"fa2cccc924d6319db38a4637e62b9874"}}' \ http://localhost:8080/zstack/v1/monitoring/triggers

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |name|String|body|资源名称| |2.1| |expression|String|body|报警表达式| |2.1| |duration|Integer|body|持续时间。当报警表达式被触发超过时间后,发出报警| |2.1| |recoveryExpression (可选)|String|body|保留字段,未使用| |2.1| |description (可选)|String|body|资源的详细描述| |2.1| |targetResourceUuid|String|body|目标资源UUID。例如对虚拟机创建报警器,则该字段为虚拟机UUID| |2.1| |resourceUuid (可选)|String|body| | |2.1| |systemTags (可选)|List|body|系统标签| |2.1| |userTags (可选)|List|body|用户标签| |2.1|

API返回

返回示例

{ "inventory": { "name": "VM1 CPU utilization trigger", "uuid": "6f1290bc85ca4cc1855b4f42515518f2", "expression": "vm.cpu.util{} \u003e 100", "status": "OK", "state": "Enabled", "duration": 60.0, "targetResourceUuid": "12282f78256148728247c8cce2097a0b" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventory|MonitorTriggerInventory|详情参考inventory|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |name|String|资源名称|2.1| |uuid|String|资源的UUID,唯一标示该资源|2.1| |expression|String| |2.1| |recoveryExpression|String| |2.1| |description|String|资源的详细描述|2.1| |status|String| |2.1| |state|String| |2.1| |duration|Integer| |2.1| |targetResourceUuid|String| |2.1| |lastStatusChangeTime|Timestamp| |2.1| |createDate|Timestamp|创建时间|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1|

SDK示例

Java SDK

CreateMonitorTriggerAction action = new CreateMonitorTriggerAction(); action.name = "trigger"; action.expression = "vm.cpu.util{} > 80"; action.duration = 60.0; action.targetResourceUuid = "e79ab971d9e84afeac5593b4e48ac94f"; action.sessionId = "d90ad055ab0848de926d2af13a7db4ce"; CreateMonitorTriggerAction.Result res = action.call();

Python SDK

CreateMonitorTriggerAction action = CreateMonitorTriggerAction() action.name = "trigger" action.expression = "vm.cpu.util{} > 80" action.duration = 60.0 action.targetResourceUuid = "48ad54174a41469bb708d0f91bd6e76d" action.sessionId = "5bb0c121270c457e9791fb2183158c5b" CreateMonitorTriggerAction.Result res = action.call()

Parent topic: 智能报警相关接口

删除报警器(DeleteMonitorTrigger)

API请求

URLs

DELETE zstack/v1/monitoring/triggers/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 33aa4811e8b244fc969b85ac78d9ef96" \ -X DELETE http://localhost:8080/zstack/v1/monitoring/triggers/51a3f49a6ebd417798b408dbc60f97cb?

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.1| |deleteMode (可选)|String|body| | |2.1| |systemTags (可选)|List|body| | |2.1| |userTags (可选)|List|body| | |2.1|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

DeleteMonitorTriggerAction action = new DeleteMonitorTriggerAction(); action.uuid = "3a0ec5a309e3492b857d1f9e918c0afe"; action.deleteMode = "Permissive"; action.sessionId = "41c4521d8f8448e4bbf31eb52e15dccb"; DeleteMonitorTriggerAction.Result res = action.call();

Python SDK

DeleteMonitorTriggerAction action = DeleteMonitorTriggerAction() action.uuid = "79106b54eee64df4934e8c30d775d320" action.deleteMode = "Permissive" action.sessionId = "2c86552f81de439297c6d638e69e90c2" DeleteMonitorTriggerAction.Result res = action.call()

Parent topic: 智能报警相关接口

查询报警器(QueryMonitorTrigger)

API请求

URLs

GET zstack/v1/monitoring/triggers GET zstack/v1/monitoring/triggers/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 3cb8730ae979446f8de7764b2502c338" \ -X GET http://localhost:8080/zstack/v1/monitoring/triggers?q=name=trigger

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 09ac80dd2c864c26a8b27df79c237594" \ -X GET http://localhost:8080/zstack/v1/monitoring/triggers/875c56d072e4439cb5876a6266a6f040

可查询字段

运行zstack-cli命令行工具,输入QueryMonitorTrigger并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例

{ "inventories": [ { "name": "VM1 CPU utilization trigger", "uuid": "261c6733483a4310a26a97b955ff62af", "expression": "vm.cpu.util{} \u003e 100", "status": "OK", "state": "Enabled", "duration": 60.0, "targetResourceUuid": "be96b591934e496f8aea8dfd4be3eb90" } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventories|List|详情参考inventories|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventories

|名字|类型|描述|起始版本| |--|--|--|----| |name|String|资源名称|2.1| |uuid|String|资源的UUID,唯一标示该资源|2.1| |expression|String| |2.1| |recoveryExpression|String| |2.1| |description|String|资源的详细描述|2.1| |status|String| |2.1| |state|String| |2.1| |duration|Integer| |2.1| |targetResourceUuid|String| |2.1| |lastStatusChangeTime|Timestamp| |2.1| |createDate|Timestamp|创建时间|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1|

SDK示例

Java SDK

QueryMonitorTriggerAction action = new QueryMonitorTriggerAction(); action.conditions = asList("name=trigger"); action.sessionId = "02f06faf71894d87a110db5ab519f48c"; QueryMonitorTriggerAction.Result res = action.call();

Python SDK

QueryMonitorTriggerAction action = QueryMonitorTriggerAction() action.conditions = ["name=trigger"] action.sessionId = "09bd39c3c9464f4e8ae654fa4ee65b28" QueryMonitorTriggerAction.Result res = action.call()

Parent topic: 智能报警相关接口

更新报警器(UpdateMonitorTrigger)

API请求

URLs

PUT zstack/v1/monitoring/triggers/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{ "updateMonitorTrigger": { "name": "trigger2", "expression": "vm.mem.util{} \u003e 0.9" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"updateMonitorTrigger":{"name":"trigger2","expression":"vm.mem.util{} \u003e 0.9"}}' \ http://localhost:8080/zstack/v1/monitoring/triggers/0a4b1776910e3bd397a0135416301882/actions

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |0.6| |name (可选)|String|body(包含在updateMonitorTrigger结构中)|资源名称| |0.6| |description (可选)|String|body(包含在updateMonitorTrigger结构中)|资源的详细描述| |0.6| |expression (可选)|String|body(包含在updateMonitorTrigger结构中)|报警表达式| |0.6| |duration (可选)|Integer|body(包含在updateMonitorTrigger结构中)|持续时间| |0.6| |systemTags (可选)|List|body|系统标签| |0.6| |userTags (可选)|List|body|用户标签| |0.6|

API返回

返回示例

{ "inventory": { "name": "VM1 CPU utilization trigger", "uuid": "0c4f5f73e05249d99a956e95cef3aab2", "expression": "vm.cpu.util{} \u003e 100", "status": "OK", "state": "Enabled", "duration": 60.0, "targetResourceUuid": "6d3617fc9c06448d8b312954e8cbf483" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|0.6| |inventory|MonitorTriggerInventory|详情参考inventory|0.6|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |name|String|资源名称|0.6| |uuid|String|资源的UUID,唯一标示该资源|0.6| |expression|String| |0.6| |recoveryExpression|String| |0.6| |description|String|资源的详细描述|0.6| |status|String| |0.6| |state|String| |0.6| |duration|Integer| |0.6| |targetResourceUuid|String| |0.6| |lastStatusChangeTime|Timestamp| |0.6| |createDate|Timestamp|创建时间|0.6| |lastOpDate|Timestamp|最后一次修改时间|0.6|

SDK示例

Java SDK

UpdateMonitorTriggerAction action = new UpdateMonitorTriggerAction(); action.uuid = "8aeedf5fc442450083ed36fef9055307"; action.name = "trigger2"; action.expression = "vm.mem.util{} > 0.9"; action.sessionId = "ff64322209b64f768d0202bedd601e68"; UpdateMonitorTriggerAction.Result res = action.call();

Python SDK

UpdateMonitorTriggerAction action = UpdateMonitorTriggerAction() action.uuid = "089b3ed064cb469db992106abdd46a7f" action.name = "trigger2" action.expression = "vm.mem.util{} > 0.9" action.sessionId = "30a9f58a52464f4ebef556d3951faa7e" UpdateMonitorTriggerAction.Result res = action.call()

Parent topic: 智能报警相关接口

修改报警器状态(ChangeMonitorTriggerState)

API请求

URLs

PUT zstack/v1/monitoring/triggers/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{ "changeMonitorTriggerState": { "stateEvent": "disable" }, "systemTags": [], "userTags": [] }

Note:

上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"changeMonitorTriggerState":{"stateEvent":"disable"}}' \ http://localhost:8080/zstack/v1/monitoring/triggers/8fcec96c762f3207bd0e1f9fd3ba76e1/actions

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.1| |stateEvent|String|body(包含在changeMonitorTriggerState结构中)|状态事件| - enable - disable

|2.1| |systemTags (可选)|List|body|系统标签| |2.1| |userTags (可选)|List|body|用户标签| |2.1|

API返回

返回示例

{ "inventory": { "name": "VM1 CPU utilization trigger", "uuid": "c746520e53624285b2f5b617d0583eb3", "expression": "vm.cpu.util{} \u003e 100", "status": "OK", "state": "Enabled", "duration": 60.0, "targetResourceUuid": "646f451549c74d58b2b15ee380fecbe7" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventory|MonitorTriggerInventory|详情参考inventory|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |name|String|资源名称|2.1| |uuid|String|资源的UUID,唯一标示该资源|2.1| |expression|String| |2.1| |recoveryExpression|String| |2.1| |description|String|资源的详细描述|2.1| |status|String| |2.1| |state|String| |2.1| |duration|Integer| |2.1| |targetResourceUuid|String| |2.1| |lastStatusChangeTime|Timestamp| |2.1| |createDate|Timestamp|创建时间|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1|

SDK示例

Java SDK

ChangeMonitorTriggerStateAction action = new ChangeMonitorTriggerStateAction(); action.uuid = "f7ee325b83664c9187be22dabd1a3e46"; action.stateEvent = "disable"; action.sessionId = "42acba683d7a4a6e956079b233aeb802"; ChangeMonitorTriggerStateAction.Result res = action.call();

Python SDK

ChangeMonitorTriggerStateAction action = ChangeMonitorTriggerStateAction() action.uuid = "412c84f98de24021889f2da41e133ec5" action.stateEvent = "disable" action.sessionId = "958433b8b21d4e72bd7f0a23f242adb4" ChangeMonitorTriggerStateAction.Result res = action.call()

Parent topic: 智能报警相关接口

删除报警器动作(DeleteMonitorTriggerAction)

API请求

URLs

DELETE zstack/v1/monitoring/trigger-actions/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 4e1775dc594845f29d8e6ad32d5df8cf" \ -X DELETE http://localhost:8080/zstack/v1/monitoring/trigger-actions/dc43dbf7cb0a4e5cb7d94fa53342e7ad?

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.1| |deleteMode (可选)|String|body| | |2.1| |systemTags (可选)|List|body| | |2.1| |userTags (可选)|List|body| | |2.1|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

DeleteMonitorTriggerActionAction action = new DeleteMonitorTriggerActionAction(); action.uuid = "0a6f76794d764ea4b1f74b087335bd6f"; action.deleteMode = "Permissive"; action.sessionId = "4664a05084694ebaabcb1b3b365ac38f"; DeleteMonitorTriggerActionAction.Result res = action.call();

Python SDK

DeleteMonitorTriggerActionAction action = DeleteMonitorTriggerActionAction() action.uuid = "f9849168f1854f6a929a96493d69838b" action.deleteMode = "Permissive" action.sessionId = "870a697df06c4a658c70722d480f9f19" DeleteMonitorTriggerActionAction.Result res = action.call()

Parent topic: 智能报警相关接口

查询报警器动作(QueryMonitorTriggerAction)

API请求

URLs

GET zstack/v1/monitoring/trigger-actions GET zstack/v1/monitoring/trigger-actions/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth bb8ddadc9abd4668933bc66416ee7700" \ -X GET http://localhost:8080/zstack/v1/monitoring/trigger-actions?q=name=email

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 7134f2042fc14653981864385b87f679" \ -X GET http://localhost:8080/zstack/v1/monitoring/trigger-actions/358fa9c8f1b8403ca46998646a2fc89c

可查询字段

QueryMonitorTriggerActionAction action = new QueryMonitorTriggerActionAction(); action.

运行zstack-cli命令行工具,输入QueryMonitorTriggerAction并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例

{ "inventories": [ { "uuid": "0da4c233f2b74d989f77527870525d97", "name": "email", "state": "Enabled", "mediaUuids": [ "7f1471b73cf14e18aefd6f284803ae29" ], "createDate": "Jul 8, 2017 7:47:36 PM", "lastOpDate": "Jul 8, 2017 7:47:36 PM" } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventories|List|详情参考inventories|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventories

|名字|state|描述|起始版本| |--|-----|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.1| |name|String|资源名称|2.1| |description|String|资源的详细描述|2.1| |postScript|String|保留字段|2.1| | |String|状态:- Enabled - Disabled

|2.1| |mediaUuids|List|媒体UUIDs|2.1| |createDate|Timestamp|创建时间|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1|

SDK示例

Java SDK

conditions = asList("name=email"); action.sessionId = "0af8ad99790b47d2a512465b6419dfb2"; QueryMonitorTriggerActionAction.Result res = action.call();

Python SDK

QueryMonitorTriggerActionAction action = QueryMonitorTriggerActionAction() action.conditions = ["name=email"] action.sessionId = "2605f9a170b84b29981d640f531adbe5" QueryMonitorTriggerActionAction.Result res = action.call()

Parent topic: 智能报警相关接口

更改报警器动作状态(ChangeMonitorTriggerActionState)

API请求

URLs

PUT zstack/v1/monitoring/trigger-actions/{uuid}/actions

Headers

Authorization: OAuth the-session-uuid

Body

{ "changeMonitorTriggerActionState": { "stateEvent": "disable" }, "systemTags": [], "userTags": [] }

Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X PUT -d '{"changeMonitorTriggerActionState":{"stateEvent":"disable"}}' \ http://localhost:8080/zstack/v1/monitoring/trigger-actions/3288df3421cf3704a979d354b8a66278/actions

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuid|String|url|资源的UUID,唯一标示该资源| |2.1| |stateEvent|String|body(包含在changeMonitorTriggerActionState结构中)|状态事件| - enable - disable

|2.1| |systemTags (可选)|List|body| | |2.1| |userTags (可选)|List|body| | |2.1|

API返回

返回示例

{ "inventory": { "uuid": "9a73af455f1b3cc19d45c29f231aaa3b", "name": "triggerAction", "state": "enable", "createDate": "Nov 14, 2017 10:20:57 PM", "lastOpDate": "Nov 14, 2017 10:20:57 PM" } }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventory|MonitorTriggerActionInventory|详情参考inventory|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventory

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.1| |name|String|资源名称|2.1| |description|String|资源的详细描述|2.1| |postScript|String|保留字段|2.1| |state|String|状态:- Enabled - Disabled

|2.1| |mediaUuids|List|媒体UUIDs|2.1| |createDate|Timestamp|创建时间|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1|

SDK示例

Java SDK

ChangeMonitorTriggerActionStateAction action = new ChangeMonitorTriggerActionStateAction(); action.uuid = "f56abd9e502b4f409a9f5ac4840d5db8"; action.stateEvent = "disable"; action.sessionId = "12f5f4e1965741cd9c243e90e75c9c0c"; ChangeMonitorTriggerActionStateAction.Result res = action.call();

Python SDK

ChangeMonitorTriggerActionStateAction action = ChangeMonitorTriggerActionStateAction() action.uuid = "4dd402c6b761430a979e4cb4187a7258" action.stateEvent = "disable" action.sessionId = "d78e4ab7de684d53a1c374c71c6be77f" ChangeMonitorTriggerActionStateAction.Result res = action.call()

Parent topic: 智能报警相关接口

加载报警动作到报警器(AttachMonitorTriggerActionToTrigger)

API请求

URLs

POST zstack/v1/monitoring/triggers/{triggerUuid}/trigger-actions/{actionUuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \ -X POST http://localhost:8080/zstack/v1/monitoring/triggers/9d9ef9b033123941acc8225d7d4215c7/trigger-actions/ccd950316e753430898f06aff1ebad1f

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |triggerUuid|String|url|报警器UUID| |2.1| |actionUuid|String|url|报警动作UUID| |2.1| |systemTags (可选)|List|body|系统标签| |2.1| |userTags (可选)|List|body|用户标签| |2.1|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

AttachMonitorTriggerActionToTriggerAction action = new AttachMonitorTriggerActionToTriggerAction(); action.triggerUuid = "0f3d545198954f53af29e0af4fd741d6"; action.actionUuid = "8b30871574e04eea9dae184de749ca3f"; action.sessionId = "e361b8ce764846d79a5a08e64bd87df6"; AttachMonitorTriggerActionToTriggerAction.Result res = action.call();

Python SDK

AttachMonitorTriggerActionToTriggerAction action = AttachMonitorTriggerActionToTriggerAction() action.triggerUuid = "9f2c7900c1244df19f62126e5f778644" action.actionUuid = "4ad9e597c9524476b9728d8dd8893c85" action.sessionId = "f89fe17125cc406b8da0ca4d458d3920" AttachMonitorTriggerActionToTriggerAction.Result res = action.call()

Parent topic: 智能报警相关接口

卸载报警动作(DetachMonitorTriggerActionFromTrigger)

API请求

URLs

DELETE zstack/v1/monitoring/triggers/{triggerUuid}/trigger-actions/{actionUuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 1d651fd35f984b328efe95e27dc9fb08" \ -X DELETE http://localhost:8080/zstack/v1/monitoring/triggers/4215d2e98e86489e99aad3749336e9e3/trigger-actions/831edf2ab0c34b43b9ccedcc95b065a5?

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |triggerUuid|String|url|报警器UUID| |2.1| |actionUuid|String|url|报警动作UUID| |2.1| |systemTags (可选)|List|body| | |2.1| |userTags (可选)|List|body| | |2.1|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

DetachMonitorTriggerActionFromTriggerAction action = new DetachMonitorTriggerActionFromTriggerAction(); action.triggerUuid = "cf377eb31f9a4c358fecc369d830b50c"; action.actionUuid = "0dcdd47e6c204a8aa4bbd52b34fe7cc7"; action.sessionId = "ebf53a6f24e141b2850c9ed2891b604e"; DetachMonitorTriggerActionFromTriggerAction.Result res = action.call();

Python SDK

DetachMonitorTriggerActionFromTriggerAction action = DetachMonitorTriggerActionFromTriggerAction() action.triggerUuid = "4f3b4441107f43ac9aac78f74aedba3b" action.actionUuid = "357c49a5c6444656a0ecbf78c700d0c8" action.sessionId = "dea7bdd4da4d4642a4ff722ce4ca52e3" DetachMonitorTriggerActionFromTriggerAction.Result res = action.call()

Parent topic: 智能报警相关接口

查询报警记录(QueryAlert)

API请求

URLs

GET zstack/v1/monitoring/alerts GET zstack/v1/monitoring/alerts/{uuid}

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth ddfcfe4fa1834d90a392ed3ed8bea89c" \ -X GET http://localhost:8080/zstack/v1/monitoring/alerts?q=uuid=f9954ed1816a4d35ac0eba8a51d40472

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 1870a8403041446382881874629e63a5" \ -X GET http://localhost:8080/zstack/v1/monitoring/alerts/dccbfa8f8006455fb44f5eef29201fa2

可查询字段

运行zstack-cli命令行工具,输入QueryAlert并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例

{ "inventories": [ { "uuid": "cb18150c6da3479289f8c71a1f7cf90a", "triggerUuid": "bc0a8d509d27456fbabc3547ef2e599a", "content": "alert content", "createDate": "Jul 8, 2017 7:47:25 PM", "lastOpDate": "Jul 8, 2017 7:47:25 PM" } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventories|List|详情参考inventories|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventories

|名字|类型|描述|起始版本| |--|--|--|----| |uuid|String|资源的UUID,唯一标示该资源|2.1| |triggerUuid|String| |2.1| |targetResourceUuid|String| |2.1| |content|String| |2.1| |createDate|Timestamp|创建时间|2.1| |lastOpDate|Timestamp|最后一次修改时间|2.1|

SDK示例

Java SDK

QueryAlertAction action = new QueryAlertAction(); action.conditions = asList("uuid=a41075ffa17744a182c5dfb16b19b33c"); action.sessionId = "d26aaa502d194e2297b3cca2390237b2"; QueryAlertAction.Result res = action.call();

Python SDK

QueryAlertAction action = QueryAlertAction() action.conditions = ["uuid=290bb8f87ff6493f82bce96a437fb7f9"] action.sessionId = "fee3f8917179497fb5ea9b28171c58b7" QueryAlertAction.Result res = action.call()

Parent topic: 智能报警相关接口

删除报警记录(DeleteAlert)

API请求

URLs

DELETE zstack/v1/monitoring/alerts

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 07483b48fe224f14b06644772eb0c2c5" \ -X DELETE http://localhost:8080/zstack/v1/monitoring/alerts?

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |uuids|List|body|报警记录UUID| |2.1| |deleteMode (可选)|String|body| | |2.1| |systemTags (可选)|List|body| | |2.1| |userTags (可选)|List|body| | |2.1|

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:

{ "error": { "code": "SYS.1001", "description": "A message or a operation timeout", "details": "Create VM on KVM timeout after 300s" } }

SDK示例

Java SDK

DeleteAlertAction action = new DeleteAlertAction(); action.uuids = asList("f5f90d7b52ed4932843bf0192b4309e9","62e55afce47648ef92ed7b9748db0a84"); action.deleteMode = "Permissive"; action.sessionId = "f9552d8b085c4b67a63e1d57aacd534c"; DeleteAlertAction.Result res = action.call();

Python SDK

DeleteAlertAction action = DeleteAlertAction() action.uuids = [28654793c2aa47c6ae0073521f7506d9, 7d4735da147e4b9fb6e7c126f5df55b7] action.deleteMode = "Permissive" action.sessionId = "b1e43ac530fb4e3e97e55bc969a7b8d6" DeleteAlertAction.Result res = action.call()

Parent topic: 智能报警相关接口

获取报警条目(GetMonitorItem)

API请求

URLs

GET zstack/v1/monitoring/items

Headers

Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "Authorization: OAuth 0487dd030a5040b68fb815b8d5002de2" \ -X GET http://localhost:8080/zstack/v1/monitoring/items?resourceType=HostVO

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |resourceType|String|query|资源类型| |2.1| |systemTags (可选)|List|query| | |2.1| |userTags (可选)|List|query| | |2.1|

API返回

返回示例

{ "inventories": [ { "name": "host.cpu.util", "readableName": "Host CPU Utilization" } ] }

|名字|类型|描述|起始版本| |--|--|--|----| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|2.1| |inventories|List|详情参考inventories|2.1|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|2.1| |description|String|错误的概要描述|2.1| |details|String|错误的详细信息|2.1| |elaboration|String|保留字段,默认为null|2.1| |opaque|LinkedHashMap|保留字段,默认为null|2.1| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|2.1|

#inventories

|名字|类型|描述|起始版本| |--|--|--|----| |name|String|资源名称|2.1| |readableName|String| |2.1|

SDK示例

Java SDK

GetMonitorItemAction action = new GetMonitorItemAction(); action.resourceType = "HostVO"; action.sessionId = "2d8e9a4b65cb4bbaa096c0243977f795"; GetMonitorItemAction.Result res = action.call();

Python SDK

GetMonitorItemAction action = GetMonitorItemAction() action.resourceType = "HostVO" action.sessionId = "47804666ecf2497c9abef70f798e1e53" GetMonitorItemAction.Result res = action.call()

Parent topic: 智能报警相关接口

查询虚拟机监控数据(PrometheusQueryVmMonitoringData)

API请求

URLs

GET zstack/v1/prometheus/vm-instances

Headers

OAuth: the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "OAuth: 3203311cdaad4f2a8fffc6b9760879ef" \ -X GET http://localhost:8080/zstack/v1/prometheus/vm-instances?instant=false

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |vmUuids|List|query|云主机UUID| |0.6| |instant (可选)|boolean|query| - true表示该查询是instant查询,即只查某个时间点的数据 - false表示是range查询

| - true - false

|0.6| |startTime (可选)|Long|query|起始时间| |0.6| |endTime (可选)|Long|query|结束时间| |0.6| |step (可选)|String|query|数据后处理间隔| |0.6| |expression|String|query|prometheus query DSL| |0.6| |relativeTime (可选)|String|query|相对时间| |0.6| |systemTags (可选)|List|query|系统标签| |0.6| |userTags (可选)|List|query|用户标签| |0.6|

API返回

返回示例

{ "inventories": { "data": { "result": [ { "metric": { "__name__": "collectd:collectd_virt_disk_octets_read", "exported_instance": "93fd69daa457477ba979c4be4e21dfdd", "hostUuid": "f8271f58468b4281a212a43e530b5535", "instance": "172.20.1.46:9103", "job": "collectd", "type": "hdc", "virt": "93fd69daa457477ba979c4be4e21dfdd" }, "values": [ [ 1510766963, "0" ], [ 1510766972, "0" ], [ 1510766981, "0" ] ] } ], "resultType": "matrix" }, "status": "success" }, "jobUuid": "18b24a19246a54f9b06c1eccf53b9c7c", "success": true }

|名字|类型|描述|起始版本| |--|--|--|----| |inventories|Map| |0.6| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|0.6|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

SDK示例

Java SDK

PrometheusQueryVmMonitoringDataAction action = new PrometheusQueryVmMonitoringDataAction(); action.instant = false; action.sessionId = "fc47a3c8833d4de8939ce16b0efaafaa"; PrometheusQueryVmMonitoringDataAction.Result res = action.call();

Python SDK

PrometheusQueryVmMonitoringDataAction action = PrometheusQueryVmMonitoringDataAction() action.instant = false action.sessionId = "5e6dd601302645dfa7057ddb5d27d85a" PrometheusQueryVmMonitoringDataAction.Result res = action.call()

查询一个label有多少个value(PrometheusQueryLabelValues)

API请求

URLs

GET zstack/v1/prometheus/labels

Headers

OAuth: the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "OAuth: 01d81357d1624c82b8cf1408ca5cf7de" \ -X GET http://localhost:8080/zstack/v1/prometheus/labels

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |labels|List|query|标签值列表| |0.6| |systemTags (可选)|List|query|系统标签| |0.6| |userTags (可选)|List|query|用户标签| |0.6|

API返回

返回示例

{ "inventories": { "cpu": { "data": [ "0", "1", "10", "11" ], "status": "success" } }, "jobUuid": "a6191542e72b3f48a5b89ab689f56210", "success": true }

|名字|类型|描述|起始版本| |--|--|--|----| |inventories|Map| |0.6| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|0.6|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

SDK示例

Java SDK

PrometheusQueryLabelValuesAction action = new PrometheusQueryLabelValuesAction(); action.sessionId = "b8baeeb6dec14b828a31de824dc18dde"; PrometheusQueryLabelValuesAction.Result res = action.call();

Python SDK

PrometheusQueryLabelValuesAction action = PrometheusQueryLabelValuesAction() action.sessionId = "e08ee4e6b6934b75ab302790d55a43eb" PrometheusQueryLabelValuesAction.Result res = action.call()

查询一个metric有多少个label(PrometheusQueryMetadata)

API请求

URLs

GET zstack/v1/prometheus/meta-data

Headers

OAuth: the-session-uuid

Curl示例

curl -H "Content-Type: application/json" \ -H "OAuth: 0f9e4b50d84b4b7eabb925858b1fa2d0" \ -X GET http://localhost:8080/zstack/v1/prometheus/meta-data

参数列表

|名字|类型|位置|描述|可选值|起始版本| |--|--|--|--|---|----| |matches|List|query|匹配条件| |0.6| |systemTags (可选)|List|query|系统标签| |0.6| |userTags (可选)|List|query|用户标签| |0.6|

API返回

返回示例

{ "inventories": { "data": [ { "__name__": "collectd:collectd_virt_disk_ops_write", "exported_instance": "93fd69daa457477ba979c4be4e21dfdd", "hostUuid": "f8271f58468b4281a212a43e530b5535", "instance": "172.20.1.46:9103", "job": "collectd", "type": "hdc", "virt": "93fd69daa457477ba979c4be4e21dfdd" }, { "__name__": "collectd:collectd_virt_disk_ops_write", "exported_instance": "93fd69daa457477ba979c4be4e21dfdd", "hostUuid": "f8271f58468b4281a212a43e530b5535", "instance": "172.20.1.46:9103", "job": "collectd", "type": "vda", "virt": "93fd69daa457477ba979c4be4e21dfdd" } ], "status": "success" }, "jobUuid": "6bb7e09be71d4ad6b786348e1a8d6944", "success": true }

|名字|类型|描述|起始版本| |--|--|--|----| |inventories|Map| |0.6| |error|ErrorCode|错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error|0.6|

#error

|名字|类型|描述|起始版本| |--|--|--|----| |code|String|错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001|0.6| |description|String|错误的概要描述|0.6| |details|String|错误的详细信息|0.6| |elaboration|String|保留字段,默认为null|0.6| |opaque|LinkedHashMap|保留字段,默认为null|0.6| |cause|ErrorCode|根错误,引发当前错误的源错误,若无原错误,该字段为null|0.6|

SDK示例

Java SDK

PrometheusQueryMetadataAction action = new PrometheusQueryMetadataAction(); action.sessionId = "fcd8fefc495546c0a3551c74762a6259"; PrometheusQueryMetadataAction.Result res = action.call();

Python SDK

PrometheusQueryMetadataAction action = PrometheusQueryMetadataAction() action.sessionId = "472800fc18d04ed283b6ad22ae6dfde0" PrometheusQueryMetadataAction.Result res = action.call()

术语表

区域(Zone)

ZStack中最大的一个资源定义,包括集群、二层网络、主存储等资源。

集群(Cluster)

一个集群是类似物理主机(Host)组成的逻辑组。在同一个集群中的物理主机必须安装相同的操作系统(虚拟机管理程序,Hypervisor),拥有相同的二层网络连接,可以访问相同的主存储。在实际的数据中心,一个集群通常对应一个机架(Rack)。

管理节点(Management Node)

安装系统的物理主机,提供UI管理、云平台部署功能。

计算节点(Compute Node)

也称之为物理主机(或物理机),为云主机实例提供计算、网络、存储等资源的物理主机。

主存储(Primary Storage)

用于存储云主机磁盘文件的存储服务器。支持本地存储、NFS、 Ceph、FusionStor、Shared Mount Point等类型。

镜像服务器(Backup Storage)

也称之为备份存储服务器,主要用于保存镜像模板文件。建议单独部署镜像服务器。

镜像仓库(Image Store)

镜像服务器的一种类型,可以为正在运行的云主机快速创建镜像,高效管理云主机镜像的版本变迁以及发布,实现快速上传、下载镜像,镜像快照,以及导出镜像的操作。

云主机(VM Instance)

运行在物理机上的虚拟机实例,具有独立的IP地址,可以访问公共网络,运行应用服务。

镜像(Image)

云主机或云盘使用的镜像模板文件,镜像模板包括系统云盘镜像和数据云盘镜像。

云盘(Volume)

云主机的数据盘,给云主机提供额外的存储空间,共享云盘可挂载到一个或多个云主机共同使用。

计算规格(Instance Offering)

启动云主机涉及到的CPU数量、内存、网络设置等规格定义。

云盘规格(Disk Offering)

创建云盘容量大小的规格定义。

二层网络(L2 Network)

二层网络对应于一个二层广播域,进行二层相关的隔离。一般用物理网络的设备名称标识。

三层网络(L3 Network)

云主机使用的网络配置,包括IP地址范围、网关、DNS等。

公有网络(Public Network)

由因特网信息中心分配的公有IP地址或者可以连接到外部互联网的IP地址。

私有网络(Private Network)

云主机连接和使用的内部网络。

L2NoVlanNetwork

物理主机的网络连接不采用Vlan设置。

L2VlanNetwork

物理主机节点的网络连接采用Vlan设置,Vlan需要在交换机端提前进行设置。

VXLAN网络池(VXLAN Network Pool)

VXLAN网络中的 Underlay 网络,一个 VXLAN 网络池可以创建多个 VXLAN Overlay 网络(即 VXLAN 网络),这些 Overlay 网络运行在同一组 Underlay 网络设施上。

VXLAN网络(VXLAN)

使用 VXLAN 协议封装的二层网络,单个 VXLAN 网络需从属于一个大的 VXLAN 网络池,不同 VXLAN 网络间相互二层隔离。

云路由(vRouter)

云路由通过定制的Linux云主机来实现的多种网络服务。

安全组(Security Group)

针对云主机进行第三层网络的防火墙控制,对IP地址、网络包类型或网络包流向等可以设置不同的安全规则。

弹性IP(EIP)

公有网络接入到私有网络的IP地址。

快照(Snapshot)

某一个时间点上某一个磁盘的数据备份。包括自动快照和手动快照两种类型。

相关文档

咨询

021-61733682

400-962-2212