批量添加模板

描述

object template.massadd(object parameters)

此方法允许同时向给定模板添加多个相关对象。

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

参数

(object)参数包含要更新的模板ID和要添加到模板的对象的参数。

该方法接受以下参数。

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

模板必须定义templateid属性。
groups object/array 要将给定模板添加到的主机群组。

主机组必须定义groupid属性。
macros object/array 为给定模板创建的用户宏。
templates_link object/array 链接到给定模板的模板。

模板必须定义templateid属性。

返回值

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

示例

将一个群组链接到模板

将主机群组“2”添加到两个模板中。

请求:

{
    "jsonrpc": "2.0",
    "method": "template.massadd",
    "params": {
        "templates": [
            {
                "templateid": "10085"
            },
            {
                "templateid": "10086"
            }
        ],
        "groups": [
            {
                "groupid": "2"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}

响应:

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

Link templates "10106" and "10104" to template "10073".

Request:

{
    "jsonrpc": "2.0",
    "method": "template.massadd",
    "params": {
        "templates": [
            {
                "templateid": "10073"
            }
        ],
        "templates_link": [
            {
                "templateid": "10106"
            },
            {
                "templateid": "10104"
            }
        ]
    },
    "id": 1
}

Response:

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

参阅

源码

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