2022 Zabbix中国峰会
2022 Zabbix中国峰会

批量添加

Description 说明

object template.massadd(object parameters)

This method allows to simultaneously add multiple related objects to the given templates. 此方法允许同时替换或删除相关对象并更新多个模板上的属性。

Parameters 参数

(object) Parameters containing the IDs of the templates to update and the objects to add to the templates. (object)参数包含需要更新的模板ID以及添加到模板的对象。 The method accepts the following parameters. 该方法接受以下参数。

Parameter 参数 T pe 类型 Des ription 说明
templates
(required 必须)
object/array 对象/数组 Tem
lates to be updated. 需要更新的模板。
The templates must have the templateid property defined. 模板必须定义templateid属性。
groups object/array 对象/数组 Hos groups to add the given templates to. 主机组添加指定的模板。

The host groups must have the groupid property defined. 主机组必须定义groupid属性。
hosts object/array 对象/数组 Hos s and templates to link the given templates to. 将主机和模板链接到指定的模板中。

The hosts must have the hostid property defined. 主机必须定义hostid属性。
macros object/array 对象/数组 Use macros to be created for the given templates. 为指定的模板创建用户宏。
templates_link object/array 对象/数组 Tem lates to link to the given templates. 将模板链接到指定模板。

The templates must have the templateid property defined. 模板必须定义templateid属性。

Return values 返回值

(object) Returns an object containing the IDs of the updated templates under the templateids property. (object)返回一个对象,此对象包含在templateids属性中已更新模板的ID。

Examples 范例

Adding templates to a group 添加模板到组

Add two templates to the host group "2". 添加两个模板到ID为"2"的主机组中。

Request 请求:

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

Response 响应:

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

Linking a template to hosts 链接模板到主机

Link template "10073" to two hosts. 链接ID为"10073"的模板到两台主机。

Request 请求:

{
           "jsonrpc": "2.0",
           "method": "template.massadd",
           "params": {
               "templates": [
                   {
                       "templateid": "10073"
                   }
               ],
               "hosts": [
                   {
                       "hostid": "10106"
                   },
                   {
                       "hostid": "10104"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response 响应:

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

See also 参考

Source 源码

CTemplate::massAdd() in frontends/php/include/classes/api/services/CTemplate.php. CTemplate::massAdd()方法可在//frontends/php/include/classes/api/services/CTemplate.php中参考。