获取

说明

integer/array template.get(object **parameters**)

The method allows to retrieve templates according to the given parameters. 此方法允许根据指定的参数检索模板。

参数

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

此方法支持以下参数。

参数类型说明
templateidsstring/array只返回指定模板ID的模板。
groupidsstring/array只返回指定主机组所属的模板。
parentTemplateidsstring/array只返回指定子类模板的模板。
hostidsstring/array只返回被链接到指定主机的模板。
graphidsstring/array只返回包含指定图形的模板。
itemidsstring/array只返回包含指定监控项的模板。
triggeridsstring/array只返回包含指定触发器的模板。
with_itemsflag只返回具有监控项的模板。
with_triggersflag只返回具有触发器的模板。
with_graphsflag只返回具有图形的模板。
with_httptestsflag只返回具有web场景的模板。
evaltypeinteger标签搜索规则。
可能的值:
0 - (default) And/Or;
2 - Or.
tagsarray/object仅返回具有给定标签的模板。 按标记进行精确匹配,并根据运算符的值按标记值进行区分大小写或不区分大小写的搜索。
格式:[{“tag”: “<tag>”, “value”: “<value>”, “operator”: “<operator>”}, …]
空数组将返回所有模板。
可能的运算符值:
0 - (default) Contains;
1 - Equals.
selectGroupsquerygroups属性中返回所属模板的主机组。
selectTagsquerytags属性中返回模板标签。
selectHostsqueryhosts属性中返回被链接模板的主机。
支持count
selectTemplatesquerytemplates属性中返回子类模板。
支持count
selectParentTemplatesqueryparentTemplates属性中返回父类模板。
支持count
selectHttpTestsqueryhttpTests属性中返回来自模板的web场景。

支持count
selectItemsqueryitems属性中返回来自模板的监控项。
支持count
selectDiscoveriesquerydiscoveries属性中返回来自模板的低级别发现。
支持count
selectTriggersquerytriggers属性中返回来自模板的触发器。
支持count
selectGraphsquerygraphs属性中返回来自模板的图表。
支持count
selectApplicationsqueryapplications属性中返回来自模板的应用。
支持count
selectMacrosquerymacros属性中返回来自模板的宏。
selectScreensqueryscreens属性中返回来自模板的聚合图形。
支持count
limitSelectsinteger限制子查询返回的记录数。
应用于以下子查询:
selectTemplates - 结果将以name排序;
selectHosts - 以host排序;
selectParentTemplates - 以host排序;
selectItems - 以name排序;
selectDiscoveries - 以name排序;
selectTriggers - 以description排序;
selectGraphs - 以name排序;
selectApplications - 以name排序;
selectScreens - 以name排序;
sortfieldstring/array根据给定的属性为结果排序。
许可值为:hostid,host,name,status
countOutputboolean这些参数十分普遍,适用所有get方法,详情参见reference commentary
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean

返回值

(integer/array)返回两者其中任一:

  • 一组对象;

  • 如果已经使用了countOutput参数,则检索对象的计数。

范例

按名称检索模板

检索名称为“Template OS Linux”和“Template OS Windows”这两个模板的所有数据。 Request 请求:

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

Response 响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "proxy_hostid": "0",
  6. "host": "Template OS 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": "Template OS 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. },
  44. {
  45. "proxy_hostid": "0",
  46. "host": "Template OS Windows",
  47. "status": "3",
  48. "disable_until": "0",
  49. "error": "",
  50. "available": "0",
  51. "errors_from": "0",
  52. "lastaccess": "0",
  53. "ipmi_authtype": "0",
  54. "ipmi_privilege": "2",
  55. "ipmi_username": "",
  56. "ipmi_password": "",
  57. "ipmi_disable_until": "0",
  58. "ipmi_available": "0",
  59. "snmp_disable_until": "0",
  60. "snmp_available": "0",
  61. "maintenanceid": "0",
  62. "maintenance_status": "0",
  63. "maintenance_type": "0",
  64. "maintenance_from": "0",
  65. "ipmi_errors_from": "0",
  66. "snmp_errors_from": "0",
  67. "ipmi_error": "",
  68. "snmp_error": "",
  69. "jmx_disable_until": "0",
  70. "jmx_available": "0",
  71. "jmx_errors_from": "0",
  72. "jmx_error": "",
  73. "name": "Template OS Windows",
  74. "flags": "0",
  75. "templateid": "10081",
  76. "description": "",
  77. "tls_connect": "1",
  78. "tls_accept": "1",
  79. "tls_issuer": "",
  80. "tls_subject": "",
  81. "tls_psk_identity": "",
  82. "tls_psk": ""
  83. }
  84. ],
  85. "id": 1
  86. }

按模板标签搜索

检索标记为“Host name”等于“ {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. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  17. "id": 1
  18. }

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

参考

源码

CTemplate::get()方法可在ui/include/classes/api/services/CTemplate.php中参考。