host.get

Description 说明

integer/array host.get(object parameters)

此方法允许根据指定的参数获取主机。

Parameters参数

(object) 定义期望输出的参数

该方法支持以下参数。

参数类型说明
groupidsstring/array 仅返回指定主机组所属的主机。
applicationidsstring/array 仅返回含有指定应用集的主机。
dserviceidsstring/array 仅返回与指定自动发现服务相关的主机。
graphidsstring/array 仅返回含有指定图表的主机。
hostidsstring/array 仅返回指定主机ID的主机。
httptestidsstring/array 仅返回含有指定网页监测的主机。
interfaceidsstring/array 仅返回使用指定接口的主机。
itemidsstring/array 仅返回含有指定监控项的主机。
maintenanceidsstring/array 仅返回被指定管理影响到的主机。
monitoredhostsflag 仅返回被监控的主机。
proxy_hostsflag 仅返回代理服务器。
proxyidsstring/array 仅返回被代理服务器监控的主机。
templated_hostsflag 同时返回主机和模板。
templateidsstring/array 仅返回与指定模板链接的主机。
triggeridsstring/array 仅返回含有指定触发器的主机。
with_itemsflag仅返回含有监控项的主机。Overrides the with_monitored_items and with_simple_graph_items parameters. 覆盖“with_monitored_items”和“with_simple_graph_items”参数。
with_applicationsflag 仅返回含有应用集的主机。
with_graphsflag仅返回含有图表的主机。
with_httptestsflag仅返回含有网页监测的主机。 Overrides the with_monitored_httptests parameter.覆盖“with_monitored_httptests”参数。
with_monitored_httptestsflag仅返回启用网页监测的主机。
with_monitored_items.仅返回启用监控项的主机。Overrides the with_simple_graph_items parameter.覆盖with_simple_graph_items参数。
with_monitored_triggersflagReturn only hosts that have enabled triggers. All of the items used in the trigger must also be enabled.仅返回启用触发器的主机。所有在触发器中使用到的监控项必须也要启用。
with_simple_graph_itemsflag仅返回含有数字类信息监控项的主机。
with_triggersflag仅返回含有触发器的主机。Overrides the with_monitored_triggers parameter.覆盖“with_monitored_triggers”参数。
withInventoryflag仅返回含有资产清单数据的主机。
selectGroupsquery返回在groups属性中主机所属的主机组。
selectApplicationsquery 返回在applications属性中来自主机的应用集。Supports count.支持count
selectDiscoveriesquery 返回在discoveries属性中来自主机的底层自动发现。Supports count.支持count。
selectDiscoveryRule query R 返回在discoveryRule属性中创建主机的底层自动发现规则。
selectGraphsquery返回在graphs属性中来自主机的图表。Supports count.支持count。
selectHostDiscovery query 返回在hostDiscovery属性中的主机自动发现对象。 主机自动发现对象将一个自动发现的主机和一个原型主机连接起来,或者把一个原型主机和一个底层自动发现规则连接起来,并且含有以下属性: host - (string) host of the host prototype;字符串)原型主机的主机。 hostid - (string) ID of the discovered host or host prototype;(字符串)自动发现的主机或原型主机的ID。 parent_hostid - (string) ID of the host prototype from which the host has been created; 字符串)创建主机的原型主机ID。parent_itemid - (string) ID of the LLD rule that created the discovered host;(字符串)创建自动发现主机的底层自动发现规则ID。 lastcheck - (timestamp) time when the host was last discovered; (时间戳)当最近一次自动发现主机时的时间。ts_delete - (timestamp)_ time when a host that is no longer discovered will be deleted.(时间戳)当不再自动发现的主机将被删除的时间。
selectHttpTestsqueryReturn the web scenarios from the host in the httpTests property. 返回在httpTests属性中主机里的网页应用场景。Supports count.支持count。
selectInterfacesquery返回在interfaces属性中的主机接口。 Supports count.支持count。
selectInventoryquery 返回在inventory属性中主机里的主机资产清单。
selectItemsquery返回在items属性中主机里的监控项。 Supports count. 支持count。
selectMacrosquery返回在macros属性中主机里的宏。
selectParentTemplatesquery返回在parentTemplates属性中与主机关联的模板。Supports count.支持count。
selectScreensquery返回在screens属性中主机里的屏幕。Supports count.支持count。
selectTriggersquery返回在triggers属性中主机里的触发器。Supports count. 支持count。
filter object 仅返回完全匹配指定筛选后的结果。接受一个数组,其键值为属性名,其值要么是一个单一的值,要么是一个匹配的数组值。 Allows filtering by interface properties.允许通过接口属性筛选。
limitSelects integer 限定由子查询返回的记录数量。 适用于以下子查询:selectParentTemplates - results will be sorted by host;结果将由host排序; selectInterfaces; selectItems - sorted by name;由name排序; selectDiscoveries - sorted by name;由name排序; selectTriggers - sorted by description;由description排序; selectGraphs - sorted by name;由name排序; selectApplications - sorted by name; 由name排序;selectScreens - sorted by name. 由name排序;
search object Return results that match the given wildcard search.返回与指定通配符搜索匹配的结果。Accepts an array, where the keys are property names, and the values are strings to search for. If no additional options are given, this will perform a LIKE “%…%” search.接受一个数组,其中键值是属性名,其值为搜索到的字符串。如果没有指定的额外选项,将会以LIKE “%…%”方式执行搜索。Allows searching by interface properties. Works only with text fields.允许通过接口属性搜索,仅对文本域产生影响。
searchInventory object 仅返回与指定通配符搜索资产清单数据匹配的主机。 This parameter is affected by the same additional parameters as search. 这个参数被相同其他参数,比如参数search所影响。
sortfieldstring/array 用指定的属性排序结果。Possible values are: hostid, host, name, status.可能的值为:hostid,host,name,status。
countOutputflagThese parameters being common for all get methods are described in detail in the reference commentary. 在reference commentary中详细描述了所有“get”方法的共同参数.
editable boolean
excludeSearch flag
limit integer
output query
preservekeys flag
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch flag

返回值

(integer/array) Returns either:返回其中任一:

  • an array of objects;一组对象;

  • the count of retrieved objects, if the countOutput parameter has been used.如果已经使用了“countOutput”参数,则检索对象的计数.

范例

根据名称检索数据

Retrieve all data about two hosts named “Zabbix server” and “Linux server”.检索所有关于主机名为“Zabbix server”和“Linux server”的数据。

Request:

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

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "maintenances": [],
  6. "hostid": "10160",
  7. "proxy_hostid": "0",
  8. "host": "Zabbix server",
  9. "status": "0",
  10. "disable_until": "0",
  11. "error": "",
  12. "available": "0",
  13. "errors_from": "0",
  14. "lastaccess": "0",
  15. "ipmi_authtype": "-1",
  16. "ipmi_privilege": "2",
  17. "ipmi_username": "",
  18. "ipmi_password": "",
  19. "ipmi_disable_until": "0",
  20. "ipmi_available": "0",
  21. "snmp_disable_until": "0",
  22. "snmp_available": "0",
  23. "maintenanceid": "0",
  24. "maintenance_status": "0",
  25. "maintenance_type": "0",
  26. "maintenance_from": "0",
  27. "ipmi_errors_from": "0",
  28. "snmp_errors_from": "0",
  29. "ipmi_error": "",
  30. "snmp_error": "",
  31. "jmx_disable_until": "0",
  32. "jmx_available": "0",
  33. "jmx_errors_from": "0",
  34. "jmx_error": "",
  35. "name": "Zabbix server",
  36. "description": "The Zabbix monitoring server.",
  37. "tls_connect": "1",
  38. "tls_accept": "1",
  39. "tls_issuer": "",
  40. "tls_subject": "",
  41. "tls_psk_identity": "",
  42. "tls_psk": ""
  43. },
  44. {
  45. "maintenances": [],
  46. "hostid": "10167",
  47. "proxy_hostid": "0",
  48. "host": "Linux server",
  49. "status": "0",
  50. "disable_until": "0",
  51. "error": "",
  52. "available": "0",
  53. "errors_from": "0",
  54. "lastaccess": "0",
  55. "ipmi_authtype": "-1",
  56. "ipmi_privilege": "2",
  57. "ipmi_username": "",
  58. "ipmi_password": "",
  59. "ipmi_disable_until": "0",
  60. "ipmi_available": "0",
  61. "snmp_disable_until": "0",
  62. "snmp_available": "0",
  63. "maintenanceid": "0",
  64. "maintenance_status": "0",
  65. "maintenance_type": "0",
  66. "maintenance_from": "0",
  67. "ipmi_errors_from": "0",
  68. "snmp_errors_from": "0",
  69. "ipmi_error": "",
  70. "snmp_error": "",
  71. "jmx_disable_until": "0",
  72. "jmx_available": "0",
  73. "jmx_errors_from": "0",
  74. "jmx_error": "",
  75. "name": "Linux server",
  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. }

Retrieving host groups 检索主机组

Retrieve names of the groups host “Zabbix server” is member of, but no host details themselves. 检索主机“Zabbix server”隶属于的组名,但是不检索主机本身的详情。

Request:

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

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10085",
  6. "groups": [
  7. {
  8. "groupid": "2",
  9. "name": "Linux servers",
  10. "internal": "0",
  11. "flags": "0"
  12. },
  13. {
  14. "groupid": "4",
  15. "name": "Zabbix servers",
  16. "internal": "0",
  17. "flags": "0"
  18. }
  19. ]
  20. }
  21. ],
  22. "id": 2
  23. }

Retrieving linked templates 检索相关模板

Retrieve the IDs and names of templates linked to host “10084”.检索主机“10084”相关模板的ID和名称。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": ["hostid"],
  6. "selectParentTemplates": [
  7. "templateid",
  8. "name"
  9. ],
  10. "hostids": "10084"
  11. },
  12. "id": 1,
  13. "auth": "70785d2b494a7302309b48afcdb3a401"
  14. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10084",
  6. "parentTemplates": [
  7. {
  8. "name": "Template OS Linux",
  9. "templateid": "10001"
  10. },
  11. {
  12. "name": "Template App Zabbix Server",
  13. "templateid": "10047"
  14. }
  15. ]
  16. }
  17. ],
  18. "id": 1
  19. }

Searching by host inventory data 根据主机资产清单数据搜索

Retrieve hosts that contain “Linux” in the host inventory “OS” field.检索在资产清单“操作系统”字段中包含“Linux”的主机。

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": [
  6. "host"
  7. ],
  8. "selectInventory": [
  9. "os"
  10. ],
  11. "searchInventory": {
  12. "os": "Linux"
  13. }
  14. },
  15. "id": 2,
  16. "auth": "7f9e00124c75e8f25facd5c093f3e9a0"
  17. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10084",
  6. "host": "Zabbix server",
  7. "inventory": {
  8. "os": "Linux Ubuntu"
  9. }
  10. },
  11. {
  12. "hostid": "10107",
  13. "host": "Linux server",
  14. "inventory": {
  15. "os": "Linux Mint"
  16. }
  17. }
  18. ],
  19. "id": 1
  20. }

See also 参见

Source 来源

CHost::get() in frontends/php/include/classes/api/services/CHost.php.