template.update

描述

object template.update(object/array templates)

此方法用于 update 现有模板。

此方法仅适用于 AdminSuper admin 用户类型。调用该方法的权限可以在用户角色设置中撤销。更多信息请参见 User roles

参数

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

必须为每个模板定义 templateid 属性,其他所有属性均为可选。只有给定的属性会被更新,其余所有属性将保持不变。

除了标准模板属性之外,该方法还接受以下参数。

Parameter Type Description
groups object/array 用于替换模板当前所属模板组的模板组

模板组只能定义 groupid 属性。
tags object/array 用于替换当前模板标签的模板标签
macros object/array 用于替换给定模板上当前用户宏的用户宏
templates object/array 用于替换当前关联模板的模板。未传入的模板只会解除关联。

模板只能定义 templateid 属性。
templates_clear object/array 用于解除关联并从给定模板中清除的模板

模板只能定义 templateid 属性。

返回值

(object) 返回一个 object,其中包含在 templateids 属性下更新的模板的 ID。

示例

更改标准模板属性

将模板的技术名称更改为"由Zabbix agent定制的Linux",可见名称改为"我的模板",并update模板描述。

执行请求:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "host": "Linux by Zabbix agent Custom",
        "name": "My template",
        "description": "This is a custom Linux template."
    },
    "id": 1
}

响应:

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

更新模板组

将给定模板的所有模板组替换为另一个模板组。

执行请求:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "groups": [
            {
                "groupid": "24"
            } 
        ]
    },
    "id": 1
}

响应:

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

更新模板标签

替换所有模板标签为不同的标签。

执行请求:

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

响应:

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

更新模板宏

将所有模板宏替换为另一个宏。

执行请求:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "macros": [
            {
                "macro": "{$MY_MACRO}",
                "value": "new_value"
            }
        ]
    },
    "id": 1
}

响应:

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

更新模板链接模板

从给定模板中取消链接(不进行清除)所有模板,并链接另一个模板到该模板。

执行请求:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "templates": [
            {
                "templateid": "10087"
            }
        ]
    },
    "id": 1
}

响应:

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

清除模板链接模板

解除与给定模板的链接,并从特定的已链接模板中clear该模板。

执行请求:

{
    "jsonrpc": "2.0",
    "method": "template.update",
    "params": {
        "templateid": "10086",
        "templates_clear": [
            {
                "templateid": "10087"
            }
        ]
    },
    "id": 1
}

响应:

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

来源

CTemplate::update() 在 ui/include/classes/api/services/CTemplate.php 中。