This is a translation of the original English documentation page. Help us make it better.

host.update

Description

object host.update(object/array hosts)

This method allows to update existing hosts.

This method is only available to Admin and Super admin user types. Permissions to call the method can be revoked in user role settings. See User roles for more information.

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.

Parameter Type Description
groups object/array Host 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.
interfaces object/array Host interfaces to replace the current host interfaces.

All interfaces that are not listed in the request will be removed.
tags object/array Host tags to replace the current host tags.

All tags that are not listed in the request will be removed.
inventory object Host inventory properties.
macros object/array User macros to replace the current user macros.

All macros that are not listed in the request will be removed.
templates object/array Templates 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_clear object/array Templates 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.

Valori di ritorno

(object) Restituisce un oggetto contenente gli ID degli host aggiornati sotto la proprietà hostids.

Esempi

Enabling a host

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

Request:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10126",
               "status": 0
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

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

Unlinking templates

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:

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

Updating host macros

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",
                       "description": "Updated description"
                   }
               ]
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

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

Updating host inventory

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:

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

Updating host tags

Replace all host tags with a new one.

Request:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10387",
               "tags": {
                   "tag": "OS",
                   "value": "CentOS 7"
               }
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

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

Updating discovered host macros

Convert discovery rule created "automatic" macro to "manual" and change its value to "new-value".

Request:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10387",
               "macros": {
                   "hostmacroid": "5541",
                   "value": "new-value",
                   "automatic": "0"
               }
           },
           "auth": "038e1d7b1735c6a5436ee9eae095879e",
           "id": 1
       }

Response:

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

Updating host encryption

Update the host "10590" to use PSK encryption only for connections from host to Zabbix server. In addition, update the PSK identity and PSK key for this host. Note that the Zabbix agent that is installed on the host has to be configured to use PSK.

Request:

{
           "jsonrpc": "2.0",
           "method": "host.update",
           "params": {
               "hostid": "10590",
               "tls_connect": 1,
               "tls_accept": 2,
               "tls_psk_identity": "PSK 002",
               "tls_psk": "e560cb0d918d26d31b4f642181f5f570ad89a390931102e5391d08327ba434e9"
           },
           "id": 1
       }

Response:

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

See also

Fonte

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