integer/array host.get(object parameters)
该方法允许根据给定参数检索主机.
此方法可供任何类型的用户使用. 调用该方法的权限可以在用户角色设置中撤销. 更多信息请参阅User roles.
(object)
定义所需输出的参数.
该方法支持以下参数.
参数 | 数据类型 | 描述 |
---|---|---|
groupids | string/array | 仅返回属于指定组的主机. |
dserviceids | string/array | 仅返回与指定发现服务相关的主机. |
graphids | string/array | 仅返回具有指定图形的主机. |
hostids | string/array | 仅返回具有指定主机 ID的主机. |
httptestids | string/array | 仅返回具有指定Web检查的主机. |
interfaceids | string/array | 仅返回使用指定接口的主机. |
itemids | string/array | 仅返回具有指定监控项的主机. |
maintenanceids | string/array | 仅返回受指定维护影响的主机. |
monitored_hosts | flag | 仅返回受监控的主机. |
proxy_hosts | flag | 仅返回proxies. |
proxyids | string/array | 仅返回由指定proxies监控的主机. |
templated_hosts | flag | 同时返回主机和模板. |
templateids | string/array | 仅返回链接到指定模板的主机. |
triggerids | string/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 - (默认) 与/或; 2 - 或. |
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 . |
selectGroups | query | 返回包含主机所属组数据的groups属性. |
selectHostDiscovery | query | 返回包含主机发现object数据的hostDiscovery 属性.主机发现object将发现的主机链接到一个主机原型或将一个主机原型链接到LLD规则, 并具有以下属性: host - (string) 主机原型的主机;hostid - (string) 发现的主机或主机原型的ID;parent_hostid - (string) 创建主机的主机原型ID;parent_itemid - (string) 创建发现主机的LLD规则ID;lastcheck - (时间戳) 主机上次被发现的时间;ts_delete - (时间戳) 不再发现的一个主机将被删除的时间. |
selectHttpTests | query | 返回包含主机Web场景的httpTests属性. 支持 count . |
selectInterfaces | query | 返回包含主机接口的interfaces属性. 支持 count . |
selectInventory | query | 返回包含主机库存数据的主机资产清单属性. |
selectItems | query | 返回包含主机监控项的items属性. 支持 count . |
selectMacros | query | 返回包含主机宏的macros属性. |
selectParentTemplates | query | 返回包含主机链接模板的parentTemplates属性. 支持 count . |
selectDashboards | query | 返回dashboards属性. 支持 count . |
selectTags | query | 返回包含主机标签的主机标签属性. |
selectInheritedTags | query | 返回包含链接到主机的所有模板上标签的主机标签属性. |
selectTriggers | query | 返回包含主机触发器的triggers属性. 支持 count . |
selectValueMaps | query | 返回包含主机值映射的valuemaps属性. |
filter | object | 仅返回完全匹配给定过滤器的结果. 接受一个array, 其中键是属性名称, 值是要匹配的单个值或值array. 允许按接口属性过滤. 不适用于 text 字段. |
limitSelects | integer | 限制子查询返回的记录数. 适用于以下子查询: selectParentTemplates - 结果将按host 排序;selectInterfaces ;selectItems - 按name 排序;selectDiscoveries - 按name 排序;selectTriggers - 按description 排序;selectGraphs - 按name 排序;selectDashboards - 按name 排序. |
search | object | 返回匹配给定模式的结果(不区分大小写). 接受一个array, 其中键是属性名称, 值是要搜索的字符串. 如果未提供其他选项, 将执行 LIKE "%…%" 搜索.允许按接口属性搜索. 仅适用于 string 和text 字段. |
searchInventory | object | 仅返回库存数据匹配给定通配符搜索的主机. 此参数受与 search 相同的附加参数影响. |
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 |
(integer/array)
返回以下两种情况之一:
countOutput
参数。获取两个名为"Zabbix server"和"Linux服务器"的主机的所有数据。
请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"filter": {
"host": [
"Zabbix server",
"Linux server"
]
}
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10160",
"proxy_hostid": "0",
"host": "Zabbix server",
"status": "0",
"lastaccess": "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": "",
"inventory_mode": "1"
},
{
"hostid": "10167",
"proxy_hostid": "0",
"host": "Linux server",
"status": "0",
"lastaccess": "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": "",
"inventory_mode": "1"
}
],
"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": "Linux",
"templateid": "10001"
},
{
"name": "Zabbix Server",
"templateid": "10047"
}
]
}
],
"id": 1
}
获取已关联"10001"(由Zabbix agent提供的Linux)模板的主机
请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["hostid", "name"],
"templateids": "10001"
},
"auth": "70785d2b494a7302309b48afcdb3a401",
"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": 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
}
获取标签"主机名"等于"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
}
检索存在"Disaster"级别问题的主机
请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["name"],
"severities": 5
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
响应:
检索存在"Average"和"High"级别问题的主机
请求:
{
"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() 位于 ui/include/classes/api/services/CHost.php 文件中。