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

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

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

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

Questo metodo consente di aggiornare host esistenti.

::: noteclassic
Questo metodo è disponibile solo per i tipi di utente *Admin* e *Super admin*.
Le autorizzazioni per chiamare il metodo possono essere revocate nelle impostazioni del ruolo utente.
Per ulteriori informazioni, vedere [Ruoli utente](/manual/web_interface/frontend_sections/users/user_roles).
:::

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

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

`(object/array)` Proprietà del host da aggiornare.

La proprietà `hostid` deve essere definita per ogni host, tutte le altre
proprietà sono facoltative. Verranno aggiornate solo le proprietà specificate, tutte
le altre rimarranno invariate.

Si noti tuttavia che l'aggiornamento del nome tecnico del host aggiornerà anche
il nome visibile del host (se non specificato separatamente) con il valore
del nome tecnico del host.

Oltre alle [proprietà standard del host](object#host), il metodo
accetta i seguenti parametri.

|Parameter|[Type](/manual/api/reference_commentary#data-types)|Description|
|--|--|------|
|groups|object/array|[Gruppi di host](/manual/api/reference/hostgroup/object#host-group) per sostituire i gruppi di host correnti a cui il host appartiene.<br>Tutti i gruppi di host non elencati nella richiesta verranno scollegati.<br><br>I gruppi di host devono avere definita solo la proprietà `groupid`.|
|interfaces|object/array|[Interfacce del host](/manual/api/reference/hostinterface/object) per sostituire le interfacce correnti del host.<br>Tutte le interfacce non elencate nella richiesta verranno rimosse.|
|tags|object/array|[Tag del host](/manual/api/reference/host/object#host-tag) per sostituire i tag correnti del host.<br>Tutti i tag non elencati nella richiesta verranno rimossi.|
|inventory|object|Proprietà dell'[inventario del host](/manual/api/reference/host/object#host-inventory).|
|macros|object/array|[Macro utente](/manual/api/reference/usermacro/object) per sostituire le macro utente correnti.<br>Tutte le macro non elencate nella richiesta verranno rimosse.|
|templates|object/array|[Template](/manual/api/reference/template/object) per sostituire i template attualmente collegati.<br>Tutti i template non elencati nella richiesta verranno solo scollegati.<br><br>I template devono avere definita solo la proprietà `templateid`.|
|templates\_clear|object/array|[Template](/manual/api/reference/template/object) da scollegare e rimuovere dal host.<br><br>I template devono avere definita solo la proprietà `templateid`.|

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

[comment]: # ({d166b99b-d166b99b})
### Valori di ritorno

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

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

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

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

[comment]: # ({bcd7b728-ce50c453})
#### Abilitazione di un host

Abilitare il monitoraggio dell'host, ovvero impostarne lo stato a "0".

[Richiesta](/manual/api#performing-requests):

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

Risposta:

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

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

[comment]: # ({56f46465-bea1db7e})
#### Scollegamento dei template

Scollega e rimuove due template da un host.

[Richiesta](/manual/api#performing-requests):

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

Risposta:

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

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

[comment]: # ({b789e636-98dcfd68})
#### Aggiornamento delle macro dell'host

Sostituisce tutte le macro dell'host con due nuove.

[Richiesta](/manual/api#performing-requests):

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

Risposta:

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

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

[comment]: # ({72eb8ecc-da99f3b8})
#### Aggiornamento dell'inventario dell'host

Modificare la modalità dell'inventario e aggiungere la posizione

[Richiesta](/manual/api#performing-requests):

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

Risposta:

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

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

[comment]: # ({603ba164-5cc5d950})
#### Aggiornamento dei tag del host

Sostituisci tutti i tag del host con uno nuovo.

[Richiesta](/manual/api#performing-requests):

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

Risposta:

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

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

[comment]: # ({58eba4cd-ae2d89bf})
#### Aggiornamento delle macro del host individuato

Convertire la macro "automatic" creata dalla regola di individuazione in "manual" e modificarne il valore in "new-value".

[Richiesta](/manual/api#performing-requests):

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

Risposta:

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

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

[comment]: # ({1948c7c9-f620e859})
#### Aggiornamento della crittografia del host

Aggiorna il host "10590" in modo che utilizzi la crittografia PSK solo per le connessioni dal host al server Zabbix e modifica l'identità PSK e la chiave PSK.
Si noti che il host deve essere [preconfigurato per utilizzare PSK](/manual/encryption/using_pre_shared_keys#configuring-psk-for-server-agent-communication-example).

[Richiesta](/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
}
```

Risposta:

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

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

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

-   [host.massadd](massadd)
-   [host.massupdate](massupdate)
-   [host.massremove](massremove)
-   [Gruppo host](/manual/api/reference/hostgroup/object#host-group)
-   [template](/manual/api/reference/template/object#template)
-   [Macro utente](/manual/api/reference/usermacro/object#hosttemplate-level-macro)
-   [Interfaccia host](/manual/api/reference/hostinterface/object#host-interface)
-   [Inventario host](object#host-inventory)
-   [Tag host](object#host-tag)
-   [proxy](/manual/api/reference/proxy/object#proxy)
-   [Gruppo proxy](/manual/api/reference/proxygroup/object#proxy-group)

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

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

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

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