object template.update(object/array templates)
此方法允许更新现有模板。
此方法仅适用于管理员和超级管理员用户类型。调用该方法的权限可在用户角色设置中撤销。更多信息请参阅User roles。
(object/array)
待更新的模板属性
每个模板必须定义 templateid
属性,其他属性均为可选。仅指定的属性会被更新,其余属性将保持不变。
除 模板 外,该方法还接受以下参数。
参数 | 数据类型 | 说明 |
---|---|---|
groups | object/array | 主机 groups 用于替换模板当前所属的 主机 组。 主机 组必须定义 groupid 属性。 |
tags | object/array | 模板 模板标签 用于替换当前模板标签。 |
macros | object/array | User macros 用于替换指定模板上的当前用户宏。 |
templates | object/array | Templates 用于替换当前链接的模板。未传递的模板仅会被取消链接。 模板必须定义 templateid 属性。 |
templates_clear | object/array | Templates 用于从指定模板取消链接并清除。 模板必须定义 templateid 属性。 |
(object)
返回一个包含更新模板ID的object,存储在templateids
属性下。
将模板的技术名称更改为"由Zabbix agent定制的Linux",可见名称改为"我的模板",并更新模板描述。
请求:
{
"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."
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
将指定模板的所有模板组替换为其他模板组。
请求:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"groups": [
{
"groupid": "24"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
将所有模板标签替换为不同的标签。
请求:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"tags": [
{
"tag": "Host name",
"value": "{HOST.NAME}"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
将所有模板宏替换为不同的宏。
请求:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"macros": [
{
"macro": "{$MY_MACRO}",
"value": "new_value"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
从指定模板中解除(不清除)所有关联模板,并为其关联另一个不同的模板。
请求:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"templates": [
{
"templateid": "10087"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
从特定关联模板中解除并清除指定模板。
请求:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"templates_clear": [
{
"templateid": "10087"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
CTemplate::update() 位于 ui/include/classes/api/services/CTemplate.php 文件中。