[comment]: # translation:outdated

[comment]: # ({65bbffce-65bbffce})
# host.get

[comment]: # ({/65bbffce-65bbffce})

[comment]: # ({54619a1f-93035b19})
### 説明

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

このメソッドは、与えられたパラメータにしたがってホストを取得することができます。

::: noteclassic
このメソッドは、すべてのタイプのユーザーが利用できます。メソッドを呼び出す権限は、ユーザーの役割の設定で取り消すことができます。詳細は[ユーザーの役割](/manual/web_interface/frontend_sections/users/user_roles)を参照してください。
:::

[comment]: # ({/54619a1f-93035b19})

[comment]: # ({20cd7ab0-77a8fabb})
### パラメータ

`(object)` 希望する出力を定義するパラメータ

このメソッドは以下のパラメータをサポートしています。

|パラメータ|[Type](/manual/api/reference_commentary#data_types)|説明|
|--|--|------|
|groupids|string/array|Return only hosts that belong to the given groups.|
|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.<br><br>Overrides the `with_monitored_items` and `with_simple_graph_items` parameters.|
|with\_item\_prototypes|flag|Return only hosts that have item prototypes.<br><br>Overrides the `with_simple_graph_item_prototypes` parameter.|
|with\_simple\_graph\_item\_prototypes|flag|Return only hosts that have item prototypes, which are enabled for creation and have numeric type of information.|
|with\_graphs|flag|Return only hosts that have graphs.|
|with\_graph\_prototypes|flag|Return only hosts that have graph prototypes.|
|with\_httptests|flag|Return only hosts that have web checks.<br><br>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.<br><br>Overrides the `with_simple_graph_items` parameter.|
|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.<br><br>Overrides the `with_monitored_triggers` parameter.|
|withProblemsSuppressed|boolean|Return hosts that have suppressed problems.<br><br>Possible values:<br>`null` - (default) all hosts;<br>`true` - only hosts with suppressed problems;<br>`false` - only hosts with unsuppressed problems.|
|evaltype|integer|Rules for tag searching.<br><br>Possible values:<br>0 - (default) And/Or;<br>2 - Or.|
|severities|integer/array|Return hosts that have only problems with given severities. Applies only if problem object is trigger.|
|tags|array/object|Return only hosts with given tags. Exact match by tag and case-sensitive or case-insensitive search by tag value depending on operator value.<br>Format: `[{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...]`.<br>An empty array returns all hosts.<br><br>Possible operator values:<br>0 - (default) Contains;<br>1 - Equals;<br>2 - Not like;<br>3 - Not equal<br>4 - Exists;<br>5 - Not exists.|
|inheritedTags|boolean|Return hosts that have given `tags` also in all of their linked templates. Default:<br><br>Possible values:<br>`true` - linked templates must also have given `tags`;<br>`false` - (default) linked template tags are ignored.|
|selectDiscoveries|query|Return a [discoveries](/manual/api/reference/discoveryrule/object) property with host low-level discovery rules.<br><br>Supports `count`.|
|selectDiscoveryRule|query|Return a [discoveryRule](/manual/api/reference/discoveryrule/object) property with the low-level discovery rule that created the host (from host prototype in VMware monitoring).|
|selectGraphs|query|Return a [graphs](/manual/api/reference/graph/object) property with host graphs.<br><br>Supports `count`.|
|selectHostDiscovery|query|Return a `hostDiscovery` property with host discovery object data.<br><br>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:<br>`host` - *(string)* host of the host prototype;<br>`hostid` - *(string)* ID of the discovered host or host prototype;<br>`parent_hostid` - *(string)* ID of the host prototype from which the host has been created;<br>`parent_itemid` - *(string)* ID of the LLD rule that created the discovered host;<br>`lastcheck` - *(timestamp)* time when the host was last discovered;<br>`ts_delete` - *(timestamp)* time when a host that is no longer discovered will be deleted.|
|selectHostGroups|query|ホストが所属するホストグループのデータと共に [hostgroups](/manual/api/reference/hostgroup/object) プロパティを返します。|
|selectHttpTests|query|Return an [httpTests](/manual/api/reference/httptest/object) property with host web scenarios.<br><br>Supports `count`.|
|selectInterfaces|query|Return an [interfaces](/manual/api/reference/hostinterface/object) property with host interfaces.<br><br>Supports `count`.|
|selectInventory|query|Return an [inventory](/manual/api/reference/host/object#host_inventory) property with host inventory data.|
|selectItems|query|Return an [items](/manual/api/reference/item/object) property with host items.<br><br>Supports `count`.|
|selectMacros|query|Return a [macros](/manual/api/reference/usermacro/object) property with host macros.|
|selectParentTemplates|query|Return a [parentTemplates](/manual/api/reference/template/object) property with templates that the host is linked to.<br><br>Supports `count`.|
|selectDashboards|query|Return a [dashboards](/manual/api/reference/templatedashboard/object) property.<br><br>Supports `count`.|
|selectTags|query|Return a [tags](/manual/api/reference/host/object#host_tag) property with host tags.|
|selectInheritedTags|query|Return an [inheritedTags](/manual/api/reference/host/object#host_tag) property with tags that are on all templates which are linked to host.|
|selectTriggers|query|Return a [triggers](/manual/api/reference/trigger/object) property with host triggers.<br><br>Supports `count`.|
|selectValueMaps|query|Return a [valuemaps](/manual/api/reference/valuemap/object) property with host value maps.|
|filter|object|Return only those results that exactly match the given filter.<br><br>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.<br><br>Allows filtering by interface properties.|
|limitSelects|integer|Limits the number of records returned by subselects.<br><br>Applies to the following subselects:<br>`selectParentTemplates` - results will be sorted by `host`;<br>`selectInterfaces`;<br>`selectItems` - sorted by `name`;<br>`selectDiscoveries` - sorted by `name`;<br>`selectTriggers` - sorted by `description`;<br>`selectGraphs` - sorted by `name`;<br>`selectDashboards` - sorted by `name`.|
|search|object|Return results that match the given wildcard search.<br><br>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.<br><br>Allows searching by interface properties. Works only with text fields.|
|searchInventory|object|Return only hosts that have inventory data matching the given wildcard search.<br><br>This parameter is affected by the same additional parameters as `search`.|
|sortfield|string/array|Sort the result by the given properties.<br><br>Possible values are: `hostid`, `host`, `name`, `status`.|
|countOutput|boolean|These parameters being common for all `get` methods are described in detail in the [reference commentary](/manual/api/reference_commentary#common_get_method_parameters).|
|editable|boolean|^|
|excludeSearch|boolean|^|
|limit|integer|^|
|output|query|^|
|preservekeys|boolean|^|
|searchByAny|boolean|^|
|searchWildcardsEnabled|boolean|^|
|sortorder|string/array|^|
|startSearch|boolean|^|
|selectGroups<br>(非推奨)|query|このパラメータは非推奨のため、 `selectHostGroups` を使ってください。ホストが所属するホストグループのデータと共に [groups](/manual/api/reference/hostgroup/object) プロパティを返します。|

[comment]: # ({/20cd7ab0-77a8fabb})

[comment]: # ({7223bab1-7223bab1})
### 戻り値

`(integer/array)` 次のいずれかを返します:

-   オブジェクトの配列
-   `countOutput`パラメーターが使用されている場合、取得したオブジェクトの数

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

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

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

[comment]: # ({bdf49605-c6ea3cce})
#### 名前によるデータの取得

"Zabbix server"と"Linux server"という名前の2つのホストに関するすべてのデータを取得します。

[リクエスト](/manual/api#performing-requests) :

```json
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "filter": {
            "host": [
                "Zabbix server",
                "Linux server"
            ]
        }
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10160",
            "proxyid": "0",
            "host": "Zabbix server",
            "status": "0",
            "ipmi_authtype": "-1",
            "ipmi_privilege": "2",
            "ipmi_username": "",
            "ipmi_password": "",
            "maintenanceid": "0",
            "maintenance_status": "0",
            "maintenance_type": "0",
            "maintenance_from": "0",
            "name": "Zabbix server",
            "flags": "0",
            "description": "The Zabbix monitoring server.",
            "tls_connect": "1",
            "tls_accept": "1",
            "tls_issuer": "",
            "tls_subject": "",
            "proxy_groupid": "0",
            "monitored_by": "0",
            "inventory_mode": "1",
            "active_available": "1",
            "assigned_proxyid": "0"
        },
        {
            "hostid": "10167",
            "proxyid": "0",
            "host": "Linux server",
            "status": "0",
            "ipmi_authtype": "-1",
            "ipmi_privilege": "2",
            "ipmi_username": "",
            "ipmi_password": "",
            "maintenanceid": "0",
            "maintenance_status": "0",
            "maintenance_type": "0",
            "maintenance_from": "0",
            "name": "Linux server",
            "flags": "0",
            "description": "",
            "tls_connect": "1",
            "tls_accept": "1",
            "tls_issuer": "",
            "tls_subject": "",
            "proxy_groupid": "0",
            "monitored_by": "0",
            "inventory_mode": "1",
            "active_available": "1",
            "assigned_proxyid": "0"
        }
    ],
    "id": 1
}
```

[comment]: # ({/bdf49605-c6ea3cce})

[comment]: # ({8d87c206-9078aff7})
#### ホストグループの取得

ホスト"Zabbix server"が所属するホストグループ取得します。

[リクエスト](/manual/api#performing-requests) :

```json
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectHostGroups": "extend",
        "filter": {
            "host": [
                "Zabbix server"
            ]
        }
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10085",
            "hostgroups": [
                {
                    "groupid": "2",
                    "name": "Linux servers",
                    "flags": "0",
                    "uuid": "dc579cd7a1a34222933f24f52a68bcd8"
                },
                {
                    "groupid": "4",
                    "name": "Zabbix servers",
                    "flags": "0",
                    "uuid": "6f6799aa69e844b4b3918f779f2abf08"
                }
            ]
        }
    ],
    "id": 1
}
```

[comment]: # ({/8d87c206-9078aff7})

[comment]: # ({3f6d4bdf-59c8a46a})
#### リンク先テンプレートの取得

ホスト"10084"にリンクしているテンプレートのIDおよび名前を取得します。

[リクエスト](/manual/api#performing-requests) :

```json
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectParentTemplates": [
            "templateid",
            "name"
        ],
        "hostids": "10084"
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10084",
            "parentTemplates": [
                {
                    "name": "Linux",
                    "templateid": "10001"
                },
                {
                    "name": "Zabbix Server",
                    "templateid": "10047"
                }
            ]
        }
    ],
    "id": 1
}
```

[comment]: # ({/3f6d4bdf-59c8a46a})

[comment]: # ({9a8b8f9f-942e31bf})
#### テンプレートでホストの取得

テンプレート"10001"(*Linux by Zabbix agent*) がリンクされているホストを取得します。

[リクエスト](/manual/api#performing-requests) :

```json
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid", "name"],
        "templateids": "10001"
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "templateid": "10001",
            "hosts": [
                {
                    "hostid": "10084",
                    "name": "Zabbix server"
                },
                {
                    "hostid": "10603",
                    "name": "Host 1"
                },
                {
                    "hostid": "10604",
                    "name": "Host 2"
                }
            ]
        }
    ],
    "id": 1
}
```

[comment]: # ({/9a8b8f9f-942e31bf})

[comment]: # ({63a1e5ba-8be1d99c})
#### ホストインベントリのデータで検索

ホストインベントリの"OS"フィールドに"Linux"が含まれるホストを検索します

[リクエスト](/manual/api#performing-requests) :

```json
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": [
            "host"
        ],
        "selectInventory": [
            "os"
        ],
        "searchInventory": {
            "os": "Linux"
        }
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10084",
            "host": "Zabbix server",
            "inventory": {
                "os": "Linux Ubuntu"
            }
        },
        {
            "hostid": "10107",
            "host": "Linux server",
            "inventory": {
                "os": "Linux Mint"
            }
        }
    ],
    "id": 1
}
```

[comment]: # ({/63a1e5ba-8be1d99c})

[comment]: # ({b6238857-b4e37e5e})
#### ホストタグで検索

タグ"host-name"が"linux-server"と等しいホストを取得します。

[リクエスト](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["hostid"],
        "selectTags": "extend",
        "evaltype": 0,
        "tags": [
            {
                "tag": "host-name",
                "value": "linux-server",
                "operator": 1
            }
        ]
    },
    "id": 1
}
```

レスポンス:

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10085",
            "tags": [
                {
                    "tag": "host-name",
                    "value": "linux-server",
                    "automatic": "0"
                },
                {
                    "tag": "os",
                    "value": "rhel-7",
                    "automatic": "0"
                }
            ]
        }
    ],
    "id": 1
}
```

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

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "tags": [
            {
                "tag": "os",
                "value": "rhel-7",
                "operator": 1
            }
        ],
        "inheritedTags": true
    },
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10623",
            "name": "PC room 1"
        },
        {
            "hostid": "10601",
            "name": "Office"
        }
    ],
    "id": 1
}
```

[comment]: # ({/b6238857-b4e37e5e})

[comment]: # ({c6c128e0-9ebae84e})
#### タグとテンプレートタグでホストの検索

タグと親テンプレートにリンクされているすべてのタグでホストを取得します。

[リクエスト](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "hostids": 10502,
        "selectTags": ["tag", "value"],
        "selectInheritedTags": ["tag", "value"]
    },
    "id": 1
}
```

レスポンス:

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10502",
            "name": "Desktop",
            "tags": [
                {
                    "tag": "host-name",
                    "value": "linux-server"
                },
                {
                    "tag": "os",
                    "value": "rhel-7"
                }
            ],
            "inheritedTags": [
                {
                    "tag": "class",
                    "value": "os"
                },
                {
                    "tag": "target",
                    "value": "linux"
                },
                {
                    "tag": "os",
                    "value": "rhel-7"
                }
            ]
        }
    ],
    "id": 1
}
```

[comment]: # ({/c6c128e0-9ebae84e})

[comment]: # ({ee33fbef-219d4ee1})
#### 障害の深刻度でホストの検索

"Disaster"の障害を持つホストを取得します。

[リクエスト](/manual/api#performing-requests) :

```json
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "severities": 5
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "10160",
            "name": "Zabbix server"
        }
    ],
    "id": 1
}
```

"Average"と"High"の障害を持つホストを取得します。

[リクエスト](/manual/api#performing-requests) :

```json
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": ["name"],
        "severities": [3, 4]
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": [
        {
            "hostid": "20170",
            "name": "Database"
        },
        {
            "hostid": "20183",
            "name": "workstation"
        }
    ],
    "id": 1
}
```

[comment]: # ({/ee33fbef-219d4ee1})

[comment]: # ({1b616a06-06c7fe93})
### 参照

-   [Host group](/manual/api/reference/hostgroup/object#host_group)
-   [Template](/manual/api/reference/template/object#template)
-   [User macro](/manual/api/reference/usermacro/object#hosttemplate_level_macro)
-   [Host interface](/manual/api/reference/hostinterface/object#host_interface)
-   [Proxy](/manual/api/reference/proxy/object#proxy)
-   [Proxy group](/manual/api/reference/proxygroup/object#proxy_group)

[comment]: # ({/1b616a06-06c7fe93})

[comment]: # ({55c08f7a-55c08f7a})
### ソース

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

[comment]: # ({/55c08f7a-55c08f7a})
