host.massadd

Description说明

object host.massadd(object parameters)

This method allows to simultaneously add multiple related objects to all the given hosts.此方法允许同时添加多个相关对象到指定的主机。

Parameters 参数

(object) Parameters containing the IDs of the hosts to update and the objects to add to all the hosts. 参数包含升级主机的ID和添加到所有主机中的对象。

The method accepts the following parameters.该方法接受以下参数。

参数 类 说明
hosts
(required)
object/array Hosts to be updated.需要更新的主机

The hosts must have the hostid property defined.主机必须已定义过hostid属性。
groups object/array Host groups to add to the given hosts.主机组添加到指定的主机中。

The host groups must have the groupid property defined. 主机组必须已定义过groupid属性。
interfaces object/array Host interfaces to be created for the given hosts.为指定主机创建的主机接口。
macros object/array User macros to be created for the given hosts.为指定主机创建的宏。
templates object/array Templates to link to the given hosts. 链接到指定主机的模板。

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

Return values返回值

(object) Returns an object containing the IDs of the updated hosts under the hostids property.返回一个对象其中包含在hostids属性下已更新主机的ID。

Examples 范例

Adding macros 添加宏

Add two new macros to two hosts.添加两个新的宏到两个主机中。

Request:

{
           "jsonrpc": "2.0",
           "method": "host.massadd",
           "params": {
               "hosts": [
                   {
                       "hostid": "10160"
                   },
                   {
                       "hostid": "10167"
                   }
               ],
               "macros": [
                   {
                       "macro": "{$TEST1}",
                       "value": "MACROTEST1"
                   },
                   {
                       "macro": "{$TEST2}",
                       "value": "MACROTEST2"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "hostids": [
                   "10160",
                   "10167"
               ]
           },
           "id": 1
       }

See also参见

Source 来源

CHost::massAdd() in frontends/php/include/classes/api/services/CHost.php.