更新
描述
object template.update(object/array templates)
这个方法可以更新已经存在的模版。
这个方法只有 管理员 和 超级管理员 用户类型可以使用。可以在用户角色设置中取消调用该方法的权限。查看 用户角色获取更多信息。
参数
(object/array) 要更新的模板属性。
必须为每个模板定义 templateid 属性,其他所有属性均为可选。
只有给定的属性会被更新,其他所有属性将保持不变。
除了标准模板属性之外, 该方法还接受以下参数。
| 参数 | 类型 | 说明 |
|---|---|---|
| groups | object/array | 用于替换模板当前所属模板组的模板组。 模板组必须仅定义 groupid 属性。 |
| tags | object/array | 用于替换当前模板标签的模板标签。 |
| macros | object/array | 用于替换给定模板上当前用户宏的用户宏。 |
| templates | object/array | 用于替换当前已链接模板的模板。未传递的模板将仅被取消链接。 模板必须仅定义 templateid 属性。 |
| templates_clear | object/array | 要从给定模板中取消链接并清除的模板。 模板必须仅定义 templateid 属性。 |
返回值
(object) 返回一个对象,该对象包含templateids属性下已更新模板的ID。
示例
更改标准模板属性
将模板的技术名称更改为 "Linux by Zabbix agent Custom",将可见名称更改为 "My template",并更新模板描述。
请求:
{
"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",
"groups": [
{
"groupid": "24"
}
]
},
{
"templateid": "10087",
"groups": [
{
"groupid": "1"
},
{
"groupid": "12"
}
]
},
{
"templateid": "10088",
"groups": [
{
"groupid": "1"
},
{
"groupid": "12"
}
]
}
],
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": {
"templateids": [
"10086",
"10087",
"10088"
]
},
"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": "10087",
"macros": [
{
"macro": "{$AGENT.TIMEOUT}",
"value": "5m",
"description": "agent 被视为不可用前的超时时间。仅适用于可从 Zabbix 服务器/proxy 访问的 agent(被动模式)。"
}
]
},
{
"templateid": "10088",
"macros": [
{
"macro": "{$AGENT.TIMEOUT}",
"value": "5m",
"description": "agent 被视为不可用前的超时时间。仅适用于可从 Zabbix 服务器/proxy 访问的 agent(被动模式)。"
}
]
}
],
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": {
"templateids": [
"10087",
"10088"
]
},
"id": 1
}
更新模板的已链接模板
取消给定模板与所有模板的链接(不清除),并为其链接另一个模板。
请求:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": {
"templateid": "10086",
"templates": [
{
"templateid": "10001"
}
]
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": {
"templateids": [
"10086"
]
},
"id": 1
}
清除多个模板的已链接模板
从给定模板中取消链接并清除指定的已链接模板。
请求:
{
"jsonrpc": "2.0",
"method": "template.update",
"params": [
{
"templateid": "10087",
"templates_clear": [
{
"templateid": "10001"
}
]
},
{
"templateid": "10088",
"templates_clear": [
{
"templateid": "10001"
}
]
}
],
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": {
"templateids": [
"10087",
"10088"
]
},
"id": 1
}
来源
CTemplate::update() 在 ui/include/classes/api/services/CTemplate.php.