获取

描述

integer/array hostgroup.get(object parameters)

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

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

参数

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

该方法支持以下参数。

参数 类型 描述
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 规则。
selectDiscoveryData query 返回 discoveryData 属性,其中包含主机群组发现对象。

每个主机群组发现对象都是一个链接到已发现主机群组的主机群组原型,并具有以下属性:
parent_group_prototypeid - (ID) 发现该主机群组所依据的主机群组原型 ID;
name - (string) 主机群组原型名称;
ts_delete - (timestamp) 不再被发现的主机群组将被删除的时间;
status - (int) 主机群组发现状态:
0 - (默认) 主机群组已被发现,
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
selectGroupDiscoveries query 返回 groupDiscoveries 属性,其中包含主机群组发现对象。

每个主机群组发现对象都是一个链接到已发现主机群组的主机群组原型。

此查询已弃用,请改用 selectDiscoveryData

返回值

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