Zabbix Documentation 2.0

3.04.05.0 (current)| In development:5.2 (devel)| Unsupported:1.82.02.22.43.23.44.24.4Guidelines

User Tools

Site Tools


manual:appendix:api:host:get

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
manual:appendix:api:host:get [2015/06/03 08:23]
manual:appendix:api:host:get [2019/01/28 14:49] (current)
sasha <code js> => <code java>
Line 1: Line 1:
 +===== host.get =====
  
 +==== Description ====
 +
 +''​integer/​array host.get(object **parameters**)''​
 +
 +The method allows to retrieve hosts according to the given parameters.
 +
 +==== Parameters ====
 +
 +''​(object)''​ Parameters defining the desired output. ​
 +
 +The method supports the following parameters.
 +
 +^Parameter^Type^Description^
 +|groupids|string/​array| Return only hosts that belong to the given groups. | 
 +|applicationids|string/​array| Return only hosts that have the given applications. |
 +|dserviceids|string/​array| Return only hosts that are related to the given discovered services.|
 +|graphids|string/​array| Return only hosts that have the given graphs. |
 +|hostids|string/​array| Return only hosts with the given host IDs. |
 +|httptestids|string/​array| Return only hosts that have the given web checks.|
 +|interfaceids|string/​array| Return only hosts that use the given interfaces. |
 +|itemids|string/​array| Return only hosts that have the given items. |
 +|maintenanceids|string/​array| Return only hosts that are affected by the given maintenances. |
 +|monitored_hosts|flag| Return only monitored hosts. |
 +|proxy_hosts|flag| Return only proxies. |
 +|proxyids|string/​array| Return only hosts that are monitored by the given proxies. |
 +|templated_hosts|flag| Return both hosts and templates. |
 +|templateids|string/​array| Return only hosts that are linked to the given templates. |
 +|triggerids|string/​array| Return only hosts that have the given triggers. |
 +^  |||
 +|with_items|flag|Return only hosts that have items. \\ \\ Overrides the ''​with_monitored_items'',​ ''​with_historical_items''​ and ''​with_simple_graph_items''​ parameters. |
 +|with_applications|flag|Return only hosts that have applications. |
 +|with_graphs|flag|Return only hosts that have graphs. |
 +|with_historical_items|flag|Return only hosts that have enabled or not supported items with historical data. \\ \\ Overrides the ''​with_simple_graph_items''​ parameter. |
 +|with_httptests|flag|Return only hosts that have web checks. \\ \\ Overrides the ''​with_monitored_httptests''​ parameter. |
 +|with_monitored_httptests|flag|Return only hosts that have enabled web checks. |
 +|with_monitored_items|flag|Return only hosts that have enabled items. \\ \\ Overrides the ''​with_historical_items''​ and ''​with_simple_graph_items''​ parameters. |
 +|with_monitored_triggers|flag|Return only hosts that have enabled triggers. All of the items used in the trigger must also be enabled. |
 +|with_simple_graph_items|flag|Return only hosts that have items with numeric type of information. |
 +|with_triggers|flag|Return only hosts that have triggers. \\ \\ Overrides the ''​with_monitored_triggers''​ parameter. |
 +|withInventory|flag|Return only hosts that have inventory data.|
 +^  |||
 +|selectGroups|query|Return the host groups that the host belongs to in the ''​groups''​ property. \\ \\ Does not support ''​shorten''​ or arrays of properties.|
 +|selectApplications|query|Return the applications from the host in the ''​applications''​ property. \\ \\ Supports ''​count'';​ does not support ''​shorten''​. |
 +|selectDiscoveries|query|Return the low level discoveries from the host in the ''​discoveries''​ property. \\ \\ Supports ''​count'';​ does not support ''​shorten''​. |
 +|selectGraphs|query|Return the graphs from the host in the ''​graphs''​ property. \\ \\ Supports ''​count'';​ does not support ''​shorten''​. |
 +|selectInterfaces|query|Return the host interfaces in the ''​interfaces''​ property. \\ \\ Supports ''​count'';​ does not support ''​shorten''​. |
 +|selectInventory|boolean/​array|Return the host inventory from the host in the ''​inventory''​ property. \\ \\ Possible values are ''​true''​ to return all of the data, or an array of property names to return only specific properties.|
 +|selectItems|query|Return the items from the host in the ''​items''​ property. \\ \\ Supports ''​count'';​ does not support ''​shorten''​. |
 +|selectMacros|query|Return the macros from the host in the ''​macros''​ property. \\ \\ Does not support ''​shorten''​ or arrays of properties.|
 +|selectParentTemplates|query|Return the templates that the host is linked to in the ''​parentTemplates''​ property. \\ \\ Supports ''​count'';​ does not support ''​shorten''​. |
 +|selectScreens|query|Return the screens from the host in the ''​screens''​ property. \\ \\ Supports ''​count'';​ does not support ''​shorten''​. |
 +|selectTriggers|query|Return the triggers from the host in the ''​triggers''​ property. \\ \\ Supports ''​count'';​ does not support ''​shorten''​. |
 +^  |||
 +|filter ​ | object |Return 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. |
 +| limitSelects | integer | Limits 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'';​ \\ ''​selectApplications''​ - sorted by ''​name'';​ \\ ''​selectScreens''​ - sorted by ''​name''​. |
 +|search ​ | object |Return 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. |
 +|sortfield|string/​array| Sort the result by the given properties. \\ \\ Possible values are: ''​hostid'',​ ''​host'',​ ''​name'',​ ''​status''​. ​ |
 +|countOutput|flag|These parameters being common for all ''​get''​ methods are described in detail on the [[manual:​appendix:​api:​generic#​common_get_method_parameters|Generic Zabbix API information]] page.  |
 +| editable |boolean|:::​|
 +| excludeSearch |flag|:::|
 +| limit |integer|:::​|
 +| nodeids |string/​array|:::​|
 +| output |query|:::|
 +| preservekeys |flag|:::|
 +| search | object |:::|
 +| searchByAny |boolean|:::​|
 +| searchWildcardsEnabled |boolean|:::​|
 +| sortorder | string/​array | ::: |
 +| startSearch |flag|:::|
 +
 +==== 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:
 +<code java>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​method":​ "​host.get",​
 +    "​params":​ {
 +        "​output":​ "​extend",​
 +        "​filter":​ {
 +            "​host":​ [
 +                "​Zabbix server",​
 +                "Linux server"​
 +            ]
 +        }
 +    },
 +    "​auth":​ "​038e1d7b1735c6a5436ee9eae095879e",​
 +    "​id":​ 1
 +}
 +</​code>​
 +
 +Response:
 +<code java>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​result":​ [
 +        {
 +            "​maintenances":​ [],
 +            "​hostid":​ "​10160",​
 +            "​proxy_hostid":​ "​0",​
 +            "​host":​ "​Zabbix server",​
 +            "​status":​ "​0",​
 +            "​disable_until":​ "​0",​
 +            "​error":​ "",​
 +            "​available":​ "​0",​
 +            "​errors_from":​ "​0",​
 +            "​lastaccess":​ "​0",​
 +            "​ipmi_authtype":​ "​-1",​
 +            "​ipmi_privilege":​ "​2",​
 +            "​ipmi_username":​ "",​
 +            "​ipmi_password":​ "",​
 +            "​ipmi_disable_until":​ "​0",​
 +            "​ipmi_available":​ "​0",​
 +            "​snmp_disable_until":​ "​0",​
 +            "​snmp_available":​ "​0",​
 +            "​maintenanceid":​ "​0",​
 +            "​maintenance_status":​ "​0",​
 +            "​maintenance_type":​ "​0",​
 +            "​maintenance_from":​ "​0",​
 +            "​ipmi_errors_from":​ "​0",​
 +            "​snmp_errors_from":​ "​0",​
 +            "​ipmi_error":​ "",​
 +            "​snmp_error":​ "",​
 +            "​jmx_disable_until":​ "​0",​
 +            "​jmx_available":​ "​0",​
 +            "​jmx_errors_from":​ "​0",​
 +            "​jmx_error":​ "",​
 +            "​name":​ "​Zabbix server"​
 +        },
 +        {
 +            "​maintenances":​ [],
 +            "​hostid":​ "​10167",​
 +            "​proxy_hostid":​ "​0",​
 +            "​host":​ "Linux server",​
 +            "​status":​ "​0",​
 +            "​disable_until":​ "​0",​
 +            "​error":​ "",​
 +            "​available":​ "​0",​
 +            "​errors_from":​ "​0",​
 +            "​lastaccess":​ "​0",​
 +            "​ipmi_authtype":​ "​-1",​
 +            "​ipmi_privilege":​ "​2",​
 +            "​ipmi_username":​ "",​
 +            "​ipmi_password":​ "",​
 +            "​ipmi_disable_until":​ "​0",​
 +            "​ipmi_available":​ "​0",​
 +            "​snmp_disable_until":​ "​0",​
 +            "​snmp_available":​ "​0",​
 +            "​maintenanceid":​ "​0",​
 +            "​maintenance_status":​ "​0",​
 +            "​maintenance_type":​ "​0",​
 +            "​maintenance_from":​ "​0",​
 +            "​ipmi_errors_from":​ "​0",​
 +            "​snmp_errors_from":​ "​0",​
 +            "​ipmi_error":​ "",​
 +            "​snmp_error":​ "",​
 +            "​jmx_disable_until":​ "​0",​
 +            "​jmx_available":​ "​0",​
 +            "​jmx_errors_from":​ "​0",​
 +            "​jmx_error":​ "",​
 +            "​name":​ "Linux server"​
 +        }
 +    ],
 +    "​id":​ 1
 +}
 +</​code>​
 +
 +=== Retrieving host groups ===
 +
 +Retrieve names of the groups host "​Zabbix server"​ is member of, but no host details themselves.
 +
 +Request:
 +<code java>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​method":​ "​host.get",​
 +    "​params":​ {
 +        "​output":​ ["​hostid"​],​
 +        "​selectGroups":​ "​extend",​
 +        "​filter":​ {
 +            "​host":​ [
 +                "​Zabbix server"​
 +            ]
 +        }
 +    },
 +    "​auth":​ "​038e1d7b1735c6a5436ee9eae095879e",​
 +    "​id":​ 2
 +}
 +</​code>​
 +
 +Response:
 +<code java>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​result":​ [
 +        {
 +            "​groups":​ [
 +                {
 +                    "​groupid":​ "​2",​
 +                    "​name":​ "Linux servers",​
 +                    "​internal":​ "​0"​
 +                },
 +                {
 +                    "​groupid":​ "​4",​
 +                    "​name":​ "​Zabbix servers",​
 +                    "​internal":​ "​0"​
 +                }
 +            ],
 +            "​hostid":​ "​10085"​
 +        }
 +    ],
 +    "​id":​ 2
 +}
 +</​code>​
 +
 +=== Retrieving linked templates ===
 +
 +Retrieve the IDs and names of templates linked to host "​10084"​.
 +
 +Request:
 +<code java>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​method":​ "​host.get",​
 +    "​params":​ {
 +        "​output":​ ["​hostid"​],​
 +        "​selectParentTemplates":​ [
 +            "​templateid",​
 +            "​name"​
 +        ],
 +        "​hostids":​ "​10084"​
 +    },
 +    "​id":​ 1,
 +    "​auth":​ "​70785d2b494a7302309b48afcdb3a401"​
 +}
 +</​code>​
 +
 +Response:
 +<code java>
 +{
 +    "​jsonrpc":​ "​2.0",​
 +    "​result":​ [
 +        {
 +            "​parentTemplates":​ [
 +                {
 +                    "​name":​ "​Template OS Linux",​
 +                    "​templateid":​ "​10001"​
 +                },
 +                {
 +                    "​name":​ "​Template App Zabbix Server",​
 +                    "​templateid":​ "​10047"​
 +                }
 +            ],
 +            "​hostid":​ "​10084"​
 +        }
 +    ],
 +    "​id":​ 1
 +}
 +</​code>​
 +
 +
 +==== See also ====
 +
 +  * [[manual:​appendix:​api:​hostgroup:​definitions#​object_details|Host group]]
 +  * [[manual:​appendix:​api:​template:​definitions#​object_details|Template]]
 +  * [[manual:​appendix:​api:​usermacro:​definitions#​hosttemplate_level_macro|User macro]]
 +  * [[manual:​appendix:​api:​hostinterface:​definitions#​host_interface|Host interface]]
 +
 +==== Source ====
 +
 +CHost::​get() in //​frontends/​php/​api/​classes/​CHost.php//​.