更新

说明

object template.update(object/array **templates**)

此方法允许更新现有模板。

参数

(object/array)需要被更新的模板属性。

必须为每个模板定义templateid属性,所有其他属性都是可选的。

只有给定的属性将被更新,所有其他属性将保持不变。

standard template properties之外,该方法接受以下参数。

参数类型说明
groupsobject/array替换所属模板的当前主机组
主机组必须已定义groupid属性。
tagsobject/array模板标签替换当前的模板标签。
hostsobject/array替换当前链接模板的主机模板
主机和模板都必须使用hostid属性传递唯一ID。
macrosobject/array替换指定模板上的当前用户宏
templatesobject/array用于替换当前链接的模板,未通过的模板只是被取消链接。
模板必须已定义templateid属性。
templates_clearobject/array从指定模板中取消链接并清除数据。
模板必须已定义templateid属性。

返回值

(object)返回一个对象,此对象包含在templateids属性中已更新模板的ID。

范例

重命名模板

将模板重命名为“Template OS Linux”。

Request 请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.update",
  4. "params": {
  5. "templateid": "10086",
  6. "name": "Template OS Linux"
  7. },
  8. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  9. "id": 1
  10. }

Response 响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "templateids": [
  5. "10086"
  6. ]
  7. },
  8. "id": 1
  9. }

更新模板标签

用新模板替换所有模板标签。

Request 请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.update",
  4. "params": {
  5. "templateid": "10086",
  6. "tags": [
  7. {
  8. "tag": "Host name",
  9. "value": "{HOST.NAME}"
  10. }
  11. ]
  12. },
  13. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  14. "id": 1
  15. }

Response 响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "hostids": [
  5. "10086"
  6. ]
  7. },
  8. "id": 1
  9. }

源码

CTemplate::update()方法可在ui/include/classes/api/services/CTemplate.php中参考。