[comment]: # ({c572a02a-c572a02a})
# host.update

[comment]: # ({/c572a02a-c572a02a})

[comment]: # ({a740c7d4-12e31652})
### Apraksts

`object host.update(object/array hosts)`

Šī metode ļauj atjaunināt esošos hostus.

::: noteclassic
Šī metode ir pieejama tikai *Admin* un *Super admin*
lietotāju tipiem. Atļaujas izsaukt šo metodi var tikt atsauktas lietotāja lomas
iestatījumos. Plašāku informāciju skatiet [Lietotāju
lomas](/manual/web_interface/frontend_sections/users/user_roles).
:::

[comment]: # ({/a740c7d4-12e31652})

[comment]: # ({7c7a9b0d-3a8eac6a})
### Parametri

`(object/array)` Atjaunināmie hosta rekvizīti.

Katram hostam jābūt definētam rekvizītam `hostid`, visi pārējie
rekvizīti nav obligāti. Tiks atjaunināti tikai norādītie rekvizīti, visi
pārējie paliks nemainīti.

Tomēr ņemiet vērā, ka, atjauninot hosta tehnisko nosaukumu, tiks atjaunināts
arī hosta redzamais nosaukums (ja tas nav norādīts atsevišķi), izmantojot hosta tehniskā
nosaukuma vērtību.

Papildus [standarta hosta rekvizītiem](object#host) metode
pieņem šādus parametrus.

|Parametrs|[Tips](/manual/api/reference_commentary#data-types)|Apraksts|
|--|--|------|
|groups|object/array|[Hostu grupas](/manual/api/reference/hostgroup/object#host-group), ar kurām aizstāt pašreizējās hostu grupas, kurām hosts pieder.<br>Visu hostu grupu saites, kas pieprasījumā nav norādītas, tiks noņemtas.<br><br>Hostu grupām jābūt definētam tikai rekvizītam `groupid`.|
|interfaces|object/array|[Hostu saskarnes](/manual/api/reference/hostinterface/object), ar kurām aizstāt pašreizējās hostu saskarnes.<br>Visas saskarnes, kas pieprasījumā nav norādītas, tiks noņemtas.|
|tags|object/array|[Hostu birkas](/manual/api/reference/host/object#host-tag), ar kurām aizstāt pašreizējās hostu birkas.<br>Visas birkas, kas pieprasījumā nav norādītas, tiks noņemtas.|
|inventory|object|[Hosta inventarizācijas](/manual/api/reference/host/object#host-inventory) rekvizīti.|
|macros|object/array|[Lietotāja makrosi](/manual/api/reference/usermacro/object), ar kuriem aizstāt pašreizējos lietotāja makrosus.<br>Visi makrosi, kas pieprasījumā nav norādīti, tiks noņemti.|
|templates|object/array|[Veidnes](/manual/api/reference/template/object), ar kurām aizstāt pašlaik piesaistītās veidnes.<br>Visām veidnēm, kas pieprasījumā nav norādītas, tiks tikai noņemta saite.<br><br>Veidnēm jābūt definētam tikai rekvizītam `templateid`.|
|templates\_clear|object/array|[Veidnes](/manual/api/reference/template/object), kurām noņemt saiti un notīrīt no hosta.<br><br>Veidnēm jābūt definētam tikai rekvizītam `templateid`.|

[comment]: # ({/7c7a9b0d-3a8eac6a})

[comment]: # ({d166b99b-d166b99b})
### Atgrieztās vērtības

`(object)` Atgriež objektu, kas satur atjaunināto hostu ID
zem `hostids` īpašības.

[comment]: # ({/d166b99b-d166b99b})

[comment]: # ({b41637d2-b41637d2})
### Piemēri

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({bcd7b728-ce50c453})
#### Hosta iespējošana

Iespējojiet hosta uzraudzību, tas ir, iestatiet tā statusu uz "0".

[Pieprasījums](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10126",
        "status": 0
    },
    "id": 1
}
```

Atbilde:

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

[comment]: # ({/bcd7b728-ce50c453})

[comment]: # ({56f46465-bea1db7e})
#### Veidņu atsaistīšana

Atsaistīt un notīrīt divas veidnes no hosta.

[Pieprasījums](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10126",
        "templates_clear": [
            {
                "templateid": "10124"
            },
            {
                "templateid": "10125"
            }
        ]
    },
    "id": 1
}
```

Atbilde:

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

[comment]: # ({/56f46465-bea1db7e})

[comment]: # ({b789e636-98dcfd68})
#### Hosta makrosu atjaunināšana

Aizstājiet visus hosta makrosus ar diviem jauniem.

[Pieprasījums](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10126",
        "macros": [
            {
                "macro": "{$PASS}",
                "value": "password"
            },
            {
                "macro": "{$DISC}",
                "value": "sda",
                "description": "Atjaunināts apraksts"
            }
        ]
    },
    "id": 1
}
```

Atbilde:

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

[comment]: # ({/b789e636-98dcfd68})

[comment]: # ({72eb8ecc-da99f3b8})
#### Hosta inventāra atjaunināšana

Mainiet inventāra režīmu un pievienojiet atrašanās vietu

[Pieprasījums](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10387",
        "inventory_mode": 0,
        "inventory": {
            "location": "Latvia, Riga"
        }
    },
    "id": 1
}
```

Atbilde:

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

[comment]: # ({/72eb8ecc-da99f3b8})

[comment]: # ({603ba164-5cc5d950})
#### Hosta birku atjaunināšana

Aizstājiet visas hosta birkas ar jaunu birku.

[Pieprasījums](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10387",
        "tags": {
            "tag": "os",
            "value": "rhel-7"
        }
    },
    "id": 1
}
```

Atbilde:

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

[comment]: # ({/603ba164-5cc5d950})

[comment]: # ({58eba4cd-ae2d89bf})
#### Atklāto hostu makrosu atjaunināšana

Pārveidojiet atklāšanas kārtulas izveidoto "automatic" makrosu par "manual" un nomainiet tā vērtību uz "new-value".

[Pieprasījums](/manual/api#performing-requests):

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

Atbilde:

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

[comment]: # ({/58eba4cd-ae2d89bf})

[comment]: # ({1948c7c9-f620e859})
#### Hosta šifrēšanas atjaunināšana

Atjauniniet hostu "10590", lai tas izmantotu tikai PSK šifrēšanu savienojumiem no hosta uz Zabbix serveri, un nomainiet PSK identitāti un PSK atslēgu.
Ņemiet vērā, ka hostam jābūt [iepriekš konfigurētam PSK izmantošanai](/manual/encryption/using_pre_shared_keys#configuring-psk-for-server-agent-communication-example).

[Pieprasījums](/manual/api#performing-requests):

```json
{
    "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
}
```

Atbilde:

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

[comment]: # ({/1948c7c9-f620e859})

[comment]: # ({78cf261e-23501347})
### Skatīt arī

-   [host.massadd](massadd)
-   [host.massupdate](massupdate)
-   [host.massremove](massremove)
-   [Hosts grupa](/manual/api/reference/hostgroup/object#host-group)
-   [Veidne](/manual/api/reference/template/object#template)
-   [Lietotāja makro](/manual/api/reference/usermacro/object#hosttemplate-level-macro)
-   [Hosts interfeiss](/manual/api/reference/hostinterface/object#host-interface)
-   [Hosts inventārs](object#host-inventory)
-   [Hosts tags](object#host-tag)
-   [Starpniekserveris](/manual/api/reference/proxy/object#proxy)
-   [Starpniekserveru grupa](/manual/api/reference/proxygroup/object#proxy-group)

[comment]: # ({/78cf261e-23501347})

[comment]: # ({a39b5a01-a39b5a01})
### Avots

CHost::update() failā *ui/include/classes/api/services/CHost.php*.

[comment]: # ({/a39b5a01-a39b5a01})
