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.

ParameterTypeDescription
groupLinks
(required)
arrayGroup links to be created for the host prototype.
ruleid
(required)
stringID of the LLD rule that the host prototype belongs to.
groupPrototypesarrayGroup prototypes to be created for the host prototype.
macrosobject/arrayUser macros to be created for the host prototype.
tagsobject/arrayHost prototype tags.
interfacesobject/arrayHost prototype custom interfaces.
templatesobject/arrayTemplates to be linked to the host prototype.

The templates must have 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:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "hostprototype.create",
  4. "params": {
  5. "host": "{#VM.NAME}",
  6. "ruleid": "23542",
  7. "custom_interfaces": "1",
  8. "groupLinks": [
  9. {
  10. "groupid": "2"
  11. }
  12. ],
  13. "groupPrototypes": [
  14. {
  15. "name": "{#HV.NAME}"
  16. }
  17. ],
  18. "tags": [
  19. {
  20. "tag": "Datacenter",
  21. "value": "{#DATACENTER.NAME}"
  22. }
  23. ],
  24. "interfaces": [
  25. {
  26. "main": "1",
  27. "type": "2",
  28. "useip": "1",
  29. "ip": "127.0.0.1",
  30. "dns": "",
  31. "port": "161",
  32. "details": {
  33. "version": "2",
  34. "bulk": "1",
  35. "community": "{$SNMP_COMMUNITY}"
  36. }
  37. }
  38. ]
  39. },
  40. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  41. "id": 1
  42. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "hostids": [
  5. "10103"
  6. ]
  7. },
  8. "id": 1
  9. }

See also

Source

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