[comment]: # translation:outdated

[comment]: # ({ce3b3e73-ce3b3e73})
# host.create

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

[comment]: # ({a2bcf5e3-2e20b613})
### Descrizione

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

Questo metodo consente di creare nuovi host.

::: noteclassic
Questo metodo è disponibile solo per gli utenti di tipo *Admin* e *Super admin*.
I permessi per chiamare il metodo possono essere revocati nelle impostazioni del ruolo
utente. Consultare [Ruoli
utente](/manual/web_interface/frontend_sections/users/user_roles)
per ulteriori informazioni.
:::

[comment]: # ({/a2bcf5e3-2e20b613})

[comment]: # ({344f1579-48df9d2f})
### Parametri

`(object/array)` Host da creare.

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

|Parametro|[Tipo](/manual/api/reference_commentary#dat-types)|Descrizione|
|--|--|------|
|groups|object/array|[Gruppi di host](/manual/api/reference/hostgroup/object) a cui aggiungere l'host.<br><br>I gruppi di host devono avere definita solo la proprietà `groupid`.<br><br>[Comportamento del parametro](/manual/api/reference_commentary#parameter-behavior):<br>- *obbligatorio*|
|interfaces|object/array|[Interfacce](/manual/api/reference/hostinterface/object) da creare per l'host.|
|tags|object/array|[Tag dell'host](/manual/api/reference/host/object#host-tag).|
|templates|object/array|[Template](/manual/api/reference/template/object) da collegare all'host.<br><br>I template devono avere definita solo la proprietà `templateid`.|
|macros|object/array|[Macro utente](/manual/api/reference/usermacro/object) da creare per l'host.|
|inventory|object|Proprietà dell'[inventario dell'host](/manual/api/reference/host/object#host-inventory).|

[comment]: # ({/344f1579-48df9d2f})

[comment]: # ({de799b9d-de799b9d})
### Valori restituiti

`(object)` Restituisce un oggetto contenente gli ID degli host creati
nella proprietà `hostids`. L'ordine degli ID restituiti corrisponde all'ordine
degli host passati.

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

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

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

[comment]: # ({5fdc5df1-26320041})
#### Creazione di un host

Creare un host chiamato "Linux server" con un'interfaccia IP e tag, aggiungerlo
a un gruppo, collegargli un template e impostare gli indirizzi MAC nell'
inventario dell'host.

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "Linux server",
        "interfaces": [
            {
                "type": 1,
                "main": 1,
                "useip": 1,
                "ip": "192.168.3.1",
                "dns": "",
                "port": "10050"
            }
        ],
        "groups": [
            {
                "groupid": "50"
            }
        ],
        "tags": [
            {
                "tag": "host-name",
                "value": "linux-server"
            }
        ],
        "templates": [
            {
                "templateid": "20045"
            }
        ],
        "macros": [
            {
                "macro": "{$USER_ID}",
                "value": "123321"
            },
            {
                "macro": "{$USER_LOCATION}",
                "value": "0:0:0",
                "description": "latitude, longitude and altitude coordinates"
            }
        ],
        "inventory_mode": 0,
        "inventory": {
            "macaddress_a": "01234",
            "macaddress_b": "56768"
        }
    },
    "id": 1
}
```

Risposta:

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

[comment]: # ({/5fdc5df1-26320041})

[comment]: # ({0ae07890-9572ca08})
#### Creazione di un host con interfaccia SNMP

Creare un host denominato "SNMP host" con un'interfaccia SNMPv3 con dettagli.

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "SNMP host",
        "interfaces": [
            {
                "type": 2,
                "main": 1,
                "useip": 1,
                "ip": "127.0.0.1",
                "dns": "",
                "port": "161",
                "details": {
                    "version": 3,
                    "bulk": 0,
                    "securityname": "mysecurityname",
                    "contextname": "",
                    "securitylevel": 1
                }
            }
        ],
        "groups": [
            {
                "groupid": "4"
            }
        ]
    },
    "id": 1
}
```

Risposta:

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

[comment]: # ({/0ae07890-9572ca08})

[comment]: # ({44acfb2a-4c198338})
#### Creazione di un host con crittografia PSK

Creare un host denominato "PSK host" con la crittografia PSK configurata.
Si noti che l'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.create",
    "params": {
        "host": "PSK host",
        "interfaces": [
            {
                "type": 1,
                "ip": "192.168.3.1",
                "dns": "",
                "port": "10050",
                "useip": 1,
                "main": 1
            }
        ],
        "groups": [
            {
                "groupid": "2"
            }
        ],
        "tls_accept": 2,
        "tls_connect": 2,
        "tls_psk_identity": "PSK 001",
        "tls_psk": "1f87b595725ac58dd977beef14b97461a7c1045b9a1c963065002c5473194952"
    },
    "id": 1
}
```

Risposta:

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

[comment]: # ({/44acfb2a-4c198338})

[comment]: # ({46a2cfaa-14d80b7d})
#### Creazione di un host monitorato da un proxy

Creare un host che sarà monitorato dal proxy con ID "1".

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "Host monitored by proxy",
        "groups": [
            {
                "groupid": "2"
            }
        ],
        "monitored_by": 1,
        "proxyid": 1
    },
    "id": 1
}
```

Risposta:

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

[comment]: # ({/46a2cfaa-14d80b7d})

[comment]: # ({4b4ad6bd-472519f8})
#### Creazione di un host monitorato da un gruppo di proxy

Creare un host che sarà monitorato dal gruppo di proxy con ID "1".

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.create",
    "params": {
        "host": "Host monitored by proxy group",
        "groups": [
            {
                "groupid": "2"
            }
        ],
        "monitored_by": 2,
        "proxy_groupid": 1
    },
    "id": 1
}
```

Risposta:

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

[comment]: # ({/4b4ad6bd-472519f8})

[comment]: # ({2b047796-203ca033})
### Vedi anche

-   [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]: # ({/2b047796-203ca033})

[comment]: # ({f7e47995-f7e47995})
### Sorgente

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

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