更新

描述

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”,可见名称更改为“我的模板”,并更新模板描述。

请求:

{
           "jsonrpc": "2.0",
           "method": "template.update",
           "params": {
               "templateid": "10086",
               "host": "Linux by Zabbix agent Custom",
               "name": "我的模板",
               "description": "这是一个自定义的Linux模板。"
           },
           "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
       }

清除模板关联的模板

从特定的关联模板中解除链接并清除给定的模板。

请求:

{
           "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.