获取

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

    任何用户类型均可使用此方法。可以在用户角色中撤销调用方法的权限设置。详情参考 用户角色

    参数

    (对象) 参数定义了所需的输出。

    该方法支持以下参数。

    (整数/数组) 返回其中之一:

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

    示例

    按名称检索数据

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

    请求:

    响应:

    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. "lastaccess": "0",
    11. "ipmi_authtype": "-1",
    12. "ipmi_privilege": "2",
    13. "ipmi_username": "",
    14. "ipmi_password": "",
    15. "ipmi_disable_until": "0",
    16. "snmp_disable_until": "0",
    17. "maintenanceid": "0",
    18. "maintenance_status": "0",
    19. "maintenance_type": "0",
    20. "maintenance_from": "0",
    21. "name": "Zabbix server",
    22. "description": "The Zabbix monitoring server.",
    23. "tls_connect": "1",
    24. "tls_accept": "1",
    25. "tls_issuer": "",
    26. "tls_subject": ""
    27. },
    28. {
    29. "maintenances": [],
    30. "hostid": "10167",
    31. "proxy_hostid": "0",
    32. "host": "Linux server",
    33. "status": "0",
    34. "lastaccess": "0",
    35. "ipmi_authtype": "-1",
    36. "ipmi_privilege": "2",
    37. "ipmi_username": "",
    38. "ipmi_password": "",
    39. "ipmi_disable_until": "0",
    40. "snmp_disable_until": "0",
    41. "maintenanceid": "0",
    42. "maintenance_status": "0",
    43. "maintenance_type": "0",
    44. "maintenance_from": "0",
    45. "name": "Linux server",
    46. "description": "",
    47. "tls_connect": "1",
    48. "tls_accept": "1",
    49. "tls_issuer": "",
    50. "tls_subject": ""
    51. }
    52. ],
    53. "id": 1
    54. }

    获取主机组

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

    请求:

    1. {
    2. "method": "host.get",
    3. "params": {
    4. "output": ["hostid"],
    5. "selectGroups": "extend",
    6. "filter": {
    7. "host": [
    8. "Zabbix server"
    9. ]
    10. }
    11. },
    12. "auth": "038e1d7b1735c6a5436ee9eae095879e",
    13. "id": 2
    14. }
    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. }

    获取关联的模板

    获取主机”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": "Linux",
    9. "templateid": "10001"
    10. },
    11. {
    12. "name": "Zabbix Server",
    13. "templateid": "10047"
    14. }
    15. ]
    16. }
    17. ],
    18. "id": 1
    19. }

    按主机资产数据进行搜索

    检索主机资产“OS”字段中包含“Linux”的主机。

    请求:

    响应:

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

    按主机标记搜索

    检索标记为“主机名”等于“Linux服务器”的主机。

    请求:

    1. {
    2. "jsonrpc": "2.0",
    3. "method": "host.get",
    4. "params": {
    5. "output": ["hostid"],
    6. "selectTags": "extend",
    7. "evaltype": 0,
    8. "tags": [
    9. {
    10. "tag": "Host name",
    11. "value": "Linux server",
    12. "operator": 1
    13. }
    14. ]
    15. },
    16. "auth": "7f9e00124c75e8f25facd5c093f3e9a0",
    17. "id": 1
    18. }

    响应:

    1. "jsonrpc": "2.0",
    2. "result": [
    3. {
    4. "hostid": "10085",
    5. "tags": [
    6. {
    7. "tag": "Host name",
    8. "value": "Linux server"
    9. },
    10. {
    11. "tag": "OS",
    12. "value": "RHEL 7"
    13. }
    14. ]
    15. ],
    16. "id": 1
    17. }

    检索不仅在主机级而且在其链接的父模板中具有这些标记的主机。

    1. {
    2. "jsonrpc": "2.0",
    3. "method": "host.get",
    4. "params": {
    5. "output": ["name"],
    6. "tags": [{"tag": "A", "value": "1", "operator": "0"}],
    7. "inheritedTags": true
    8. },
    9. "auth": "038e1d7b1735c6a5436ee9eae095879e",
    10. "id": 1
    11. }

    响应:

    1. {
    2. "jsonrpc": "2.0",
    3. "result": [
    4. {
    5. "hostid": "10623",
    6. "name": "PC room 1"
    7. },
    8. {
    9. "hostid": "10601",
    10. "name": "Office"
    11. }
    12. ],
    13. "id": 1
    14. }

    搜索主机标签和模板标签

    检索带有标记的主机以及链接到父模板的所有标记。

    请求:

    响应:

    1. {
    2. "jsonrpc": "2.0",
    3. "result": [
    4. {
    5. "hostid": "10502",
    6. "name": "Desktop",
    7. "tags": [
    8. {
    9. "tag": "A",
    10. "value": "1"
    11. }
    12. ],
    13. "inheritedTags": [
    14. {
    15. "tag": "B",
    16. "value": "2"
    17. }
    18. ]
    19. }
    20. ],
    21. "id": 1
    22. }

    根据问题严重程度搜索主机

    检索有“灾难”问题的主机。

    请求:

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

    响应:

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

    检索具有“一般严重”和“严重”问题的主机。

    请求:

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

    响应:

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

    源代码