integer/array host.get(object parameters)
该方法允许根据给定的参数检索主机。
此方法可供任何类型的用户使用。调用该方法的权限 可以在用户角色设置中撤销。更多信息请参见User roles。
(object)
参数定义了期望的输出。
该方法支持以下参数。
参数 | 数据类型 | 描述 |
---|---|---|
groupids | ID/array | 仅返回属于给定组的主机。 |
dserviceids | ID/array | 仅返回与给定发现服务相关的主机。 |
graphids | ID/array | 仅返回具有给定图表的主机。 |
hostids | ID/array | 仅返回具有给定主机 ID的主机。 |
httptestids | ID/array | 仅返回具有给定Web检查的主机。 |
interfaceids | ID/array | 仅返回使用给定接口的主机。 |
itemids | ID/array | 仅返回具有给定监控项的主机。 |
maintenanceids | ID/array | 仅返回受给定维护影响的主机。 |
monitored_hosts | flag | 仅返回被监控的主机。 |
proxyids | ID/array | 仅返回由给定proxies监控的主机。 |
proxy_groupids | ID/array | 仅返回由给定proxy 组监控的主机。 |
templated_hosts | flag | 返回主机和模板。 |
templateids | ID/array | 仅返回链接到给定模板的主机。 |
triggerids | ID/array | 仅返回具有给定触发器的主机。 |
with_items | flag | 仅返回具有监控项的主机。 覆盖 with_monitored_items 和 with_simple_graph_items 参数。 |
with_item_prototypes | flag | 仅返回具有监控项原型的主机。 覆盖 with_simple_graph_item_prototypes 参数。 |
with_simple_graph_item_prototypes | flag | 仅返回具有监控项原型,并且已启用创建且信息类型为数字的主机。 |
with_graphs | flag | 仅返回具有图表的主机。 |
with_graph_prototypes | flag | 仅返回具有图表原型的主机。 |
with_httptests | flag | 仅返回具有Web检查的主机。 覆盖 with_monitored_httptests 参数。 |
with_monitored_httptests | flag | 仅返回具有已启用Web检查的主机。 |
with_monitored_items | flag | 仅返回具有已启用监控项的主机。 覆盖 with_simple_graph_items 参数。 |
with_monitored_triggers | flag | 仅返回具有已启用触发器的主机。触发器中使用的所有监控项也必须已启用。 |
with_simple_graph_items | flag | 仅返回具有信息类型为数字的监控项的主机。 |
with_triggers | flag | 仅返回具有触发器的主机。 覆盖 with_monitored_triggers 参数。 |
withProblemsSuppressed | boolean | 返回具有被抑制问题的主机。 可能值: null - (默认) 所有主机;true - 仅具有被抑制问题的主机;false - 仅具有未被抑制问题的主机。 |
evaltype | integer | 标签搜索规则。 可能值: 0 - (默认) And/Or; 2 - Or。 |
severities | integer/array | 返回仅具有给定严重级别的问题的主机。仅当问题object是触发器时适用。 |
tags | object/array | 仅返回具有给定标签的主机。根据操作符值,按标签精确匹配或按标签值进行区分大小写或不区分大小写的搜索。 格式: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...] 。空的array返回所有主机。 可能的操作符值: 0 - (默认) 包含; 1 - 等于; 2 - 不包含; 3 - 不等于; 4 - 存在; 5 - 不存在。 |
inheritedTags | boolean | 返回具有给定tags 的主机,并且其所有链接的模板也具有该标签。可能值: true - 链接的模板也必须具有给定的tags ;false - (默认) 忽略链接模板的标签。 |
selectDiscoveries | query | 返回一个discoveries 属性,包含主机的低级别发现规则。支持 count 。 |
selectDiscoveryRule | query | 返回一个discoveryRule 属性,包含创建主机的低级别发现规则(来自VMware监控中的主机原型)。 |
selectGraphs | query | 返回一个graphs 属性,包含主机的图表。支持 count 。 |
selectHostDiscovery | query | 返回一个hostDiscovery 属性,包含主机的发现object数据。主机的发现object将发现的主机链接到主机原型或一个主机原型链接到LLD规则,并具有以下属性: host - (string) 主机原型的主机;hostid - (string) 发现的主机或主机原型的ID;parent_hostid - (string) 创建主机的主机原型的ID;parent_itemid - (string) 创建发现的主机的LLD规则的ID;lastcheck - (时间戳) 主机最后一次被发现的时间;status - (整数) 主机发现状态:0 - (默认) 主机已发现, 1 - 主机不再被发现; ts_delete - (时间戳) 不再被发现的一个主机将被删除的时间;ts_disable - (时间戳) 不再被发现的一个主机将被禁用的时间;disable_source - (整数) 指示主机是被LLD规则禁用还是手动禁用:0 - (默认) 自动禁用, 1 - 被LLD规则禁用。 |
selectHostGroups | query | 返回一个hostgroups 属性,包含主机所属的主机组数据。 |
selectHttpTests | query | 返回一个httpTests 属性,包含主机的Web场景。支持 count 。 |
selectInterfaces | query | 返回一个interfaces 属性,包含主机的接口。支持 count 。 |
selectInventory | query | 返回一个inventory 属性,包含主机的资产数据。 |
selectItems | query | 返回一个items 属性,包含主机的监控项。支持 count 。 |
selectMacros | query | 返回一个macros 属性,包含主机宏。 |
selectParentTemplates | query | 返回一个parentTemplates 属性,包含主机链接到的templates。除了模板object字段外,它还包含 link_type - (integer) 模板链接到主机的方式。可能值: 0 - (默认) 手动链接; 1 - 由LLD自动链接。 支持 count 。 |
selectDashboards | query | 返回一个dashboards 属性。支持 count 。 |
selectTags | query | 返回一个tags 属性,包含主机的标签。 |
selectInheritedTags | query | 返回一个inheritedTags 属性,包含链接到主机的所有模板上的标签。 |
selectTriggers | query | 返回一个triggers 属性,包含主机的触发器。支持 count 。 |
selectValueMaps | query | 返回一个valuemaps 属性,包含主机的值映射。 |
filter | object | 仅返回与给定过滤器完全匹配的结果。 接受一个object,其中键是属性名,值是单个值或要匹配的array值。 不支持 text 数据类型的属性。支持附加属性:主机-接口-object属性。 |
limitSelects | integer | 限制子查询返回的记录数。 适用于以下子查询: selectParentTemplates - 结果将按host 排序;selectInterfaces ;selectItems - 按name 排序;selectDiscoveries - 按name 排序;selectTriggers - 按description 排序;selectGraphs - 按name 排序;selectDashboards - 按name 排序。 |
search | object | 返回与给定模式匹配的结果(不区分大小写)。 接受一个object,其中键是属性名,值是要搜索的字符串。如果没有给出其他选项,这将执行一个 LIKE "%…%" 搜索。仅支持 string 和text 数据类型的属性。支持附加属性:主机-接口-object属性。 |
searchInventory | object | 返回具有与给定模式匹配的资产数据的主机(不区分大小写)。 接受一个object,其中键是属性名,值是要搜索的字符串。如果没有给出其他选项,这将执行一个 LIKE "%…%" 搜索。仅支持 string 和text 数据类型的属性。 |
sortfield | string/array | 按给定属性对结果进行排序。 可能值: hostid 、host 、name 、status 。 |
countOutput | boolean | 这些参数在通用get方法参数中描述。 |
editable | boolean | |
excludeSearch | boolean | |
limit | integer | |
output | query | |
preservekeys | boolean | |
searchByAny | boolean | |
searchWildcardsEnabled | boolean | |
sortorder | string/array | |
startSearch | boolean | |
selectGroups (deprecated) |
query | 此参数已弃用,请改用selectHostGroups 。返回一个 groups 属性,包含主机所属的主机组数据。 |
(integer/array)
返回以下之一:
countOutput
参数,则为检索到的 objects 的数量。检索有关两个名为“Zabbix server”和“Linux server”的主机的所有数据。
执行请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"filter": {
"host": [
"Zabbix server",
"Linux server"
]
}
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10160",
"proxyid": "0",
"host": "Zabbix server",
"status": "0",
"ipmi_authtype": "-1",
"ipmi_privilege": "2",
"ipmi_username": "",
"ipmi_password": "",
"maintenanceid": "0",
"maintenance_status": "0",
"maintenance_type": "0",
"maintenance_from": "0",
"name": "Zabbix server",
"flags": "0",
"description": "The Zabbix monitoring server.",
"tls_connect": "1",
"tls_accept": "1",
"tls_issuer": "",
"tls_subject": "",
"proxy_groupid": "0",
"monitored_by": "0",
"inventory_mode": "1",
"active_available": "1",
"assigned_proxyid": "0"
},
{
"hostid": "10167",
"proxyid": "0",
"host": "Linux server",
"status": "0",
"ipmi_authtype": "-1",
"ipmi_privilege": "2",
"ipmi_username": "",
"ipmi_password": "",
"maintenanceid": "0",
"maintenance_status": "0",
"maintenance_type": "0",
"maintenance_from": "0",
"name": "Linux server",
"flags": "0",
"description": "",
"tls_connect": "1",
"tls_accept": "1",
"tls_issuer": "",
"tls_subject": "",
"proxy_groupid": "0",
"monitored_by": "0",
"inventory_mode": "1",
"active_available": "1",
"assigned_proxyid": "0"
}
],
"id": 1
}
检索主机组,其中主机 "Zabbix server" 是成员。
执行请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["hostid"],
"selectHostGroups": "extend",
"filter": {
"host": [
"Zabbix server"
]
}
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10085",
"hostgroups": [
{
"groupid": "2",
"name": "Linux servers",
"flags": "0",
"uuid": "dc579cd7a1a34222933f24f52a68bcd8"
},
{
"groupid": "4",
"name": "Zabbix servers",
"flags": "0",
"uuid": "6f6799aa69e844b4b3918f779f2abf08"
}
]
}
],
"id": 1
}
检索链接到 主机 "10084" 的模板的 ID 和名称。
执行请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["hostid"],
"selectParentTemplates": [
"templateid",
"name"
],
"hostids": "10084"
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10084",
"parentTemplates": [
{
"name": "Linux",
"templateid": "10001"
},
{
"name": "Zabbix Server",
"templateid": "10047"
}
]
}
],
"id": 1
}
检索那些链接了 "10001"(Linux by Zabbix agent)模板的 主机。
执行请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["hostid", "name"],
"templateids": "10001"
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"templateid": "10001",
"hosts": [
{
"hostid": "10084",
"name": "Zabbix server"
},
{
"hostid": "10603",
"name": "Host 1"
},
{
"hostid": "10604",
"name": "Host 2"
}
]
}
],
"id": 1
}
检索在 主机 资产清单的 "OS" 字段中包含 "Linux" 的 主机。
执行请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"host"
],
"selectInventory": [
"os"
],
"searchInventory": {
"os": "Linux"
}
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10084",
"host": "Zabbix server",
"inventory": {
"os": "Linux Ubuntu"
}
},
{
"hostid": "10107",
"host": "Linux server",
"inventory": {
"os": "Linux Mint"
}
}
],
"id": 1
}
检索具有标签 "主机-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
}
]
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10085",
"tags": [
{
"tag": "host-name",
"value": "linux-server",
"automatic": "0"
},
{
"tag": "os",
"value": "rhel-7",
"automatic": "0"
}
]
}
],
"id": 1
}
检索不仅在 主机 层面具有这些标签,而且在其链接的父模板中也具有这些标签的 主机。
执行请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["name"],
"tags": [
{
"tag": "os",
"value": "rhel-7",
"operator": 1
}
],
"inheritedTags": true
},
"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"]
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10502",
"name": "Desktop",
"tags": [
{
"tag": "host-name",
"value": "linux-server"
},
{
"tag": "os",
"value": "rhel-7"
}
],
"inheritedTags": [
{
"tag": "class",
"value": "os"
},
{
"tag": "target",
"value": "linux"
},
{
"tag": "os",
"value": "rhel-7"
}
]
}
],
"id": 1
}
检索具有“Disaster(灾难)”问题的主机。
执行请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["name"],
"severities": 5
},
"id": 1
}
响应:
检索具有“Average(一般)”和“High(严重)”问题的主机。
执行请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["name"],
"severities": [3, 4]
},
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "20170",
"name": "Database"
},
{
"hostid": "20183",
"name": "workstation"
}
],
"id": 1
}
CHost::get() 在 ui/include/classes/api/services/CHost.php 中。