hostprototype.create

Description

object hostprototype.create(object/array hostPrototypes)

This method allows to create new host prototypes.

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.

Parameters

(object/array) Host prototypes to create.

Additionally to the standard host prototype properties, the method accepts the following parameters.

Parameter Type Description
groupLinks array Group links to be created for the host prototype.

Parameter behavior:
- required
ruleid ID ID of the LLD rule that the host prototype belongs to.

Parameter behavior:
- required
groupPrototypes array Group prototypes to be created for the host prototype.
macros object/array User macros to be created for the host prototype.
tags object/array Host prototype tags.
interfaces object/array Host prototype custom interfaces.
templates object/array Templates to be linked to the host prototype.

The templates must have only the templateid property defined.

Return values

(object) Returns an object containing the IDs of the created host prototypes under the hostids property. The order of the returned IDs matches the order of the passed host prototypes.

Examples

Creating a host prototype

Create a host prototype "{#VM.NAME}" on LLD rule "23542" with a group prototype "{#HV.NAME}", tag pair "Datacenter": "{#DATACENTER.NAME}" and custom SNMPv2 interface 127.0.0.1:161 with community {$SNMP_COMMUNITY}. Link it to host group "2".

Request:

{
           "jsonrpc": "2.0",
           "method": "hostprototype.create",
           "params": {
               "host": "{#VM.NAME}",
               "ruleid": "23542",
               "custom_interfaces": "1",
               "groupLinks": [
                   {
                       "groupid": "2"
                   }
               ],
               "groupPrototypes": [
                   {
                       "name": "{#HV.NAME}"
                   }
               ],
               "tags": [
                   {
                       "tag": "Datacenter",
                       "value": "{#DATACENTER.NAME}"
                   }
               ],
               "interfaces": [
                   {
                       "main": "1",
                       "type": "2",
                       "useip": "1",
                       "ip": "127.0.0.1",
                       "dns": "",
                       "port": "161",
                       "details": {
                           "version": "2",
                           "bulk": "1",
                           "community": "{$SNMP_COMMUNITY}"
                       }
                   }
               ]
           },
           "id": 1
       }

Response:

{
           "jsonrpc": "2.0",
           "result": {
               "hostids": [
                   "10103"
               ]
           },
           "id": 1
       }

See also

Source

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