integer/array host.get(object parameters)
此方法允许根据指定的参数获取主机。
(object)
定义期望输出的参数
该方法支持以下参数。
参数 类 | 说明 | |
---|---|---|
groupids | string/array | 仅返回指定主机组所属的主机。 |
applicationids | string/array | 仅返回含有指定应用集的主机。 |
dserviceids | string/array | 仅返回与指定自动发现服务相关的主机。 |
graphids | string/array | 仅返回含有指定图表的主机。 |
hostids | string/array | 仅返回指定主机ID的主机。 |
httptestids | string/array | 仅返回含有指定网页监测的主机。 |
interfaceids | string/array | 仅返回使用指定接口的主机。 |
itemids | string/array | 仅返回含有指定监控项的主机。 |
maintenanceids | string/array | 仅返回被指定管理影响到的主机。 |
monitored_hosts | flag | 仅返回被监控的主机。 |
proxy_hosts | flag | 仅返回代理服务器。 |
proxyids | string/array | 仅返回被代理服务器监控的主机。 |
templated_hosts | flag | 同时返回主机和模板。 |
templateids | string/array | 仅返回与指定模板链接的主机。 |
triggerids | string/array | 仅返回含有指定触发器的主机。 |
with_items | flag | 仅返回含有监控项的主机。 Overrides the with_monitored_items and with_simple_graph_items parameters. 覆盖“with_monitored_items”和“with_simple_graph_items”参数。 |
with_applications | flag | 仅返回含有应用集的主机。 |
with_graphs | flag | 仅返回含有图表的主机。 |
with_httptests | flag | 仅返回含有网页监测的主机。 Overrides the with_monitored_httptests parameter.覆盖“with_monitored_httptests”参数。 |
with_monitored_httptests | flag | 仅返回启用网页监测的主机。 |
with_monitored_items | .仅返回启用监控项的主机。 Overrides the with_simple_graph_items parameter.覆盖with_simple_graph_items 参数。 |
|
with_monitored_triggers | flag | Return only hosts that have enabled triggers. All of the items used in the trigger must also be enabled.仅返回启用触发器的主机。所有在触发器中使用到的监控项必须也要启用。 |
with_simple_graph_items | flag | 仅返回含有数字类信息监控项的主机。 |
with_triggers | flag | 仅返回含有触发器的主机。 Overrides the with_monitored_triggers parameter.覆盖“with_monitored_triggers”参数。 |
withInventory | flag | 仅返回含有资产清单数据的主机。 |
selectGroups | query | 返回在groups属性中主机所属的主机组。 |
selectApplications | query | 返回在applications属性中来自主机的应用集。 Supports count .支持count |
selectDiscoveries | query | 返回在discoveries属性中来自主机的底层自动发现。 Supports count .支持count。 |
selectDiscoveryRule | query | R 返回在discoveryRule属性中创建主机的底层自动发现规则。 |
selectGraphs | query | 返回在graphs属性中来自主机的图表。 Supports count .支持count。 |
selectHostDiscovery | query | 返回在hostDiscovery属性中的主机自动发现对象。 主机自动发现对象将一个自动发现的主机和一个原型主机连接起来,或者把一个原型主机和一个底层自动发现规则连接起来,并且含有以下属性: host - (string) host of the host prototype;字符串)原型主机的主机。hostid - (string) ID of the discovered host or host prototype;(字符串)自动发现的主机或原型主机的ID。parent_hostid - (string) ID of the host prototype from which the host has been created; 字符串)创建主机的原型主机ID。parent_itemid - (string) ID of the LLD rule that created the discovered host;(字符串)创建自动发现主机的底层自动发现规则ID。lastcheck - (timestamp) time when the host was last discovered; (时间戳)当最近一次自动发现主机时的时间。ts_delete - (timestamp) time when a host that is no longer discovered will be deleted.(时间戳)当不再自动发现的主机将被删除的时间。 |
selectHttpTests | query | Return the web scenarios from the host in the httpTests property. 返回在httpTests属性中主机里的网页应用场景。Supports count .支持count。 |
selectInterfaces | query返回在interfaces属性中的主机接口。 Supports count .支持count。 |
|
selectInventory | query | 返回在inventory属性中主机里的主机资产清单。 |
selectItems | query | 返回在items属性中主机里的监控项。 Supports count . 支持count。 |
selectMacros | query | 返回在macros属性中主机里的宏。 |
selectParentTemplates | query | 返回在parentTemplates属性中与主机关联的模板。 Supports count .支持count。 |
selectScreens | query | 返回在screens属性中主机里的屏幕。 Supports count .支持count。 |
selectTriggers | query | 返回在triggers属性中主机里的触发器。 Supports count . 支持count。 |
filter | object | 仅返回完全匹配指定筛选后的结果。 接受一个数组,其键值为属性名,其值要么是一个单一的值,要么是一个匹配的数组值。 Allows filtering by interface properties.允许通过接口属性筛选。 |
limitSelects | integer | 限定由子查询返回的记录数量。 适用于以下子查询: selectParentTemplates - results will be sorted by host ;结果将由host排序;selectInterfaces ;selectItems - sorted by name ;由name排序;selectDiscoveries - sorted by name ;由name排序;selectTriggers - sorted by description ;由description排序;selectGraphs - sorted by name ;由name排序;selectApplications - sorted by name ; 由name排序;selectScreens - sorted by name . 由name排序; |
search | object | Return results that match the given wildcard search.返回与指定通配符搜索匹配的结果。 Accepts an array, where the keys are property names, and the values are strings to search for. If no additional options are given, this will perform a LIKE "%…%" search.接受一个数组,其中键值是属性名,其值为搜索到的字符串。如果没有指定的额外选项,将会以LIKE “%…%”方式执行搜索。Allows searching by interface properties. Works only with text fields.允许通过接口属性搜索,仅对文本域产生影响。 |
searchInventory | object | 仅返回与指定通配符搜索资产清单数据匹配的主机。 This parameter is affected by the same additional parameters as search . 这个参数被相同其他参数,比如参数search所影响。 |
sortfield | string/array | 用指定的属性排序结果。 Possible values are: hostid , host , name , status .可能的值为:hostid,host,name,status。 |
countOutput | flag | These parameters being common for all get methods are described in detail in the reference commentary. 在reference commentary中详细描述了所有“get”方法的共同参数. |
editable | boolean | |
excludeSearch | flag | |
limit | integer | |
output | query | |
preservekeys | flag | |
searchByAny | boolean | |
searchWildcardsEnabled | boolean | |
sortorder | string/array | |
startSearch | flag |
(integer/array)
Returns either:返回其中任一:
countOutput
parameter has been used.如果已经使用了“countOutput”参数,则检索对象的计数.Retrieve all data about two hosts named "Zabbix server" and "Linux server".检索所有关于主机名为“Zabbix server”和“Linux server”的数据。
Request:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": "extend",
"filter": {
"host": [
"Zabbix server",
"Linux server"
]
}
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
{
"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
}
Retrieve names of the groups host "Zabbix server" is member of, but no host details themselves. 检索主机“Zabbix server”隶属于的组名,但是不检索主机本身的详情。
Request:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["hostid"],
"selectGroups": "extend",
"filter": {
"host": [
"Zabbix server"
]
}
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 2
}
Response:
{
"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
}
Retrieve the IDs and names of templates linked to host "10084".检索主机“10084”相关模板的ID和名称。
Request:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["hostid"],
"selectParentTemplates": [
"templateid",
"name"
],
"hostids": "10084"
},
"id": 1,
"auth": "70785d2b494a7302309b48afcdb3a401"
}
Response:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10084",
"parentTemplates": [
{
"name": "Template OS Linux",
"templateid": "10001"
},
{
"name": "Template App Zabbix Server",
"templateid": "10047"
}
]
}
],
"id": 1
}
Retrieve hosts that contain "Linux" in the host inventory "OS" field.检索在资产清单“操作系统”字段中包含“Linux”的主机。
Request:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": [
"host"
],
"selectInventory": [
"os"
],
"searchInventory": {
"os": "Linux"
}
},
"id": 2,
"auth": "7f9e00124c75e8f25facd5c093f3e9a0"
}
Response:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "10084",
"host": "Zabbix server",
"inventory": {
"os": "Linux Ubuntu"
}
},
{
"hostid": "10107",
"host": "Linux server",
"inventory": {
"os": "Linux Mint"
}
}
],
"id": 1
}
CHost::get() in frontends/php/include/classes/api/services/CHost.php.