hostgroup.get

Description

integer/array hostgroup.get(object parameters)

The method allows to retrieve host groups according to the given parameters.

This method is available to users of any type. Permissions to call the method can be revoked in user role settings. See User roles for more information.

Parameters

(object) Parameters defining the desired output.

The method supports the following parameters.

ParameterTypeDescription
graphidsstring/arrayReturn only host groups that contain hosts with the given graphs.
groupidsstring/arrayReturn only host groups with the given host group IDs.
hostidsstring/arrayReturn only host groups that contain the given hosts.
maintenanceidsstring/arrayReturn only host groups that are affected by the given maintenances.
triggeridsstring/arrayReturn only host groups that contain hosts with the given triggers.
with_graphsflagReturn only host groups that contain hosts with graphs.
with_graph_prototypesflagReturn only host groups that contain hosts with graph prototypes.
with_hostsflagReturn only host groups that contain hosts.
with_httptestsflagReturn only host groups that contain hosts with web checks.

Overrides the with_monitored_httptests parameter.
with_itemsflagReturn only host groups that contain hosts with items.

Overrides the with_monitored_items and with_simple_graph_items parameters.
with_item_prototypesflagReturn only host groups that contain hosts with item prototypes.

Overrides the with_simple_graph_item_prototypes parameter.
with_simple_graph_item_prototypesflagReturn only host groups that contain hosts with item prototypes, which are enabled for creation and have numeric type of information.
with_monitored_httptestsflagReturn only host groups that contain hosts with enabled web checks.
with_monitored_hostsflagReturn only host groups that contain monitored hosts.
with_monitored_itemsflagReturn only host groups that contain hosts with enabled items.

Overrides the with_simple_graph_items parameter.
with_monitored_triggersflagReturn only host groups that contain hosts with enabled triggers. All of the items used in the trigger must also be enabled.
with_simple_graph_itemsflagReturn only host groups that contain hosts with numeric items.
with_triggersflagReturn only host groups that contain hosts with triggers.

Overrides the with_monitored_triggers parameter.
selectDiscoveryRulequeryReturn a discoveryRule property with the LLD rule that created the host group.
selectGroupDiscoveryqueryReturn a groupDiscovery property with the host group discovery object.

The host group discovery object links a discovered host group to a host group prototype and has the following properties:
groupid - (string) ID of the discovered host group;
lastcheck - (timestamp) time when the host group was last discovered;
name - (string) name of the host group prototype;
parent_group_prototypeid - (string) ID of the host group prototype from which the host group has been created;
ts_delete - (timestamp) time when a host group that is no longer discovered will be deleted.
selectHostsqueryReturn a hosts property with the hosts that belong to the host group.

Supports count.
limitSelectsintegerLimits the number of records returned by subselects.

Applies to the following subselects:
selectHosts - results will be sorted by host.
sortfieldstring/arraySort the result by the given properties.

Possible values: groupid, name.
countOutputbooleanThese parameters being common for all get methods are described in detail in the reference commentary page.
editableboolean
excludeSearchboolean
filterobject
limitinteger
outputquery
preservekeysboolean
searchobject
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean
monitored_hosts
(deprecated)
flagThis parameter is deprecated, please use with_monitored_hosts instead.
Return only host groups that contain monitored hosts.
real_hosts
(deprecated)
flagThis parameter is deprecated, please use with_hosts instead.
Return only host groups that contain hosts.

Return values

(integer/array) Returns either:

  • an array of objects;
  • the count of retrieved objects, if the countOutput parameter has been used.

Examples

Retrieving data by name

Retrieve all data about two host groups named “Zabbix servers” and “Linux servers”.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "hostgroup.get",
  4. "params": {
  5. "output": "extend",
  6. "filter": {
  7. "name": [
  8. "Zabbix servers",
  9. "Linux servers"
  10. ]
  11. }
  12. },
  13. "id": 1
  14. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "groupid": "2",
  6. "name": "Linux servers",
  7. "internal": "0"
  8. },
  9. {
  10. "groupid": "4",
  11. "name": "Zabbix servers",
  12. "internal": "0"
  13. }
  14. ],
  15. "id": 1
  16. }

See also

Source

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