这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.

更新模板

描述

object template.update(object/array templates)

此方法允许更新现有模板。

此方法仅适用于管理员超级管理员用户类型。可以在用户角色设置中撤销调用该方法的权限。 详情请阅 User roles

参数

(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。

示例

Changing the standard template properties

Change the technical name of the template to "Linux by Zabbix agent Custom", the visible name to "My template", and update the template description.

Request:

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

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "templateids": [
                   "10086"
               ]
           },
           "id": 1
       }

Updating template groups

Replace all template groups for the given template with a different one.

Request:

{
           "jsonrpc": "2.0",
           "method": "template.update",
           "params": {
               "templateid": "10086",
               "groups": [
                   {
                       "groupid": "24"
                   } 
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "templateids": [
                   "10086"
               ]
           },
           "id": 1
       }

Updating template tags

Replace all template tags with a different one.

Request:

{
           "jsonrpc": "2.0",
           "method": "template.update",
           "params": {
               "templateid": "10086",
               "tags": [
                   {
                       "tag": "Host name",
                       "value": "{HOST.NAME}"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "templateids": [
                   "10086"
               ]
           },
           "id": 1
       }

Updating template macros

Replace all template macros with a different one.

Request:

{
           "jsonrpc": "2.0",
           "method": "template.update",
           "params": {
               "templateid": "10086",
               "macros": [
                   {
                       "macro": "{$MY_MACRO}",
                       "value": "new_value"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "templateids": [
                   "10086"
               ]
           },
           "id": 1
       }

Updating template linked templates

Unlink (without clearing) all templates from the given template and link a different one to it.

Request:

{
           "jsonrpc": "2.0",
           "method": "template.update",
           "params": {
               "templateid": "10086",
               "templates": [
                   {
                       "templateid": "10087"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "templateids": [
                   "10086"
               ]
           },
           "id": 1
       }

Clearing template linked templates

Unlink and clear the given template from a specific linked template.

Request:

{
           "jsonrpc": "2.0",
           "method": "template.update",
           "params": {
               "templateid": "10086",
               "templates_clear": [
                   {
                       "templateid": "10087"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "templateids": [
                   "10086"
               ]
           },
           "id": 1
       }

源码

CTemplate::update() in ui/include/classes/api/services/CTemplate.php.