批量更新模板

描述

object template.massupdate(object parameters)

此方法允许同时替换或删除相关对象,并更新多个模板上的属性。

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

参数

(object) 参数包含要更新的模板ID和要替换的模板对象。

该方法接受以下参数.

参数 类型 描述
templates
(必须)
object/array 要更新的模版。

模版必须有已定义的templateid属性。
groups object/array 用于替换模板所属的当前主机群组的主机群组。

主机群组必须有已定义的groupid属性。
macros object/array 用户宏替换给定模板上的当前用户宏。
templates_clear object/array 取消链接并清除给定模板的模板。

模版必须有已定义的templateid属性。
templates_link object/array 替换当前链接的模板的模板。

模版必须有已定义的templateid属性。

返回值

(object) 返回一个对象,该对象包含templateids属性下已更新模板的ID。

示例

Unlinking a template

Unlink and clear template "10091" from the given templates.

Request:

{
    "jsonrpc": "2.0",
    "method": "template.massupdate",
    "params": {
        "templates": [
            {
                "templateid": "10085"
            },
            {
                "templateid": "10086"
            }
        ],
        "templates_clear": [
            {
                "templateid": "10091"
            }
        ]
    },
    "id": 1
}

Response:

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

替换主机群组

从给定模板中取消链接并清除模板“10091”。

请求:

{
    "jsonrpc": "2.0",
    "method": "template.massupdate",
    "params": {
        "templates": [
            {
                "templateid": "10085"
            },
            {
                "templateid": "10086"
            }
        ],
        "templates_clear": [
            {
                "templateid": "10091"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

响应:

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

参阅

源码

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