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.
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. |
interfaces | object/array | Host interfaces to replace the current host interfaces. The method accepts a single interface object starting from 2.0.2. |
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. |
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
is the same as host
, updating host
will not automatically update name
. Both properties need to be updated explicitly.
(object)
Returns an object containing the IDs of the updated hosts under the hostids
property.
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:
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/api/classes/CHost.php.