获取

描述

integer/array template.get(object parameters)

该方法允许根据给定的参数检索模板。

这个方法所有用户类型都可以使用。在用户角色设置中可用撤销掉用该方法的权限。 查看 用户角色获取更多信息。

参数

(object) 定义所需输出的参数。

这个方法支持下列参数。

参数类型描述
templateidsID/array仅返回具有指定模板ID的模板。
groupidsID/array仅返回属于给定模板组的模板。
parentTemplateidsID/array仅返回与给定模板关联的模板。
hostidsID/array仅返回与给定主机/模板关联的模板。
graphidsID/array仅返回包含给定图形的模板。
itemidsID/array仅返回包含给定监控项的模板。
triggeridsID/array仅返回包含给定触发器的模板。
with_itemsflag仅返回具有监控项的模板。
with_triggersflag仅返回具有触发器的模板。
with_graphsflag仅返回具有图形的模板。
with_httptestsflag仅返回具有 Web 场景的模板。
evaltypeinteger标签搜索的规则。

可能的值:
0 - (默认) And/Or;
2 - Or.
tagsobject/array仅返回具有指定标签的模板。根据操作符的值,可以进行标签值的精确匹配(大小写敏感)或大小写不敏感的搜索。
格式: [{“tag”: “<tag>”, “value”: “<value>”, “operator”: “<operator>”}, …].
如果数组为空将返回所有模板。

可能的操作值:
0 - (默认) 包含;
1 - 等于;
2 - 不包含;
3 - 不等于;
4 - 存在;
5 - 不存在.
selectTagsquery返回模版的标签在 tags 属性。
selectHostsquery返回与模板关联的主机在 hosts 属性中。

支持 count
selectTemplateGroupsquery返回模板组所属的模板在 templategroups 属性中。
selectTemplatesquery返回给定模板在 templates 属性中链接到的模板。

支持 count
selectParentTemplatesquery返回链接到给定模板的模板,在 parentTemplates 属性中。

支持 count
selectHttpTestsquery返回模板中的 Web 场景在 httpTests 属性中。

支持 count
selectItemsquery返回模板中的监控项在 items 属性中。

支持 count
selectDiscoveriesquery返回模板中的低级别发现在 discoveries 属性中。

支持 count
selectTriggersquery返回模板中的触发器在 triggers 属性中。

支持 count
selectGraphsquery返回模板中的图形在 graphs 属性中。

支持 count
selectMacrosquery返回模板中的宏在 macros 属性中。
selectDashboardsquery返回模板中的仪表板在 dashboards 属性中。

支持 count
selectValueMapsquery返回一个包含模板值映射的 valuemaps 属性。
limitSelectsinteger限制子查询返回的记录数。

适用于以下子查询:
selectTemplates - 结果将按 name 排序 ;
selectHosts - 按 host 排序;
selectParentTemplates - 按 host 排序;
selectItems - 按 name 排序;
selectDiscoveries - 按 name 排序;
selectTriggers - 按 description 排序;
selectGraphs - 按 name 排序;
selectDashboards - 按 name 排序.
sortfieldstring/array按照给定的属性对结果进行排序。

可能的值: hostid, host, name, status.
countOutputboolean这些参数在所有 get 方法中都是通用的,详细描述在参考说明中。
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean
selectGroups
(已弃用)
query这个参数已经废弃,请使用 selectTemplateGroups 替换该参数。
返回模板所属的模板组在 groups 属性中。

返回值

(integer/array) 返回以下二选一:

  • 一个对象数组;
  • 如果使用了 countOutput 参数,则返回检索到的对象的数量。

示例

按名称检索模板

检索名为 “Linux” 和 “Windows” 的两个模板的所有数据。

请求:

  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. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "proxyid": "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. "proxyid": "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. }

检索模板组

检索模板 “Linux by Zabbix agent” 所属的模板组。

请求:

  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. }

响应:

  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. }

按模板检索主机

检索已链接到 “10001”(即 Linux by Zabbix agent)模板的主机。

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.get",
  4. "params": {
  5. "output": "templateid",
  6. "templateids": "10001",
  7. "selectHosts": ["hostid", "name"]
  8. },
  9. "id": 1
  10. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "templateid": "10001",
  6. "hosts": [
  7. {
  8. "hostid": "10084",
  9. "name": "Zabbix server"
  10. },
  11. {
  12. "hostid": "10603",
  13. "name": "Host 1"
  14. },
  15. {
  16. "hostid": "10604",
  17. "name": "Host 2"
  18. }
  19. ]
  20. }
  21. ],
  22. "id": 1
  23. }

按模板标签进行搜索

检索标签 “Host name” 等于 “{HOST.NAME}” 的模板。

请求:

  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. }

响应:

  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. }

参考

来源

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