object template.update(object/array templates)
此方法用于 update 现有模板。
此方法仅适用于 Admin 和 Super admin 用户类型。调用该方法的权限可以在用户角色设置中撤销。更多信息请参见 User roles。
(object/array)
要更新的模板属性。
每个模板必须定义 templateid
属性,所有其他属性都是可选的。只有给定的属性将被更新,其他属性将保持不变。
除了 模板 中列出的参数外,该方法还接受以下参数。
参数 | 数据类型 | 描述 |
---|---|---|
groups | object/array | Template groups,用于替换模板当前所属的模板组。 模板组必须仅定义 groupid 属性。 |
tags | object/array | 模板标签,用于替换当前模板标签。 |
macros | object/array | User macros,用于替换给定模板上的当前用户宏。 |
templates | object/array | Templates,用于替换当前链接的模板。未传递的模板将被解除链接。 模板必须仅定义 templateid 属性。 |
templates_clear | object/array | Templates,用于解除链接并从给定模板中 clear。 模板必须仅定义 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", "method": "template.update", "params": { "templateid": "10086", "groups": [ { "groupid": "24" } ] }, "id": 1 }
响应:
替换所有模板标签为不同的标签。
执行请求:
{ "jsonrpc": "2.0", "method": "template.update", "params": { "templateid": "10086", "tags": [ { "tag": "host-name", "value": "{HOST.NAME}" } ] }, "id": 1 }
响应:
将所有模板宏替换为另一个宏。
执行请求:
{ "jsonrpc": "2.0", "method": "template.update", "params": { "templateid": "10086", "macros": [ { "macro": "{$MY_MACRO}", "value": "new_value" } ] }, "id": 1 }
响应:
从给定模板中取消链接(不进行清除)所有模板,并链接另一个模板到该模板。
执行请求:
{ "jsonrpc": "2.0", "method": "template.update", "params": { "templateid": "10086", "templates": [ { "templateid": "10087" } ] }, "id": 1 }
响应:
解除与给定模板的链接,并从特定的已链接模板中clear该模板。
执行请求:
{ "jsonrpc": "2.0", "method": "template.update", "params": { "templateid": "10086", "templates_clear": [ { "templateid": "10087" } ] }, "id": 1 }
响应:
CTemplate::update() 在 ui/include/classes/api/services/CTemplate.php 中。