integer/array host.get(object parameters)
此方法允许根据指定的参数获取主机.
(object)
定义期望输出的参数.
该方法支持以下参数.
参数 类 | 描述 | |
---|---|---|
groupids | 字符串/数组 返回指定 | 机组的主机. |
applicationids | 字符串/数组 返回指定 | 用集的主机. |
dserviceids | 字符串/数组 返回与指 | 自动发现服务相关的主机. |
graphids | 字符串/数组 返回包含 | 指定图表的主机. |
hostids | 字符串/数组 返回指定 | 机ID的主机. |
httptestids | 字符串/数组 返回指定 | 页监测的主机. |
interfaceids | 字符串/数组 返回指定 | 口的主机. |
itemids | 字符串/数组 返回指定 | 控项的主机. |
maintenanceids | 字符串/数组 返回指定 | 护的主机. |
monitored_hosts | 标识 返 | 被监控的主机. |
proxy_hosts | 标识 返 | 代理服务器. |
proxyids | 字符串/数组 返回被代 | 服务器监控的主机. |
templated_hosts | 标识 返 | 主机和模板. |
templateids | 字符串/数组 返回使用 | 定模板的主机. |
triggerids | 字符串/数组 返回指定 | 发器的主机. |
with_items | 标识 返 | 含有监控项的主机. 覆盖 with_monitored_items 和 with_simple_graph_items 参数. |
with_applications | 标识 返 | 含有应用集的主机. |
with_graphs | 标识 返 | 含有图表的主机. |
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 参数. |
withInventory | 标识 返 | 含有资产清单数据的主机. |
selectGroups | 查询 在 | groups属性中返回主机所属的主机组.| |selectApplications|查询 在|applications 属性中返回来自主机的应用集.支持 count . |
selectDiscoveries | 查询 在 | discoveries属性中返回来自主机的底层自动发现. count.| |selectDiscoveryRule|查询 在|discoveryRule 属性中返回创建主机的底层自动发现规则. |
selectGraphs | 查询 在 | graphs属性中返回来自主机的图表. count.| |selectHostDiscovery|查询 在|hostDiscovery 属性中返回主机自动发现对象.主机自动发现对象将一个自动发现的主机和一个原型主机连接起来,或者把一个原型主机和一个底层自动发现规则连接起来,并且含有以下属性: host - (字符串) 主机原型的主机;hostid - (字符串) 主机原型和自动发现主机的ID;parent_hostid - (字符串) 已经创建主机的主机原型ID;parent_itemid - (字符串) 创建自动发现主机的底层自动发现规则ID;lastcheck - (时间戳) 最近一次发现主机的时间;ts_delete - (时间戳) 当不再自动发现的主机将被删除的时间. |
selectHttpTests | 查询 在 | httpTests属性中返回主机的web场景. count.| |selectInterfaces|查询 在|interfaces 属性中返回主机的接口.支持 count . |
selectInventory | 查询 在 | inventory属性中返回主机清单.| |selectItems|查询 在|item 属性中返回主机监控项.支持 count . |
selectMacros | 查询 在 | macros属性中返回主机宏.| |selectParentTemplates|查询 在|parentTemplates 属性中返回主机连接的模板.支持 count . |
selectScreens | 查询 在 | screens属性中返回主机的屏幕. count.| |selectTriggers|查询 在|triggers 属性中返回主机的触发器.支持 count . |
filter | 对象 仅 | 回完全匹配指定筛选后的结果. 接受数组,键为属性名,值为一个单一值或者一个要匹配的数组. 允许通过接口属性进行过滤. |
limitSelects | 整数 限 | 由子查询返回的记录数量. 适用于以下子查询: selectParentTemplates - 结果将按照host 排序;selectInterfaces ;selectItems - 按name 排序;selectDiscoveries - 按name 排序;selectTriggers - 按description 排序;selectGraphs - 按name 排序;selectApplications - 按name 排序;selectScreens - 按name 排序. |
search | 对象 返 | 与通配符相匹配的结果. 接受数组,键为属性名,值为待匹配搜索的字符串 . 如果没有指定的额外选项,将会以LIKE “%…%”方式执行搜索. 允许通过接口属性搜索,仅对文本域产生影响. |
searchInventory | 对象 仅 | 回与指定通配符搜索资产清单数据匹配的主机. 这个参数同时受 search 参数影响. |
sortfield | 字符串/数组 结果按给 | 的属性进行排序. 可能值: hostid , host , name , status . |
countOutput | 布尔值 以下 | 是与reference commentary中详细描述的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
}
CHost::get() in frontends/php/include/classes/api/services/CHost.php.
Retrieve hosts that have "Disaster" problems.
Request:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["name"],
"severities": 5
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
Retrieve hosts that have "Average" and "High" problems.
Request:
{
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": ["name"],
"severities": [3, 4]
},
"auth": "038e1d7b1735c6a5436ee9eae095879e",
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": [
{
"hostid": "20170",
"name": "Database"
},
{
"hostid": "20183",
"name": "workstation"
}
],
"id": 1
}
CHost::get() in ui/include/classes/api/services/CHost.php.