integer/array host.get(object parameters)
此方法允许根据指定的参数检索主机。
任何用户类型均可使用此方法。可以在用户角色设置中撤销调用方法的权限。详情参考用户角色获取更多信息。
(object)
定义所需输出的参数。
该方法支持以下参数。
参数 | 类型 | 描述 |
---|---|---|
groupids | ID/数组 | 仅返回属于指定组的hosts。 |
dserviceids | ID/数组 | 仅返回与指定发现服务相关的hosts。 |
graphids | ID/数组 | 仅返回具有指定图表的hosts。 |
hostids | ID/数组 | 仅返回具有指定host ID的hosts。 |
httptestids | ID/数组 | 仅返回具有指定web检查的hosts。 |
interfaceids | ID/数组 | 仅返回使用指定接口的hosts。 |
itemids | ID/数组 | 仅返回具有指定监控项的hosts。 |
maintenanceids | ID/数组 | 仅返回受指定维护影响的hosts。 |
monitored_hosts | 标志 | 仅返回受监控的hosts。 |
proxyids | ID/数组 | 仅返回由指定proxies监控的hosts。 |
proxy_groupids | ID/数组 | 仅返回由指定proxy组监控的hosts。 |
templated_hosts | 标志 | 返回hosts和模板两者。 |
templateids | ID/数组 | 仅返回链接到指定模板的hosts。 |
triggerids | ID/数组 | 仅返回具有指定触发器的hosts。 |
with_items | 标志 | 仅返回具有监控项的hosts。 覆盖 with_monitored_items 和with_simple_graph_items 参数。 |
with_item_prototypes | 标志 | 仅返回具有监控项原型的hosts。 覆盖 with_simple_graph_item_prototypes 参数。 |
with_simple_graph_item_prototypes | 标志 | 仅返回具有监控项原型的hosts,这些原型已启用创建且具有数值信息类型。 |
with_graphs | 标志 | 仅返回具有图表的hosts。 |
with_graph_prototypes | 标志 | 仅返回具有图表原型的hosts。 |
with_httptests | 标志 | 仅返回具有web检查的hosts。 覆盖 with_monitored_httptests 参数。 |
with_monitored_httptests | 标志 | 仅返回具有启用web检查的hosts。 |
with_monitored_items | 标志 | 仅返回具有启用监控项的hosts。 覆盖`with_simple |
(integer/array)
返回其中之一:
countOutput
参数, 则返回检索到的对象数量。获取主机名为"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
}
检索具有标签“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
}
]
},
"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
}
检索所有 "灾难" 问题的主机。
请求:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["name"],
"severities": 5
},
"id": 1
}
响应:
检索具有 "一般严重" 和 "严重" 问题的主机。
请求:
{
"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() in ui/include/classes/api/services/CHost.php.