object host.update(object/array hosts)
This method allows to update existing hosts.该方法允许更新目前的主机。
(object/array)
Host properties to be updated. 需要更新的主机属性。
The hostid
property must be defined for each host, all other properties are optional. Only the given properties will be updated, all others will remain unchanged.每一个主机的hostid属性必须已定义过,其他属性为可选项。Only the given properties will be updated, all others will remain unchanged. 仅指定属性会被更新,其他属性保持不变。
Additionally to the standard host properties, the method accepts the following parameters.另外,对于标准主机属性,此方法接受以下参数。
参数 类 | 说明 | |
---|---|---|
groups | object/array | Host groups to replace the current host groups the host belongs to. 替换当前主机所属主机组。 The host groups must have the groupid property defined.主机组必须已定义过groupid属性 |
interfaces | object/array | Host interfaces to replace the current host interfaces. 替换当前主机接口。 |
inventory | object | Host inventory properties.主机资产清单属性。 |
macros | object/array | User macros to replace the current user macros.替换当前用户宏。 |
templates | object/array | Templates to replace the currently linked templates. Templates that are not passed are only unlinked. 替换当前链接的模板。 模板没有传递仅删除链接。 The templates must have the templateid property defined.模板必须已定义过templateid属性。 |
templates_clear | object/array | Templates to unlink and clear from the host. 从主机中删除模板链接并清除。 The templates must have the templateid property defined.模板必须已定义过templateid属性。 |
As opposed to the Zabbix frontend, when name
is the same as host
, updating host
will not automatically update name
. Both properties need to be updated explicitly.相对于Zabbix前端,当name和host一致,更新host的时候不会自动更新name。两个属性需要明确的更新。
(object)
Returns an object containing the IDs of the updated hosts under the hostids
property.返回一个对象其中包含在hostids属性下已更新主机的ID。
Enable host monitoring, i.e. set its status to 0.启用主机监控,例如,把主机状态设置为0。
Request:
{
"jsonrpc": "2.0",
"method": "host.update",
"params": {
"hostid": "10092",
"status": 0
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
Unlink and clear two templates from host.从主机中删除链接并清除两个模板。
Request:
{
"jsonrpc": "2.0",
"method": "host.update",
"params": {
"hostid": "10126",
"templates_clear": [
{
"templateid": "10124"
},
{
"templateid": "10125"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
Replace all host macros with two new ones.用两个新的宏替换主机所有的宏。
Request:
{
"jsonrpc": "2.0",
"method": "host.update",
"params": {
"hostid": "10126",
"macros": [
{
"macro": "{$PASS}",
"value": "password"
},
{
"macro": "{$DISC}",
"value": "sda"
}
]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
Change inventory mode and add location更改资产清单模式并添加地点。
Request:
{
"jsonrpc": "2.0",
"method": "host.update",
"params": {
"hostid": "10387",
"inventory_mode": 0,
"inventory": {
"location": "Latvia, Riga"
}
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
CHost::update() in frontends/php/include/classes/api/services/CHost.php.