host.update

Description 说明

object host.update(object/array hosts)

This method allows to update existing hosts.该方法允许更新目前的主机。

Parameters参数

(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。两个属性需要明确的更新。

Return values返回值

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

Examples 范例

Enabling a host启用一个主机

Enable host monitoring, i.e. set its status to 0.启用主机监控,例如,把主机状态设置为0。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.update",
  4. "params": {
  5. "hostid": "10092",
  6. "status": 0
  7. },
  8. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  9. "id": 1
  10. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "hostids": [
  5. "10126"
  6. ]
  7. },
  8. "id": 1
  9. }

Unlinking templates 删除模板链接

Unlink and clear two templates from host.从主机中删除链接并清除两个模板。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.update",
  4. "params": {
  5. "hostid": "10126",
  6. "templates_clear": [
  7. {
  8. "templateid": "10124"
  9. },
  10. {
  11. "templateid": "10125"
  12. }
  13. ]
  14. },
  15. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  16. "id": 1
  17. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "hostids": [
  5. "10126"
  6. ]
  7. },
  8. "id": 1
  9. }

Updating host macros更新主机的宏

Replace all host macros with two new ones.用两个新的宏替换主机所有的宏。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.update",
  4. "params": {
  5. "hostid": "10126",
  6. "macros": [
  7. {
  8. "macro": "{$PASS}",
  9. "value": "password"
  10. },
  11. {
  12. "macro": "{$DISC}",
  13. "value": "sda"
  14. }
  15. ]
  16. },
  17. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  18. "id": 1
  19. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "hostids": [
  5. "10126"
  6. ]
  7. },
  8. "id": 1
  9. }

Updating host inventory 更新主机资产清单

Change inventory mode and add location更改资产清单模式并添加地点。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.update",
  4. "params": {
  5. "hostid": "10387",
  6. "inventory_mode": 0,
  7. "inventory": {
  8. "location": "Latvia, Riga"
  9. }
  10. },
  11. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  12. "id": 1
  13. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "hostids": [
  5. "10387"
  6. ]
  7. },
  8. "id": 2
  9. }

See also 参见

Source 来源

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