object host.create(object/array hosts)
This method allows to create new 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.
(object/array)
Hosts to create.
Additionally to the standard host properties, the method accepts the following parameters.
Parameter | Type | Description |
---|---|---|
groups | object/array | Host groups to add the host to. The host groups must have the groupid property defined.Parameter behavior: - required |
interfaces | object/array | Interfaces to be created for the host. |
tags | object/array | Host tags. |
templates | object/array | Templates to be linked to the host. The templates must have the templateid property defined. |
macros | object/array | User macros to be created for the host. |
inventory | object | Host inventory properties. |
(object)
Returns an object containing the IDs of the created hosts under the hostids
property. The order of the returned IDs matches the order of the passed hosts.
Create a host called "Linux server" with an IP interface and tags, add it to a group, link a template to it and set the MAC addresses in the host inventory.
{
"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
}
Response:
Create a host called "SNMP host" with an SNMPv3 interface with details.
{
"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
}
Response:
Create a host called "PSK host" with PSK encryption configured. Note that the host has to be pre-configured to use PSK.
{
"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
}
Response:
CHost::create() in ui/include/classes/api/services/CHost.php.