获取

描述

integer/array host.get(object parameters)

该方法允许根据指定的参数检索主机。

参数

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

该方法支持以下参数。

参数 [ 型](//zh/manual/api/reference_commentary#data_types) 描述
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_item_prototypes flag 仅返回具有项目原型的主机。

覆盖with_simple_graph_item_prototypes 参数。
with_simple_graph_item_prototypes flag 仅返回具有项目原型的主机,这些主机已启用创建并且具有数字类型的信息。
with_applications 标识 返 含有应用集的主机。
with_graphs 标识 返 含有图表的主机。
with_graph_prototypes flag 只返回具有原型图的主机。
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 参数。
withProblemsSuppressed 布尔值 返回 抑制问题的主机。

可能值:
null - (默认) 所有主机;
true - 仅已抑制问题的主机;
false - 仅未抑制问题的主机。
evaltype 整数 标 搜索规则。

可能值:
0 - (默认) 和/或;
2 - 或。
severities 整数/数组 返回只 指定问题严重性的主机。仅当问题对象是触发器时适用。
tags 数组/对象 仅返回 有指定标签的主机。 按标记进行精确匹配,并根据运算符的值按标记值区分大小写或不区分大小写。
格式: [{"标签": "<tag>","值": "<value>", "操作符": "<operator>"}, ...]
空数组将返回所有主机。

可能操作符的值:
0 - (默认) 包含;
1 - 等于。
inheritedTags 布尔值 返回 所有链接的模板中且带有“标签”的主机。 默认:

可能值:
true - 链接的模板还必须具有给定的 标签;
false - (默认)链接的模板标签将被忽略。
selectApplications 查询 在 applications](//zh/manual/api/reference/application/object)属性中返回来自主机的应用集。

支持count
selectDiscoveries 查询 在 discoveries](//zh/manual/api/reference/discoveryrule/object)属性中返回来自主机的底层自动发现。

支持count
selectDiscoveryRule 查询 在 discoveryRule](//zh/manual/api/reference/discoveryrule/object)属性中返回创建主机的底层自动发现规则。
selectGraphs 查询 在 graphs](//zh/manual/api/reference/graph/object)属性中返回来自主机的图表。

支持count
selectGroups query groups 属性中返回主机所属的主机组数据。
selectHostDiscovery 查询 在 hostDiscovery属性中返回主机自动发现对象。

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

支持
count。| |selectInterfaces|查询 在|interfaces](//zh/manual/api/reference/hostinterface/object)属性中返回主机的接口。

支持
count。| |selectInventory|查询 在|inventory](//zh/manual/api/reference/host/object#host_inventory)属性中返回主机清单。| |selectItems|查询 在|items](//zh/manual/api/reference/item/object)属性中返回主机监控项。

支持
count。| |selectMacros|查询 在|macros](//zh/manual/api/reference/usermacro/object)属性中返回主机宏。| |selectParentTemplates|查询 在|parentTemplates](//zh/manual/api/reference/template/object)属性中返回主机连接的模板。

支持
count。| |selectScreens|查询 在|screens](//zh/manual/api/reference/screen/object)属性中返回主机的屏幕。

支持
count。| |selectTags|query|在[tags](//zh/manual/api/reference/host/object#host_tag) 属性中返回主机标签。| |selectInheritedTags|query|在[inheritedTags](//zh/manual/api/reference/host/object#host_tag) 属性中返回链接到主机模板的标签。| |selectTriggers|查询 在|triggers](//zh/manual/api/reference/trigger/object)属性中返回主机的触发器。

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

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

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

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

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

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

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

可能值:
hostidhostnamestatus。| |countOutput|布尔值 以下|与[reference commentary](/zh/manual/api/reference_commentary#common_get_method_parameters)中详细描述的get`方法相同的参数。
editable 布尔值 ::
excludeSearch 布尔值 ::
limit 整数 : :
output 查询 : :
preservekeys 布尔值 ::
searchByAny 布尔值 ::
searchWildcardsEnabled 布尔值 ::
sortorder 字符串/数组 :::
startSearch 布尔值 ::

返回值

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

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

示例

通过名称获取数据

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

{  "jsonrpc": "2.0",  "method": "host.get",  "params": {  "filter": {  "host": [  "Zabbix server",  "Linux server"  ]  }  },  "auth": "038e1d7b1735c6a5436ee9eae095879e",  "id": 1 }

响应:

{  "jsonrpc": "2.0",  "result": [  {  "maintenances": [],  "hostid": "10160",  "proxy_hostid": "0",  "host": "Zabbix server",  "status": "0",  "disable_until": "0",  "error": "",  "available": "0",  "errors_from": "0",  "lastaccess": "0",  "ipmi_authtype": "-1",  "ipmi_privilege": "2",  "ipmi_username": "",  "ipmi_password": "",  "ipmi_disable_until": "0",  "ipmi_available": "0",  "snmp_disable_until": "0",  "snmp_available": "0",  "maintenanceid": "0",  "maintenance_status": "0",  "maintenance_type": "0",  "maintenance_from": "0",  "ipmi_errors_from": "0",  "snmp_errors_from": "0",  "ipmi_error": "",  "snmp_error": "",  "jmx_disable_until": "0",  "jmx_available": "0",  "jmx_errors_from": "0",  "jmx_error": "",  "name": "Zabbix server",  "description": "The Zabbix monitoring server.",  "tls_connect": "1",  "tls_accept": "1",  "tls_issuer": "",  "tls_subject": "",  "tls_psk_identity": "",  "tls_psk": ""  },  {  "maintenances": [],  "hostid": "10167",  "proxy_hostid": "0",  "host": "Linux server",  "status": "0",  "disable_until": "0",  "error": "",  "available": "0",  "errors_from": "0",  "lastaccess": "0",  "ipmi_authtype": "-1",  "ipmi_privilege": "2",  "ipmi_username": "",  "ipmi_password": "",  "ipmi_disable_until": "0",  "ipmi_available": "0",  "snmp_disable_until": "0",  "snmp_available": "0",  "maintenanceid": "0",  "maintenance_status": "0",  "maintenance_type": "0",  "maintenance_from": "0",  "ipmi_errors_from": "0",  "snmp_errors_from": "0",  "ipmi_error": "",  "snmp_error": "",  "jmx_disable_until": "0",  "jmx_available": "0",  "jmx_errors_from": "0",  "jmx_error": "",  "name": "Linux server",  "description": "",  "tls_connect": "1",  "tls_accept": "1",  "tls_issuer": "",  "tls_subject": "",  "tls_psk_identity": "",  "tls_psk": ""  }  ],  "id": 1 }

获取主机组

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

请求:

{  "jsonrpc": "2.0",  "method": "host.get",  "params": {  "output": ["hostid"],  "selectGroups": "extend",  "filter": {  "host": [  "Zabbix server"  ]  }  },  "auth": "038e1d7b1735c6a5436ee9eae095879e",  "id": 2 }

响应:

{  "jsonrpc": "2.0",  "result": [  {  "hostid": "10085",  "groups": [  {  "groupid": "2",  "name": "Linux servers",  "internal": "0",  "flags": "0"  },  {  "groupid": "4",  "name": "Zabbix servers",  "internal": "0",  "flags": "0"  }  ]  }  ],  "id": 2 }

获取关联的模板

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

{  "jsonrpc": "2.0",  "method": "host.get",  "params": {  "output": ["hostid"],  "selectParentTemplates": [  "templateid",  "name"  ],  "hostids": "10084"  },  "id": 1,  "auth": "70785d2b494a7302309b48afcdb3a401" }

响应:

{  "jsonrpc": "2.0",  "result": [  {  "hostid": "10084",  "parentTemplates": [  {  "name": "Template OS Linux",  "templateid": "10001"  },  {  "name": "Template App Zabbix Server",  "templateid": "10047"  }  ]  }  ],  "id": 1 }

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

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

{  "jsonrpc": "2.0",  "method": "host.get",  "params": {  "output": [  "host"  ],  "selectInventory": [  "os"  ],  "searchInventory": {  "os": "Linux"  }  },  "id": 2,  "auth": "7f9e00124c75e8f25facd5c093f3e9a0" }

响应:

{  "jsonrpc": "2.0",  "result": [  {  "hostid": "10084",  "host": "Zabbix server",  "inventory": {  "os": "Linux Ubuntu"  }  },  {  "hostid": "10107",  "host": "Linux server",  "inventory": {  "os": "Linux Mint"  }  }  ],  "id": 1 }

按主机标签进行检索

检索"Host name"标签等于 "Linux server" 的主机。

请求:

{  "jsonrpc": "2.0",  "method": "host.get",  "params": {  "output": ["hostid"],  "selectTags": "extend",  "evaltype": 0,  "tags": [  {  "tag": "Host name",  "value": "Linux server",  "operator": 1  }  ]  },  "auth": "7f9e00124c75e8f25facd5c093f3e9a0",  "id": 1 }

响应:

{  "jsonrpc": "2.0",  "result": [  {  "hostid": "10085",  "tags": [  {  "tag": "Host name",  "value": "Linux server"  },  {  "tag": "OS",  "value": "RHEL 7"  }  ]  }  ],  "id": 1 }

检索主机级别和其链接的父类模板中具有这些标签的主机。

请求:

{  "jsonrpc": "2.0",  "method": "host.get",  "params": {  "output": ["name"],  "tags": [{"tag": "A", "value": "1", "operator": "0"}],  "inheritedTags": true  },  "auth": "038e1d7b1735c6a5436ee9eae095879e",  "id": 1 }

响应:

{  "jsonrpc": "2.0",  "result": [  {  "hostid": "10623",  "name": "PC room 1"  },  {  "hostid": "10601",  "name": "Office"  }  ],  "id": 1 }

使用标签和模板标签进行检索

使用标签以及链接到父模板的所有标签检索主机。

请求:

{  "jsonrpc": "2.0",  "method": "host.get",  "params": {  "output": ["name"],  "hostids": 10502,  "selectTags": ["tag", "value"],  "selectInheritedTags": ["tag", "value"]  },  "auth": "038e1d7b1735c6a5436ee9eae095879e",  "id": 1 }

响应:

{  "jsonrpc": "2.0",  "result": [  {  "hostid": "10502",  "name": "Desktop",  "tags": [  {  "tag": "A",  "value": "1"  }  ],  "inheritedTags": [  {  "tag": "B",  "value": "2"  }  ]  }  ],  "id": 1 }

按问题严重性进行检索

检索有 "灾难" 级别问题的主机。

请求:

{  "jsonrpc": "2.0",  "method": "host.get",  "params": {  "output": ["name"],  "severities": 5  },  "auth": "038e1d7b1735c6a5436ee9eae095879e",  "id": 1 }

响应:

{  "jsonrpc": "2.0",  "result": [  {  "hostid": "10160",  "name": "Zabbix server"  }  ],  "id": 1 }

检索有 "平均" 和 "高" 级别问题的主机。

请求:

{  "jsonrpc": "2.0",  "method": "host.get",  "params": {  "output": ["name"],  "severities": [3, 4]  },  "auth": "038e1d7b1735c6a5436ee9eae095879e",  "id": 1 }

响应:

{  "jsonrpc": "2.0",  "result": [  {  "hostid": "20170",  "name": "Database"  },  {  "hostid": "20183",  "name": "workstation"  }  ],  "id": 1 }

参考

来源

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