template.get

Description

integer/array template.get(object parameters)

The method allows to retrieve templates 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
templateidsstring/arrayReturn only templates with the given template IDs.
groupidsstring/arrayReturn only templates that belong to the given template groups.
parentTemplateidsstring/arrayReturn only templates that the given template is linked to.
hostidsstring/arrayReturn only templates that are linked to the given hosts/templates.
graphidsstring/arrayReturn only templates that contain the given graphs.
itemidsstring/arrayReturn only templates that contain the given items.
triggeridsstring/arrayReturn only templates that contain the given triggers.
with_itemsflagReturn only templates that have items.
with_triggersflagReturn only templates that have triggers.
with_graphsflagReturn only templates that have graphs.
with_httptestsflagReturn only templates that have web scenarios.
evaltypeintegerRules for tag searching.

Possible values:
0 - (default) And/Or;
2 - Or.
tagsarray/objectReturn only templates with given tags. Exact match by tag and case-sensitive or case-insensitive search by tag value depending on operator value.
Format: [{“tag”: “<tag>”, “value”: “<value>”, “operator”: “<operator>”}, …].
An empty array returns all templates.

Possible operator values:
0 - (default) Contains;
1 - Equals;
2 - Not like;
3 - Not equal
4 - Exists;
5 - Not exists.
selectTagsqueryReturn template tags in the tags property.
selectHostsqueryReturn the hosts that are linked to the template in the hosts property.

Supports count.
selectTemplateGroupsqueryReturn the template groups that the template belongs to in the templategroups property.
selectTemplatesqueryReturn templates to which the given template is linked in the templates property.

Supports count.
selectParentTemplatesqueryReturn templates that are linked to the given template in the parentTemplates property.

Supports count.
selectHttpTestsqueryReturn the web scenarios from the template in the httpTests property.

Supports count.
selectItemsqueryReturn items from the template in the items property.

Supports count.
selectDiscoveriesqueryReturn low-level discoveries from the template in the discoveries property.

Supports count.
selectTriggersqueryReturn triggers from the template in the triggers property.

Supports count.
selectGraphsqueryReturn graphs from the template in the graphs property.

Supports count.
selectMacrosqueryReturn the macros from the template in the macros property..
selectDashboardsqueryReturn dashboards from the template in the dashboards property.

Supports count.
selectValueMapsqueryReturn a valuemaps property with template value maps.
limitSelectsintegerLimits the number of records returned by subselects.

Applies to the following subselects:
selectTemplates - results will be sorted by name;
selectHosts - sorted by host;
selectParentTemplates - sorted by host;
selectItems - sorted by name;
selectDiscoveries - sorted by name;
selectTriggers - sorted by description;
selectGraphs - sorted by name;
selectDashboards - sorted by name.
sortfieldstring/arraySort the result by the given properties.

Possible values: hostid, host, name, status.
countOutputbooleanThese parameters being common for all get methods are described in detail in the reference commentary.
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean
selectGroups
(deprecated)
queryThis parameter is deprecated, please use selectTemplateGroups instead.
Return the template groups that the template belongs to in the groups property.

Return values

(integer/array) Returns either:

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

Examples

Retrieving templates by name

Retrieve all data about two templates named “Linux” and “Windows”.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.get",
  4. "params": {
  5. "output": "extend",
  6. "filter": {
  7. "host": [
  8. "Linux",
  9. "Windows"
  10. ]
  11. }
  12. },
  13. "id": 1
  14. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "proxy_hostid": "0",
  6. "host": "Linux",
  7. "status": "3",
  8. "disable_until": "0",
  9. "error": "",
  10. "available": "0",
  11. "errors_from": "0",
  12. "lastaccess": "0",
  13. "ipmi_authtype": "0",
  14. "ipmi_privilege": "2",
  15. "ipmi_username": "",
  16. "ipmi_password": "",
  17. "ipmi_disable_until": "0",
  18. "ipmi_available": "0",
  19. "snmp_disable_until": "0",
  20. "snmp_available": "0",
  21. "maintenanceid": "0",
  22. "maintenance_status": "0",
  23. "maintenance_type": "0",
  24. "maintenance_from": "0",
  25. "ipmi_errors_from": "0",
  26. "snmp_errors_from": "0",
  27. "ipmi_error": "",
  28. "snmp_error": "",
  29. "jmx_disable_until": "0",
  30. "jmx_available": "0",
  31. "jmx_errors_from": "0",
  32. "jmx_error": "",
  33. "name": "Linux",
  34. "flags": "0",
  35. "templateid": "10001",
  36. "description": "",
  37. "tls_connect": "1",
  38. "tls_accept": "1",
  39. "tls_issuer": "",
  40. "tls_subject": "",
  41. "tls_psk_identity": "",
  42. "tls_psk": "",
  43. "uuid": "282ffe33afc74cccaf1524d9aa9dc502"
  44. },
  45. {
  46. "proxy_hostid": "0",
  47. "host": "Windows",
  48. "status": "3",
  49. "disable_until": "0",
  50. "error": "",
  51. "available": "0",
  52. "errors_from": "0",
  53. "lastaccess": "0",
  54. "ipmi_authtype": "0",
  55. "ipmi_privilege": "2",
  56. "ipmi_username": "",
  57. "ipmi_password": "",
  58. "ipmi_disable_until": "0",
  59. "ipmi_available": "0",
  60. "snmp_disable_until": "0",
  61. "snmp_available": "0",
  62. "maintenanceid": "0",
  63. "maintenance_status": "0",
  64. "maintenance_type": "0",
  65. "maintenance_from": "0",
  66. "ipmi_errors_from": "0",
  67. "snmp_errors_from": "0",
  68. "ipmi_error": "",
  69. "snmp_error": "",
  70. "jmx_disable_until": "0",
  71. "jmx_available": "0",
  72. "jmx_errors_from": "0",
  73. "jmx_error": "",
  74. "name": "Windows",
  75. "flags": "0",
  76. "templateid": "10081",
  77. "description": "",
  78. "tls_connect": "1",
  79. "tls_accept": "1",
  80. "tls_issuer": "",
  81. "tls_subject": "",
  82. "tls_psk_identity": "",
  83. "tls_psk": "",
  84. "uuid": "522d17e1834049be879287b7c0518e5d"
  85. }
  86. ],
  87. "id": 1
  88. }

Retrieving template groups

Retrieve template groups that the template “Linux by Zabbix agent” is a member of.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.get",
  4. "params": {
  5. "output": ["hostid"],
  6. "selectTemplateGroups": "extend",
  7. "filter": {
  8. "host": [
  9. "Linux by Zabbix agent"
  10. ]
  11. }
  12. },
  13. "id": 1
  14. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "templateid": "10001",
  6. "templategroups": [
  7. {
  8. "groupid": "10",
  9. "name": "Templates/Operating systems",
  10. "uuid": "846977d1dfed4968bc5f8bdb363285bc"
  11. }
  12. ]
  13. }
  14. ],
  15. "id": 1
  16. }

Searching by template tags

Retrieve templates that have tag “Host name” equal to “{HOST.NAME}”.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.get",
  4. "params": {
  5. "output": ["hostid"],
  6. "selectTags": "extend",
  7. "evaltype": 0,
  8. "tags": [
  9. {
  10. "tag": "Host name",
  11. "value": "{HOST.NAME}",
  12. "operator": 1
  13. }
  14. ]
  15. },
  16. "id": 1
  17. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10402",
  6. "tags": [
  7. {
  8. "tag": "Host name",
  9. "value": "{HOST.NAME}"
  10. }
  11. ]
  12. }
  13. ],
  14. "id": 1
  15. }

See also

Source

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