Sidebar

zh:manual:api:reference:host:get

获取

描述

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_itemswith_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.