获取

描述

integer/array host.get(object parameters)

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

参数

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

该方法支持以下参数.

参数 类描述
groupids字符串/数组 返回指定机组的主机.
applicationids字符串/数组 返回指定用集的主机.
dserviceids字符串/数组 返回与指自动发现服务相关的主机.
graphids字符串/数组 返回包含指定图表的主机.
hostids字符串/数组 返回指定机ID的主机.
httptestids字符串/数组 返回指定页监测的主机.
interfaceids字符串/数组 返回指定口的主机.
itemids字符串/数组 返回指定控项的主机.
maintenanceids字符串/数组 返回指定护的主机.
monitored_hosts标识 返被监控的主机.
proxy_hosts标识 返代理服务器.
proxyids字符串/数组 返回被代服务器监控的主机.
templated_hosts标识 返主机和模板.
templateids字符串/数组 返回使用定模板的主机.
triggerids字符串/数组 返回指定发器的主机.
with_items标识 返含有监控项的主机.

覆盖with_monitored_itemswith_simple_graph_items 参数.
with_applications标识 返含有应用集的主机.
with_graphs标识 返含有图表的主机.
with_httptests标识 返含有web监测的主机.

覆盖with_monitored_httptests 参数.
with_monitored_httptests标识 返含有启动网页监测的主机.
with_monitored_items标识 返启用监控项的主机.

覆盖 with_simple_graph_items 参数.
with_monitored_triggers标识 返启用触发器的主机.所有在触发器中使用到的监控项必须也要启用.
with_simple_graph_items标识 返含有数字类信息监控项的主机.
with_triggers标识 返含有触发器的主机.

覆盖 with_monitored_triggers 参数.
withInventory标识 返含有资产清单数据的主机.
selectGroups查询 在groups属性中返回主机所属的主机组.| |selectApplications|查询 在|applications属性中返回来自主机的应用集.

支持count.
selectDiscoveries查询 在discoveries属性中返回来自主机的底层自动发现.

支持
count.| |selectDiscoveryRule|查询 在|discoveryRule属性中返回创建主机的底层自动发现规则.
selectGraphs查询 在graphs属性中返回来自主机的图表.

支持
count.| |selectHostDiscovery|查询 在|hostDiscovery属性中返回主机自动发现对象.

主机自动发现对象将一个自动发现的主机和一个原型主机连接起来,或者把一个原型主机和一个底层自动发现规则连接起来,并且含有以下属性:
host - (字符串) 主机原型的主机;
hostid - (字符串) 主机原型和自动发现主机的ID;
parent_hostid - (字符串) 已经创建主机的主机原型ID;
parent_itemid - (字符串) 创建自动发现主机的底层自动发现规则ID;
lastcheck - (时间戳) 最近一次发现主机的时间;
ts_delete - (时间戳) 当不再自动发现的主机将被删除的时间.
selectHttpTests查询 在httpTests属性中返回主机的web场景.

支持
count.| |selectInterfaces|查询 在|interfaces属性中返回主机的接口.

支持 count.
selectInventory查询 在inventory属性中返回主机清单.| |selectItems|查询 在|item属性中返回主机监控项.

支持 count.
selectMacros查询 在macros属性中返回主机宏.| |selectParentTemplates|查询 在|parentTemplates属性中返回主机连接的模板.

支持 count.
selectScreens查询 在screens属性中返回主机的屏幕.

支持
count.| |selectTriggers|查询 在|triggers属性中返回主机的触发器.

支持 count.
filter对象 仅回完全匹配指定筛选后的结果.

接受数组,键为属性名,值为一个单一值或者一个要匹配的数组.

允许通过接口属性进行过滤.
limitSelects整数 限由子查询返回的记录数量.

适用于以下子查询:
selectParentTemplates - 结果将按照host排序;
selectInterfaces;
selectItems - 按name排序;
selectDiscoveries - 按name排序;
selectTriggers - 按description排序;
selectGraphs - 按name排序;
selectApplications - 按name排序;
selectScreens - 按name排序.
search对象 返与通配符相匹配的结果.

接受数组,键为属性名,值为待匹配搜索的字符串 . 如果没有指定的额外选项,将会以LIKE “%…%”方式执行搜索.

允许通过接口属性搜索,仅对文本域产生影响.
searchInventory对象 仅回与指定通配符搜索资产清单数据匹配的主机.

这个参数同时受search参数影响.
sortfield字符串/数组 结果按给的属性进行排序.

可能值: hostid, host, name, status.
countOutput布尔值 以下是与reference commentary中详细描述的get方法相同的参数.
editable布尔值 ::
excludeSearch布尔值 ::
limit整数 ::
output查询 ::
preservekeys布尔值 ::
searchByAny布尔值 ::
searchWildcardsEnabled布尔值 ::
sortorder字符串/数组 :::
startSearch布尔值 ::

返回值

(integer/array) 返回其中之一:

  • 一组对象;
  • 如果使用了countOutput参数,则返回获取的对象数量.

示例

通过名称获取数据

获取所有关于”Zabbix server”和”Linux server”两个主机的数据 请求:

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

响应:

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

获取主机组

获取主机”Zabbix server”所属的主机组,并不检索主机本身的详细信息

请求:

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

响应:

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

获取关联的模板

获取主机”10084”关联的模板的ID和名称 请求:

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

响应:

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

根据主机资产清单数据进行检索

获取主机清单中”OS”字段包含”Linux”的主机 请求:

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

响应:

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

参考

来源

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

Searching hosts by problem severity

Retrieve hosts that have “Disaster” problems.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": ["name"],
  6. "severities": 5
  7. },
  8. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  9. "id": 1
  10. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10160",
  6. "name": "Zabbix server"
  7. }
  8. ],
  9. "id": 1
  10. }

Retrieve hosts that have “Average” and “High” problems.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": ["name"],
  6. "severities": [3, 4]
  7. },
  8. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  9. "id": 1
  10. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "20170",
  6. "name": "Database"
  7. },
  8. {
  9. "hostid": "20183",
  10. "name": "workstation"
  11. }
  12. ],
  13. "id": 1
  14. }

See also

Source

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