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.

Note, however, that updating the host technical name will also update the host’s visible name (if not given or empty) by the host’s technical name value.

Additionally to the standard host properties, the method accepts the following parameters.

ParameterTypeDescription
groupsobject/arrayHost groups to replace the current host groups the host belongs to.

The host groups must have the groupid property defined. All host groups that are not listed in the request will be unlinked.
interfacesobject/arrayHost interfaces to replace the current host interfaces.

All interfaces that are not listed in the request will be removed.
tagsobject/arrayHost tags to replace the current host tags.

All tags that are not listed in the request will be removed.
inventoryobjectHost inventory properties.
macrosobject/arrayUser macros to replace the current user macros.

All macros that are not listed in the request will be removed.
templatesobject/arrayTemplates to replace the currently linked templates. All templates that are not listed in the request will be only unlinked.

The templates must have the templateid property defined.
templates_clearobject/arrayTemplates to unlink and clear from the host.

The templates must have the templateid property defined.

As opposed to the Zabbix frontend, when name (visible host name) is the same as host (technical host name), updating host via API will not automatically update name. Both properties need to be updated explicitly.

Return values

(object) Returns an object containing the IDs of the updated hosts under the hostids property.

Examples

Enabling a host

Enable host monitoring, i.e. set its status to 0.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.update",
  4. "params": {
  5. "hostid": "10126",
  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. "description": "Updated description"
  15. }
  16. ]
  17. },
  18. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  19. "id": 1
  20. }

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": 1
  9. }

Updating host tags

Replace all host tags with a new one.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.update",
  4. "params": {
  5. "hostid": "10387",
  6. "tags": {
  7. "tag": "OS",
  8. "value": "CentOS 7"
  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": 1
  9. }

See also

Source

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