hostgroup.get

描述

integer/array hostgroup.get(object parameters)

该方法允许根据给定参数检索主机组。

此方法对任何类型的用户都可用。 在用户角色设置中可以撤销调用该方法的权限。 有关更多信息,请参见 User roles

参数

(object) 定义所需输出的参数。

该方法支持以下参数。

Parameter Type Description
graphids ID/array 仅返回包含给定图形的主机组。
groupids ID/array 仅返回具有给定主机组 ID 的主机组。
hostids ID/array 仅返回包含给定主机的主机组。
maintenanceids ID/array 仅返回受给定维护影响的主机组。
triggerids ID/array 仅返回包含具有给定触发器的主机的主机组。
with_graphs boolean 仅返回包含具有图形的主机的主机组。
with_graph_prototypes boolean 仅返回包含具有图形原型的主机的主机组。
with_hosts boolean 仅返回包含主机的主机组。
with_httptests boolean 仅返回包含具有 web 检查的主机的主机组。

覆盖 with_monitored_httptests 参数。
with_items boolean 仅返回包含具有监控项的主机的主机组。

覆盖 with_monitored_itemswith_simple_graph_items 参数。
with_item_prototypes boolean 仅返回包含具有监控项原型的主机的主机组。

覆盖 with_simple_graph_item_prototypes 参数。
with_simple_graph_item_prototypes boolean 仅返回包含具有监控项原型的主机的主机组,这些原型已启用创建且信息类型为数值。
with_monitored_httptests boolean 仅返回包含已启用 web 检查的主机的主机组。
with_monitored_hosts boolean 仅返回包含受监控主机的主机组。
with_monitored_items boolean 仅返回包含具有已启用监控项的主机的主机组。

覆盖 with_simple_graph_items 参数。
with_monitored_triggers boolean 仅返回包含具有已启用触发器的主机的主机组。触发器中使用的所有监控项也必须已启用。
with_simple_graph_items boolean 仅返回包含具有数值监控项的主机的主机组。
with_triggers boolean 仅返回包含具有触发器的主机的主机组。

覆盖 with_monitored_triggers 参数。
selectDiscoveryRules query 返回一个 discoveryRules 属性,其中包含发现该主机组的 LLD 规则。
selectGroupDiscoveries query 返回一个 groupDiscoveries 属性,其中包含主机组发现对象。

每个主机组发现对象都是一个与已发现主机组关联的主机组原型,并具有以下属性:
parent_group_prototypeid - (ID) 发现该主机组所依据的主机组原型 ID;
name - (string) 主机组原型名称;
lastcheck - (timestamp) 主机组上次被发现的时间;
ts_delete - (timestamp) 不再被发现的主机组将被删除的时间;
status - (int) 主机组发现状态:
0 - (default) 主机组已被发现,
1 - 主机组不再被发现。
selectHostPrototypes query 返回一个 hostPrototypes 属性,其中包含发现此主机组的主机原型。
selectHosts query 返回一个 hosts 属性,其中包含属于该主机组的主机。

支持 count
limitSelects integer 限制子查询返回的记录数。

适用于以下子查询:
selectHosts - 结果将按 host 排序。
sortfield string/array 按给定属性对结果排序。

可能的值:groupidname
countOutput boolean 这些参数在参考说明中有描述。
editable boolean
excludeSearch boolean
filter object
limit integer
output query
preservekeys boolean
search object
searchByAny boolean
searchWildcardsEnabled boolean
sortorder string/array
startSearch boolean
monitored_hosts
(deprecated)
flag 此参数已弃用,请改用 with_monitored_hosts
仅返回包含受监控主机的主机组。
real_hosts
(deprecated)
flag 此参数已弃用,请改用 with_hosts
仅返回包含主机的主机组。

返回值

(integer/array) 返回以下之一:

  • 对象数组
  • 检索到的对象数量(如果使用了 countOutput 参数)

示例

按名称检索数据

检索名为 "Zabbix servers" 和 "Linux servers" 的两个主机组的所有数据。

请求:

{
    "jsonrpc": "2.0",
    "method": "hostgroup.get",
    "params": {
        "output": "extend",
        "filter": {
            "name": [
                "Zabbix servers",
                "Linux servers"
            ]
        }
    },
    "id": 1
}

响应:

{
    "jsonrpc": "2.0",
    "result": [
        {
            "groupid": "2",
            "name": "Linux servers",
            "flags": "0",
            "uuid": "dc579cd7a1a34222933f24f52a68bcd8"
        },
        {
            "groupid": "4",
            "name": "Zabbix servers",
            "flags": "0",
            "uuid": "6f6799aa69e844b4b3918f779f2abf08"
        }
    ],
    "id": 1
}

另请参阅

来源

CHostGroup::get() 在 ui/include/classes/api/services/CHostGroup.php 中。