# host.massupdate

### Description 说明

`object host.massupdate(object parameters)`

This method allows to simultaneously replace or remove related objects
and update properties on multiple
hosts.此方法允许同时替换或移除相关对象和在多个主机中更新属性。

### Parameters 参数

`(object)` Parameters containing the IDs of the hosts to update and the
properties that should be updated.
参数包含更新主机的ID和需要更新的属性。

Additionally to the [standard host properties](object#host), the method
accepts the following
parameters.另外，对于标准主机属性，此方法接受以下参数。

|参数               类|说明|<|
|------------------------|------|-|
|**hosts**<br>(required)|object/array|Hosts to be updated.需要更新的主机。<br><br>The hosts must have the `hostid` property defined.主机必须已定义过hostid属性。|
|groups|object/array|Host groups to replace the current host groups the hosts belong to. 替换当前主机所属主机组。<br><br>The host groups must have the `groupid` property defined. 主机组必须已定义过groupid属性。|
|interfaces|object/array|Host interfaces to replace the current host interfaces on the given hosts.在指定主机上替换当前主机接口。|
|inventory|object|Host inventory properties.主机资产清单属性。<br><br>Host inventory mode cannot be updated using the `inventory` parameter, use `inventory_mode` instead.使用参数inventory无法更新主机资产清单模式，用参数inventory\_mode替换|
|inventory\_mode|integer|Host inventory population mode. 主机资产清单群体模式。<br><br>Refer to the [host inventory object page](object#host_inventory) for a list of supported inventory modes.参考host inventory object page支持的资产清单模式列表|
|macros|object/array|User macros to replace the current user macros on the given hosts. 在指定主机中替换当前用户宏。|
|templates|object/array|Templates to replace the currently linked templates on the given hosts. 在指定主机中替换当前链接的模板。<br><br>The templates must have the `templateid` property defined. 模板必须已定义过templateid属性。|
|templates\_clear|object/array|Templates to unlink and clear from the given hosts. 在指定主机中删除模板链接并清除。<br><br>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 范例

#### Enabling multiple hosts 启用多个主机

Enable monitoring of two hosts, i.e., set their status to
0.启用两个主机的监控，例如，把这两个主机的状态设置为0。

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "host.massupdate",
    "params": {
        "hosts": [
            {
                "hostid": "69665"
            },
            {
                "hostid": "69666"
            }
        ],
        "status": 0
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "69665",
            "69666"
        ]
    },
    "id": 1
}
```

### See also 参见

-   [host.update](update)
-   [host.massadd](massadd)
-   [host.massremove](massremove)
-   [Host group](/manual/api/reference/hostgroup/object#host_group)
-   [Template](/manual/api/reference/template/object#host_group)
-   [User
    macro](/manual/api/reference/usermacro/object#hosttemplate_level_macro)
-   [Host
    interface](/manual/api/reference/hostinterface/object#host_interface)

### Source 来源

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