host.get

Description

integer/array host.get(object parameters)

The method allows to retrieve hosts 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
groupidsstring/arrayReturn only hosts that belong to the given groups.
dserviceidsstring/arrayReturn only hosts that are related to the given discovered services.
graphidsstring/arrayReturn only hosts that have the given graphs.
hostidsstring/arrayReturn only hosts with the given host IDs.
httptestidsstring/arrayReturn only hosts that have the given web checks.
interfaceidsstring/arrayReturn only hosts that use the given interfaces.
itemidsstring/arrayReturn only hosts that have the given items.
maintenanceidsstring/arrayReturn only hosts that are affected by the given maintenances.
monitored_hostsflagReturn only monitored hosts.
proxy_hostsflagReturn only proxies.
proxyidsstring/arrayReturn only hosts that are monitored by the given proxies.
templated_hostsflagReturn both hosts and templates.
templateidsstring/arrayReturn only hosts that are linked to the given templates.
triggeridsstring/arrayReturn only hosts that have the given triggers.
with_itemsflagReturn only hosts that have items.

Overrides the with_monitored_items and with_simple_graph_items parameters.
with_item_prototypesflagReturn only hosts that have item prototypes.

Overrides the with_simple_graph_item_prototypes parameter.
with_simple_graph_item_prototypesflagReturn only hosts that have item prototypes, which are enabled for creation and have numeric type of information.
with_graphsflagReturn only hosts that have graphs.
with_graph_prototypesflagReturn only hosts that have graph prototypes.
with_httptestsflagReturn only hosts that have web checks.

Overrides the with_monitored_httptests parameter.
with_monitored_httptestsflagReturn only hosts that have enabled web checks.
with_monitored_itemsflagReturn only hosts that have enabled items.

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

Overrides the with_monitored_triggers parameter.
withProblemsSuppressedbooleanReturn hosts that have suppressed problems.

Possible values:
null - (default) all hosts;
true - only hosts with suppressed problems;
false - only hosts with unsuppressed problems.
evaltypeintegerRules for tag searching.

Possible values:
0 - (default) And/Or;
2 - Or.
severitiesinteger/arrayReturn hosts that have only problems with given severities. Applies only if problem object is trigger.
tagsarray/objectReturn only hosts with given tags. Exact match by tag and case-sensitive or case-insensitive search by tag value depending on operator value.
Format: [{“tag”: “<tag>”, “value”: “<value>”, “operator”: “<operator>”}, …].
An empty array returns all hosts.

Possible operator values:
0 - (default) Contains;
1 - Equals;
2 - Not like;
3 - Not equal;
4 - Exists;
5 - Not exists.
inheritedTagsbooleanReturn hosts that have given tags also in all of their linked templates. Default:

Possible values:
true - linked templates must also have given tags;
false - (default) linked template tags are ignored.
selectDiscoveriesqueryReturn a discoveries property with host low-level discovery rules.

Supports count.
selectDiscoveryRulequeryReturn a discoveryRule property with the low-level discovery rule that created the host (from host prototype in VMware monitoring).
selectGraphsqueryReturn a graphs property with host graphs.

Supports count.
selectHostDiscoveryqueryReturn a hostDiscovery property with host discovery object data.

The host discovery object links a discovered host to a host prototype or a host prototypes to an LLD rule and has the following properties:
host - (string) host of the host prototype;
hostid - (string) ID of the discovered host or host prototype;
parent_hostid - (string) ID of the host prototype from which the host has been created;
parent_itemid - (string) ID of the LLD rule that created the discovered host;
lastcheck - (timestamp) time when the host was last discovered;
ts_delete - (timestamp) time when a host that is no longer discovered will be deleted.
selectHostGroupsqueryReturn a hostgroups property with host groups data that the host belongs to.
selectHttpTestsqueryReturn an httpTests property with host web scenarios.

Supports count.
selectInterfacesqueryReturn an interfaces property with host interfaces.

Supports count.
selectInventoryqueryReturn an inventory property with host inventory data.
selectItemsqueryReturn an items property with host items.

Supports count.
selectMacrosqueryReturn a macros property with host macros.
selectParentTemplatesqueryReturn a parentTemplates property with templates that the host is linked to.

In addition to Template object fields, it contains link_type - (integer) the way that the template is linked to host.
Possible values:
0 - (default) manually linked;
1 - automatically linked by LLD.

Supports count.
selectDashboardsqueryReturn a dashboards property.

Supports count.
selectTagsqueryReturn a tags property with host tags.
selectInheritedTagsqueryReturn an inheritedTags property with tags that are on all templates which are linked to host.
selectTriggersqueryReturn a triggers property with host triggers.

Supports count.
selectValueMapsqueryReturn a valuemaps property with host value maps.
filterobjectReturn only those results that exactly match the given filter.

Accepts an array, where the keys are property names, and the values are either a single value or an array of values to match against.

Allows filtering by interface properties.
limitSelectsintegerLimits the number of records returned by subselects.

Applies to the following subselects:
selectParentTemplates - results will be sorted by host;
selectInterfaces;
selectItems - sorted by name;
selectDiscoveries - sorted by name;
selectTriggers - sorted by description;
selectGraphs - sorted by name;
selectDashboards - sorted by name.
searchobjectReturn results that match the given wildcard search.

Accepts an array, where the keys are property names, and the values are strings to search for. If no additional options are given, this will perform a LIKE “%…%” search.

Allows searching by interface properties. Works only with text fields.
searchInventoryobjectReturn only hosts that have inventory data matching the given wildcard search.

This parameter is affected by the same additional parameters as search.
sortfieldstring/arraySort the result by the given properties.

Possible values: hostid, host, name, status.
countOutputbooleanThese parameters being common for all get methods are described in detail in the reference commentary.
editableboolean
excludeSearchboolean
limitinteger
outputquery
preservekeysboolean
searchByAnyboolean
searchWildcardsEnabledboolean
sortorderstring/array
startSearchboolean
selectGroups
(deprecated)
queryThis parameter is deprecated, please use selectHostGroups instead.
Return a groups property with host groups data that the host belongs to.

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 hosts named “Zabbix server” and “Linux server”.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "filter": {
  6. "host": [
  7. "Zabbix server",
  8. "Linux server"
  9. ]
  10. }
  11. },
  12. "id": 1
  13. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10160",
  6. "proxy_hostid": "0",
  7. "host": "Zabbix server",
  8. "status": "0",
  9. "lastaccess": "0",
  10. "ipmi_authtype": "-1",
  11. "ipmi_privilege": "2",
  12. "ipmi_username": "",
  13. "ipmi_password": "",
  14. "maintenanceid": "0",
  15. "maintenance_status": "0",
  16. "maintenance_type": "0",
  17. "maintenance_from": "0",
  18. "name": "Zabbix server",
  19. "flags": "0",
  20. "description": "The Zabbix monitoring server.",
  21. "tls_connect": "1",
  22. "tls_accept": "1",
  23. "tls_issuer": "",
  24. "tls_subject": "",
  25. "inventory_mode": "1",
  26. "active_available": "1"
  27. },
  28. {
  29. "hostid": "10167",
  30. "proxy_hostid": "0",
  31. "host": "Linux server",
  32. "status": "0",
  33. "ipmi_authtype": "-1",
  34. "ipmi_privilege": "2",
  35. "ipmi_username": "",
  36. "ipmi_password": "",
  37. "maintenanceid": "0",
  38. "maintenance_status": "0",
  39. "maintenance_type": "0",
  40. "maintenance_from": "0",
  41. "name": "Linux server",
  42. "flags": "0",
  43. "description": "",
  44. "tls_connect": "1",
  45. "tls_accept": "1",
  46. "tls_issuer": "",
  47. "tls_subject": "",
  48. "inventory_mode": "1",
  49. "active_available": "1"
  50. }
  51. ],
  52. "id": 1
  53. }

Retrieving host groups

Retrieve host groups that the host “Zabbix server” is a member of.

Request:

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

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10085",
  6. "hostgroups": [
  7. {
  8. "groupid": "2",
  9. "name": "Linux servers",
  10. "flags": "0",
  11. "uuid": "dc579cd7a1a34222933f24f52a68bcd8"
  12. },
  13. {
  14. "groupid": "4",
  15. "name": "Zabbix servers",
  16. "flags": "0",
  17. "uuid": "6f6799aa69e844b4b3918f779f2abf08"
  18. }
  19. ]
  20. }
  21. ],
  22. "id": 1
  23. }

Retrieving linked templates

Retrieve the IDs and names of templates linked to host “10084”.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": ["hostid"],
  6. "selectParentTemplates": [
  7. "templateid",
  8. "name"
  9. ],
  10. "hostids": "10084"
  11. },
  12. "id": 1
  13. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10084",
  6. "parentTemplates": [
  7. {
  8. "name": "Linux",
  9. "templateid": "10001"
  10. },
  11. {
  12. "name": "Zabbix Server",
  13. "templateid": "10047"
  14. }
  15. ]
  16. }
  17. ],
  18. "id": 1
  19. }

Searching by host inventory data

Retrieve hosts that contain “Linux” in the host inventory “OS” field.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": [
  6. "host"
  7. ],
  8. "selectInventory": [
  9. "os"
  10. ],
  11. "searchInventory": {
  12. "os": "Linux"
  13. }
  14. },
  15. "id": 1
  16. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10084",
  6. "host": "Zabbix server",
  7. "inventory": {
  8. "os": "Linux Ubuntu"
  9. }
  10. },
  11. {
  12. "hostid": "10107",
  13. "host": "Linux server",
  14. "inventory": {
  15. "os": "Linux Mint"
  16. }
  17. }
  18. ],
  19. "id": 1
  20. }

Searching by host tags

Retrieve hosts that have tag “Host name” equal to “Linux server”.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": ["hostid"],
  6. "selectTags": "extend",
  7. "evaltype": 0,
  8. "tags": [
  9. {
  10. "tag": "Host name",
  11. "value": "Linux server",
  12. "operator": 1
  13. }
  14. ]
  15. },
  16. "id": 1
  17. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10085",
  6. "tags": [
  7. {
  8. "tag": "Host name",
  9. "value": "Linux server"
  10. },
  11. {
  12. "tag": "OS",
  13. "value": "RHEL 7"
  14. }
  15. ]
  16. }
  17. ],
  18. "id": 1
  19. }

Retrieve hosts that have these tags not only on host level but also in their linked parent templates.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": ["name"],
  6. "tags": [
  7. {
  8. "tag": "A",
  9. "value": "1",
  10. "operator": 1
  11. }
  12. ],
  13. "inheritedTags": true
  14. },
  15. "id": 1
  16. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10623",
  6. "name": "PC room 1"
  7. },
  8. {
  9. "hostid": "10601",
  10. "name": "Office"
  11. }
  12. ],
  13. "id": 1
  14. }

Searching host with tags and template tags

Retrieve a host with tags and all tags that are linked to parent templates.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": ["name"],
  6. "hostids": 10502,
  7. "selectTags": ["tag", "value"],
  8. "selectInheritedTags": ["tag", "value"]
  9. },
  10. "id": 1
  11. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10502",
  6. "name": "Desktop",
  7. "tags": [
  8. {
  9. "tag": "A",
  10. "value": "1"
  11. }
  12. ],
  13. "inheritedTags": [
  14. {
  15. "tag": "B",
  16. "value": "2"
  17. }
  18. ]
  19. }
  20. ],
  21. "id": 1
  22. }

Searching hosts by problem severity

Retrieve hosts that have “Disaster” problems.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": ["name"],
  6. "severities": 5
  7. },
  8. "id": 1
  9. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10160",
  6. "name": "Zabbix server"
  7. }
  8. ],
  9. "id": 1
  10. }

Retrieve hosts that have “Average” and “High” problems.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "host.get",
  4. "params": {
  5. "output": ["name"],
  6. "severities": [3, 4]
  7. },
  8. "id": 1
  9. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "20170",
  6. "name": "Database"
  7. },
  8. {
  9. "hostid": "20183",
  10. "name": "workstation"
  11. }
  12. ],
  13. "id": 1
  14. }

See also

Source

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