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

    Parameters参数

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

    该方法支持以下参数。

    (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”的数据。

    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. "maintenances": [],
    45. "hostid": "10167",
    46. "proxy_hostid": "0",
    47. "host": "Linux server",
    48. "status": "0",
    49. "disable_until": "0",
    50. "error": "",
    51. "available": "0",
    52. "errors_from": "0",
    53. "lastaccess": "0",
    54. "ipmi_authtype": "-1",
    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": "Linux server",
    75. "description": "",
    76. "tls_connect": "1",
    77. "tls_accept": "1",
    78. "tls_issuer": "",
    79. "tls_subject": "",
    80. "tls_psk_identity": "",
    81. "tls_psk": ""
    82. }
    83. ],
    84. "id": 1
    85. }

    Retrieving host groups 检索主机组

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

    Request:

    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. "groupid": "4",
    14. "name": "Zabbix servers",
    15. "internal": "0",
    16. "flags": "0"
    17. }
    18. ]
    19. }
    20. ],
    21. "id": 2
    22. }

    Retrieving linked templates 检索相关模板

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

    Request:

    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 根据主机资产清单数据搜索

    Request:

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

    Source 来源

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