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.
selectGroupsqueryReturn a groups property with host groups data that the host belongs to.
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.
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.

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 are: 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

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. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  13. "id": 1
  14. }

Response:

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

Retrieving host groups

Retrieve names of the groups host “Zabbix server” is member of, but no host details themselves.

Request:

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

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": [
  4. {
  5. "hostid": "10085",
  6. "groups": [
  7. {
  8. "groupid": "2",
  9. "name": "Linux servers",
  10. "internal": "0",
  11. "flags": "0"
  12. },
  13. {
  14. "groupid": "4",
  15. "name": "Zabbix servers",
  16. "internal": "0",
  17. "flags": "0"
  18. }
  19. ]
  20. }
  21. ],
  22. "id": 2
  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. "auth": "70785d2b494a7302309b48afcdb3a401"
  14. }

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": 2,
  16. "auth": "7f9e00124c75e8f25facd5c093f3e9a0"
  17. }

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. "auth": "7f9e00124c75e8f25facd5c093f3e9a0",
  17. "id": 1
  18. }

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": [{"tag": "A", "value": "1", "operator": "0"}],
  7. "inheritedTags": true
  8. },
  9. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  10. "id": 1
  11. }

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. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  11. "id": 1
  12. }

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. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  9. "id": 1
  10. }

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. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  9. "id": 1
  10. }

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.