[comment]: # translation:outdated

[comment]: # ({f8d4c2e5-f8d4c2e5})
# 获取

[comment]: # ({/f8d4c2e5-f8d4c2e5})

[comment]: # ({1365c68e-08ff22f2})


### 描述

`hostgroup.get(对象参数)整数/数组`

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

::: noteclassic
这个方法仅允许任何用户类型。可以在用户角色中撤销调用方法的权限设置。详情参考 [用户角色](/manual/web_interface/frontend_sections/administration/user_roles)
:::

[comment]: # ({/1365c68e-08ff22f2})

[comment]: # ({77cfb4f7-7f042696})
### 参数

`(对象)` 参数定义所需的输出。

该方法支持以下参数。

|参数|[类](/manual/api/reference_commentary#data_types)|描述|
|---------|---------------------------------------------------|-----------|
|graphids|字符串/数组|只返回包含给定图形的主机或模板的主机组。|
|groupids|字符串/数组|只返回具有给定主机组id的主机组。|
|hostids|字符串/数组|只返回包含给定主机的主机组。|
|maintenanceids|字符串/数组|只返回受给定维护影响的主机组。|
|monitored\_hosts|标记|只返回包含监控主机的主机组。|
|real\_hosts|标记|只返回包含主机的主机组。|
|templated\_hosts|标记|只返回包含模板的主机组。|
|templateids|字符串/数组|只返回包含给定模板的主机组。|
|triggerids|字符串/数组|只返回包含具有给定触发器的主机或模板的主机组。|
|with\_graphs|标记|只返回包含有图形的主机的主机组。|
|with\_graph\_prototypes|标记|只返回包含带有图形原型的主机的主机组。|
|with\_hosts\_and\_templates|标记|只返回包含主机 **或** 模板的主机组。|
|with\_httptests|标记|只返回包含web检查主机的主机组。<br><br>覆盖 `with_monitored_httptests` 参数。|
|with\_items|标记|只返回包含有监控项的主机或模板的主机组。<br><br>覆盖 `with_monitored_items` 和 `with_simple_graph_items` 参数。|
|with\_item\_prototypes|标记|只返回包含带有监控项原型的主机的主机组。<br><br>覆盖 `with_simple_graph_item_prototypes` 参数。|
|with\_simple\_graph\_item\_prototypes|标记|只返回包含具有监控项原型的主机的主机组，监控项原型支持创建并具有数字类型的信息。|
|with\_monitored\_httptests|标记|只返回包含启用web检查的主机的主机组。|
|with\_monitored\_items|标记|只返回包含启用监控项的主机或模板的主机组。<br><br>覆盖 `with_simple_graph_items` 参数。|
|with\_monitored\_triggers|标记|只返回包含启用触发器的主机的主机组。触发器中使用的所有监控项也必须启用。|
|with\_simple\_graph\_items|标记|只返回包含带有数字监控项的主机的主机组。|
|with\_triggers|标记|只返回包含有触发器的主机的主机组。<br><br>覆盖 `with_monitored_triggers` 参数。|
|selectDiscoveryRule|查询|返回 [发现规则](/manual/api/reference/drule/对象) 属性和创建主机组的LLD规则。|
|selectGroupDiscovery|查询|返回 `groupDiscovery` 属性和主机组发现对象.<br><br>发现主机组对象将发现的主机组链接到主机组原型，具有以下属性:<br>`groupid` - `(字符串)` 发现的主机组ID;<br>`lastcheck` - `(时间戳)` 最后发现主机组的时间;<br>`name` - `(字符串)` 主机组原型的名称;<br>`parent_group_prototypeid` - `(字符串)` 创建主机组的主机组原型ID;<br>`ts_delete` - `(时间戳)` 当主机组未被发现时，删除该主机组的时间。|
|selectHosts|查询|返回[主机](/manual/api/reference/host/对象)属性和属于主机组的主机。<br><br>支持 `count`.|
|selectTemplates|查询|返回 [模板](/manual/api/reference/template/对象) 属性和属于主机组的模板。<br><br>支持 `count`.|
|limitSelects|整型|限制子查询返回的记录数量。<br><br>适用于下列子查询项:<br>`selectHosts` - 结果将按 `host` 排序;<br>`selectTemplates` - r结果将按 `host` 排序。|
|sortfield|字符串/数组|根据给定的属性对结果进行排序。<br><br>可能的值是: `groupid`, `name`.|
|countOutput|布尔值|这些对所有 `get` 方法通用的参数在 [参考注释](/manual/api/reference_commentary#common_get_method_parameters) 中有详细描述。|
|editable|布尔值|^|
|excludeSearch|布尔值|^|
|filter|对象|^|
|limit|整型|^|
|output|查询|^|
|preservekeys|布尔值|^|
|search|对象|^|
|searchByAny|布尔值|^|
|searchWildcardsEnabled|布尔值|^|
|sortorder|字符串/数组|^|
|startSearch|布尔值|^|

[comment]: # ({/77cfb4f7-7f042696})

[comment]: # ({7223bab1-7223bab1})

### 返回值

`(整数/数组)` 返回其中之一:

-   一组对象;
-   如果使用了 `countOutput` 参数,返回对象的数量。

[comment]: # ({/7223bab1-7223bab1})

[comment]: # ({b41637d2-b41637d2})
### 示例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({9334c875-8ed2756a})
#### 按名称检索数据

检索关于“Zabbix servers”和“Linux servers”两个主机组的所有数据。

请求:

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

响应:

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "groupid": "2",
            "name": "Linux servers",
            "internal": "0"
        },
        {
            "groupid": "4",
            "name": "Zabbix servers",
            "internal": "0"
        }
    ],
    "id": 1
}
```

[comment]: # ({/9334c875-8ed2756a})

[comment]: # ({c6e0749d-e5f0abe1})
### 另请参考

-   [主机](/manual/api/reference/host/object#host)
-   [模板](/manual/api/reference/template/object#template)

[comment]: # ({/c6e0749d-e5f0abe1})

[comment]: # ({1e72ea39-1e72ea39})
### 源代码

CHostGroup::get() in *ui/include/classes/api/services/CHostGroup.php*.

[comment]: # ({/1e72ea39-1e72ea39})
