hostprototype.get

Description

integer/array hostprototype.get(object parameters)

The method allows to retrieve host prototypes according to the given parameters.

This method is available to users of any type. Permissions to call the method can be revoked in user role settings. See User roles for more information.

Parameters

(object) Parameters defining the desired output.

The method supports the following parameters.

ParameterTypeDescription
hostidsstring/arrayReturn only host prototypes with the given IDs.
discoveryidsstring/arrayReturn only host prototype that belong to the given LLD rules.
inheritedbooleanIf set to true return only items inherited from a template.
selectDiscoveryRulequeryReturn a discoveryRule property with the LLD rule that the host prototype belongs to.
selectInterfacesqueryReturn an interfaces property with host prototype custom interfaces.
selectGroupLinksqueryReturn a groupLinks property with the group links of the host prototype.
selectGroupPrototypesqueryReturn a groupPrototypes property with the group prototypes of the host prototype.
selectMacrosqueryReturn a macros property with host prototype macros.
selectParentHostqueryReturn a parentHost property with the host that the host prototype belongs to.
selectTagsqueryReturn a tags property with host prototype tags.
selectTemplatesqueryReturn a templates property with the templates linked to the host prototype.

Supports count.
sortfieldstring/arraySort the result by the given properties.

Possible values are: hostid, host, name and status.
countOutputbooleanThese parameters being common for all get methods are described in detail on the Generic Zabbix API information page.
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

Return values

(integer/array) Returns either:

  • an array of objects;
  • the count of retrieved objects, if the countOutput parameter has been used.

Examples

Retrieving host prototypes from an LLD rule

Retrieve all host prototypes, their group links, group prototypes and tags from an LLD rule.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "hostprototype.get",
  4. "params": {
  5. "output": "extend",
  6. "selectInterfaces": "extend",
  7. "selectGroupLinks": "extend",
  8. "selectGroupPrototypes": "extend",
  9. "selectTags": "extend",
  10. "discoveryids": "23554"
  11. },
  12. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  13. "id": 1
  14. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10092",
  6. "host": "{#HV.UUID}",
  7. "name": "{#HV.UUID}",
  8. "status": "0",
  9. "templateid": "0",
  10. "discover": "0",
  11. "custom_interfaces": "1",
  12. "inventory_mode": "-1",
  13. "groupLinks": [
  14. {
  15. "group_prototypeid": "4",
  16. "hostid": "10092",
  17. "groupid": "7",
  18. "templateid": "0"
  19. }
  20. ],
  21. "groupPrototypes": [
  22. {
  23. "group_prototypeid": "7",
  24. "hostid": "10092",
  25. "name": "{#CLUSTER.NAME}",
  26. "templateid": "0"
  27. }
  28. ],
  29. "tags": [
  30. {
  31. "tag": "Datacenter",
  32. "value": "{#DATACENTER.NAME}"
  33. },
  34. {
  35. "tag": "Instance type",
  36. "value": "{#INSTANCE_TYPE}"
  37. }
  38. ],
  39. "interfaces": [
  40. {
  41. "main": "1",
  42. "type": "2",
  43. "useip": "1",
  44. "ip": "127.0.0.1",
  45. "dns": "",
  46. "port": "161",
  47. "details": {
  48. "version": "2",
  49. "bulk": "1",
  50. "community": "{$SNMP_COMMUNITY}"
  51. }
  52. }
  53. ]
  54. }
  55. ],
  56. "id": 1
  57. }

See also

Source

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