更新

说明

object template.update(object/array templates)

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

参数

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

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

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

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

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

返回值

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

范例

重命名模板

将模板重命名为"Template OS Linux"。

Request 请求:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "name": "Template OS Linux"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response 响应:

{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10086"
        ]
    },
    "id": 1
}

更新模板标签

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

Request 请求:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "tags": [
            {
                "tag": "Host name",
                "value": "{HOST.NAME}"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

Response 响应:

{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10086"
        ]
    },
    "id": 1
}

源码

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