Zabbix Documentation 3.4

2.23.04.04.2 (current)In development:4.4 (devel)Unsupported:1.82.02.43.23.4

User Tools

Site Tools


Sidebar

zh:manual:api:reference:host:get

host.get

Description 说明

integer/array host.get(object parameters)

此方法允许根据指定的参数获取主机。

Parameters参数

(object) 定义期望输出的参数

该方法支持以下参数。

参数类型说明
groupidsstring/array 仅返回指定主机组所属的主机。
applicationidsstring/array 仅返回含有指定应用集的主机。
dserviceidsstring/array 仅返回与指定自动发现服务相关的主机。
graphidsstring/array 仅返回含有指定图表的主机。
hostidsstring/array 仅返回指定主机ID的主机。
httptestidsstring/array 仅返回含有指定网页监测的主机。
interfaceidsstring/array 仅返回使用指定接口的主机。
itemidsstring/array 仅返回含有指定监控项的主机。
maintenanceidsstring/array 仅返回被指定管理影响到的主机。
monitored_hostsflag 仅返回被监控的主机。
proxy_hostsflag 仅返回代理服务器。
proxyidsstring/array 仅返回被代理服务器监控的主机。
templated_hostsflag 同时返回主机和模板。
templateidsstring/array 仅返回与指定模板链接的主机。
triggeridsstring/array 仅返回含有指定触发器的主机。
with_itemsflag仅返回含有监控项的主机。

Overrides the with_monitored_items and with_simple_graph_items parameters. 覆盖“with_monitored_items”和“with_simple_graph_items”参数。
with_applicationsflag 仅返回含有应用集的主机。
with_graphsflag仅返回含有图表的主机。
with_httptestsflag仅返回含有网页监测的主机。

Overrides the with_monitored_httptests parameter.覆盖“with_monitored_httptests”参数。
with_monitored_httptestsflag仅返回启用网页监测的主机。
with_monitored_items.仅返回启用监控项的主机。

Overrides the with_simple_graph_items parameter.覆盖with_simple_graph_items参数。
with_monitored_triggersflagReturn only hosts that have enabled triggers. All of the items used in the trigger must also be enabled.仅返回启用触发器的主机。所有在触发器中使用到的监控项必须也要启用。
with_simple_graph_itemsflag仅返回含有数字类信息监控项的主机。
with_triggersflag仅返回含有触发器的主机。

Overrides the with_monitored_triggers parameter.覆盖“with_monitored_triggers”参数。
withInventoryflag仅返回含有资产清单数据的主机。
selectGroupsquery返回在groups属性中主机所属的主机组。
selectApplicationsquery 返回在applications属性中来自主机的应用集。

Supports count.支持count
selectDiscoveriesquery 返回在discoveries属性中来自主机的底层自动发现。

Supports count.支持count。
selectDiscoveryRule query R 返回在discoveryRule属性中创建主机的底层自动发现规则。
selectGraphsquery返回在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.(时间戳)当不再自动发现的主机将被删除的时间。
selectHttpTestsqueryReturn the web scenarios from the host in the httpTests property. 返回在httpTests属性中主机里的网页应用场景。

Supports count.支持count。
selectInterfacesquery返回在interfaces属性中的主机接口。

Supports count.支持count。
selectInventoryquery 返回在inventory属性中主机里的主机资产清单。
selectItemsquery返回在items属性中主机里的监控项。

Supports count. 支持count。
selectMacrosquery返回在macros属性中主机里的宏。
selectParentTemplatesquery返回在parentTemplates属性中与主机关联的模板。

Supports count.支持count。
selectScreensquery返回在screens属性中主机里的屏幕。

Supports count.支持count。
selectTriggersquery返回在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所影响。
sortfieldstring/array 用指定的属性排序结果。

Possible values are: hostid, host, name, status.可能的值为:hostid,host,name,status。
countOutputflagThese 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:返回其中任一:

  • an array of objects;一组对象;
  • the count of retrieved objects, if the 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
}

Retrieving host groups 检索主机组

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
}

Retrieving linked templates 检索相关模板

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
}

Searching by host inventory data 根据主机资产清单数据搜索

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
}

See also 参见

Source 来源

CHost::get() in frontends/php/include/classes/api/services/CHost.php.