[comment]: # ({37c3aad7-37c3aad7})
# dhost.get

[comment]: # ({/37c3aad7-37c3aad7})

[comment]: # ({a1812e61-1309d6bb})
### Description

`integer/array dhost.get(object parameters)`

The method allows to retrieve discovered hosts according to the given
parameters.

::: noteclassic
This method is available to users of any type. Permissions
to call the method can be revoked in user role settings. See [User
roles](/manual/web_interface/frontend_sections/users/user_roles)
for more information.
:::

[comment]: # ({/a1812e61-1309d6bb})

[comment]: # ({5f644960-061d7cf0})
### Parameters

`(object)` Parameters defining the desired output.

The method supports the following parameters.

|Parameter|[Type](/manual/api/reference_commentary#data-types)|Description|
|--|--|------|
|dhostids|ID/array|Return only discovered hosts with the given IDs.|
|druleids|ID/array|Return only discovered hosts that have been created by the given discovery rules.|
|dserviceids|ID/array|Return only discovered hosts that are running the given services.|
|selectDRules|query|Return a [`drules`](/manual/api/reference/drule/object) property with an array of the discovery rules that detected the host.|
|selectDServices|query|Return a [`dservices`](/manual/api/reference/dservice/object) property with the discovered services running on the host.<br><br>Supports `count`.|
|limitSelects|integer|Limits the number of records returned by subselects.<br><br>Applies to the following subselects:<br>`selectDServices` - results will be sorted by `dserviceid`.|
|sortfield|string/array|Sort the result by the given properties.<br><br>Possible values: `dhostid`, `druleid`.|
|countOutput|boolean|These parameters are described in the [reference commentary](/manual/api/reference_commentary#common-get-method-parameters).|
|editable|boolean|^|
|excludeSearch|boolean|^|
|filter|object|^|
|limit|integer|^|
|output|query|^|
|preservekeys|boolean|^|
|search|object|^|
|searchByAny|boolean|^|
|searchWildcardsEnabled|boolean|^|
|sortorder|string/array|^|
|startSearch|boolean|^|

[comment]: # ({/5f644960-061d7cf0})

[comment]: # ({7223bab1-7223bab1})
### Return values

`(integer/array)` Returns either:

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

[comment]: # ({/7223bab1-7223bab1})

[comment]: # ({b41637d2-b41637d2})
### Examples

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({c08efc78-4b9c1e99})
#### Retrieve discovered hosts by discovery rule

Retrieve all hosts and the discovered services they are running that
have been detected by discovery rule "4".

[Request](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "dhost.get",
    "params": {
        "output": "extend",
        "selectDServices": "extend",
        "druleids": "4"
    },
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "dservices": [
                {
                    "dserviceid": "1",
                    "dhostid": "1",
                    "type": "4",
                    "key_": "",
                    "value": "",
                    "port": "80",
                    "status": "0",
                    "lastup": "1337697227",
                    "lastdown": "0",
                    "dcheckid": "5",
                    "ip": "192.168.1.1",
                    "dns": "station.company.lan"
                }
            ],
            "dhostid": "1",
            "druleid": "4",
            "status": "0",
            "lastup": "1337697227",
            "lastdown": "0"
        },
        {
            "dservices": [
                {
                    "dserviceid": "2",
                    "dhostid": "2",
                    "type": "4",
                    "key_": "",
                    "value": "",
                    "port": "80",
                    "status": "0",
                    "lastup": "1337697234",
                    "lastdown": "0",
                    "dcheckid": "5",
                    "ip": "192.168.1.4",
                    "dns": "john.company.lan"
                }
            ],
            "dhostid": "2",
            "druleid": "4",
            "status": "0",
            "lastup": "1337697234",
            "lastdown": "0"
        },
        {
            "dservices": [
                {
                    "dserviceid": "3",
                    "dhostid": "3",
                    "type": "4",
                    "key_": "",
                    "value": "",
                    "port": "80",
                    "status": "0",
                    "lastup": "1337697234",
                    "lastdown": "0",
                    "dcheckid": "5",
                    "ip": "192.168.1.26",
                    "dns": "printer.company.lan"
                }
            ],
            "dhostid": "3",
            "druleid": "4",
            "status": "0",
            "lastup": "1337697234",
            "lastdown": "0"
        },
        {
            "dservices": [
                {
                    "dserviceid": "4",
                    "dhostid": "4",
                    "type": "4",
                    "key_": "",
                    "value": "",
                    "port": "80",
                    "status": "0",
                    "lastup": "1337697234",
                    "lastdown": "0",
                    "dcheckid": "5",
                    "ip": "192.168.1.7",
                    "dns": "mail.company.lan"
                }
            ],
            "dhostid": "4",
            "druleid": "4",
            "status": "0",
            "lastup": "1337697234",
            "lastdown": "0"
        }
    ],
    "id": 1
}
```

[comment]: # ({/c08efc78-4b9c1e99})

[comment]: # ({184a9e84-e6b09247})
### See also

-   [Discovered
    service](/manual/api/reference/dservice/object#discovered-service)
-   [Discovery rule](/manual/api/reference/drule/object#discovery-rule)

[comment]: # ({/184a9e84-e6b09247})

[comment]: # ({8dc0c01a-8dc0c01a})
### Source

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

[comment]: # ({/8dc0c01a-8dc0c01a})
