2022 Zabbix中国峰会
2022 Zabbix中国峰会

hostgroup.get

描述

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 flag 只返回包含有图形的主机的主机组。
with_graph_prototypes flag 只返回包含图形原型主机的主机组。
with_hosts flag 只返回包含主机的主机组。
with_httptests flag 只返回包含网络检查主机的主机组。

覆盖 with_monitored_httptests 参数。
with_items flag 只返回包含监控项主机的主机组。

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

覆盖 with_simple_graph_item_prototypes 参数。
with_simple_graph_item_prototypes flag 只返回包含具有监控项原型的主机的主机组,这些主机已启用创建并具有数字类型信息。
with_monitored_httptests flag 只返回包含已启用网络检查的主机的主机组。
with_monitored_hosts flag 只返回包含受监控主机的主机组。
with_monitored_items flag 只返回包含已启用监控项的主机的主机组。

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

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

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

支持 count.
limitSelects integer 限制子选择返回的记录数。

适用于以下子选择:
selectHosts - 结果将按 host 排序。
sortfield string/array 根据给定的属性对结果进行排序。

可能的值:groupid, name.
countOutput boolean 这些参数是所有 get方法的通用参数,详见 参考评论 页面。
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",
                   "internal": "0"
               },
               {
                   "groupid": "4",
                   "name": "Zabbix servers",
                   "internal": "0"
               }
           ],
           "id": 1
       }

另请参考

来源

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