object template.update(object/array templates)
此方法允许update现有模板.
此方法仅适用于管理员和超级管理员 用户类型. 调用该方法的权限可在用户角色 设置中撤销. 更多信息请参阅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 用于解除链接并从给定模板中 clear。 模板必须定义 templateid 属性。 |
(object)
返回一个包含更新模板ID的object 该ID位于templateids
属性下
将模板的技术名称更改为"Linux by Zabbix agent Custom",可见名称改为"My template",并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."
},
"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
}
响应:
解除关联并从特定关联模板中clear给定模板。
请求:
{
"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 文件中。