[comment]: # translation:outdated

[comment]: # ({c572a02a-c572a02a})
# host.update

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

[comment]: # ({4162909c-12e31652})
### 説明

`object host.update(object/array hosts)`

このメソッドでは、既存のホストを更新することができます。

::: noteclassic
このメソッドは、*Admin* および *Super admin* ユーザータイプにのみ使用できます。このメソッドを呼び出す許可は、<br>
ユーザーロール設定で取り消すことができます。詳細については、[User roles](/manual/web_interface/frontend_sections/administration/user_roles) を参照してください。
:::

[comment]: # ({/4162909c-12e31652})

[comment]: # ({6727520a-3a8eac6a})
### パラメータ

`(object/array)` 更新されるホストプロパティ

`hostid` プロパティは各ホストに対して定義する必要があり、他のプロパティはすべてオプションです。<br>
与えられたプロパティのみが更新され、その他のプロパティは変更されません。

しかし、ホストの technical name(実ホスト名) を更新すると、ホストの visible name (表示名 指定されていないか空の場合) も<br>
ホストの technical name の値で更新されることに注意してください。

[standard host properties](object#host)に加えて、このメソッドは以下のパラメータを受け付けます。

|パラメータ|[Type](/manual/api/reference_commentary#data_types)|説明|
|--|--|------|
|groups|object/array|Host [groups](/manual/api/reference/hostgroup/object#host_group) to replace the current host groups the host belongs to.<br><br>The host groups must have the `groupid` property defined. All host groups that are not listed in the request will be unlinked.|
|interfaces|object/array|Host [interfaces](/manual/api/reference/hostinterface/object) to replace the current host interfaces.<br><br>All interfaces that are not listed in the request will be removed.|
|tags|object/array|Host [tags](/manual/api/reference/host/object#host_tag) to replace the current host tags.<br><br>All tags that are not listed in the request will be removed.|
|inventory|object|Host [inventory](/manual/api/reference/host/object#host_inventory) properties.|
|macros|object/array|[User macros](/manual/api/reference/usermacro/object) to replace the current user macros.<br><br>All macros that are not listed in the request will be removed.|
|templates|object/array|[Templates](/manual/api/reference/template/object) to replace the currently linked templates. All templates that are not listed in the request will be only unlinked.<br><br>The templates must have the `templateid` property defined.|
|templates\_clear|object/array|[Templates](/manual/api/reference/template/object) to unlink and clear from the host.<br><br>The templates must have the `templateid` property defined.|

::: notetip
Zabbix フロントエンドとは異なり、`name`(表示名)と`host`(ホスト名)が同じ場合、API 経由で `host` を更新しても、<br>
自動的に `name` は更新されません。両方のプロパティを明示的に更新する必要があります。
:::

[comment]: # ({/6727520a-3a8eac6a})

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

`(object)` `hostids` プロパティの下で更新されたホストの ID を含むオブジェクトを返します。

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

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

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

[comment]: # ({bcd7b728-ce50c453})
#### ホストの有効化

ホストの監視を有効にする、つまりステータスを0にします。

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10126",
        "status": 0
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10126"
        ]
    },
    "id": 1
}
```

[comment]: # ({/bcd7b728-ce50c453})

[comment]: # ({56f46465-bea1db7e})
#### テンプレートのリンク削除

ホストから2つのテンプレートのリンクを削除してクリアします。

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10126",
        "templates_clear": [
            {
                "templateid": "10124"
            },
            {
                "templateid": "10125"
            }
        ]
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10126"
        ]
    },
    "id": 1
}
```

[comment]: # ({/56f46465-bea1db7e})

[comment]: # ({b789e636-98dcfd68})
#### ホストマクロの更新

すべてのホストマクロを新しい2つのマクロに置き換えます。

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10126",
        "macros": [
            {
                "macro": "{$PASS}",
                "value": "password"
            },
            {
                "macro": "{$DISC}",
                "value": "sda",
                "description": "Updated description"
            }
        ]
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10126"
        ]
    },
    "id": 1
}
```

[comment]: # ({/b789e636-98dcfd68})

[comment]: # ({72eb8ecc-da99f3b8})
#### ホストインベントリの更新

インベントリモードの変更とロケーションの追加をします。

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10387",
        "inventory_mode": 0,
        "inventory": {
            "location": "Latvia, Riga"
        }
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10387"
        ]
    },
    "id": 1
}
```

[comment]: # ({/72eb8ecc-da99f3b8})

[comment]: # ({4a11868e-5cc5d950})
#### ホストタグの更新

すべてのホストタグを新しいものに置き換えます。

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10387",
        "tags": {
            "tag": "OS",
            "value": "RHEL 7"
        }
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10387"
        ]
    },
    "id": 1
}
```

[comment]: # ({/4a11868e-5cc5d950})

[comment]: # ({58eba4cd-ae2d89bf})
#### 検出されたホストマクロの更新

作成した検出ルールの"自動"マクロを"手動"に変換し、その値を"new-value"に変更します。

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10387",
        "macros": {
            "hostmacroid": "5541",
            "value": "new-value",
            "automatic": "0"
        }
    },
    "id": 1
}
```

レスポンス :

```json
{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10387"
        ]
    },
    "id": 1
}
```

[comment]: # ({/58eba4cd-ae2d89bf})

[comment]: # ({new-b4a9cd46})
#### Updating host encryption

Update the [host "10590"](create#creating-a-host-with-psk-encryption-configured) to use PSK encryption only for connections from host to Zabbix server.
In addition, update the PSK identity and PSK key for this host.
Note that the Zabbix agent that is installed on the host has to be configured to [use PSK](/manual/encryption/using_pre_shared_keys#using-pre-shared-keys).

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

```json
{
    "jsonrpc": "2.0",
    "method": "host.update",
    "params": {
        "hostid": "10590",
        "tls_connect": 1,
        "tls_accept": 2,
        "tls_psk_identity": "PSK 002",
        "tls_psk": "e560cb0d918d26d31b4f642181f5f570ad89a390931102e5391d08327ba434e9"
    },
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "hostids": [
            "10590"
        ]
    },
    "id": 1
}
```

[comment]: # ({/new-b4a9cd46})

[comment]: # ({345be18f-23501347})
### 参照

-   [host.massadd](massadd)
-   [host.massupdate](massupdate)
-   [host.massremove](massremove)
-   [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)
-   [Host inventory](object#host_inventory)
-   [Host tag](object#host_tag)

[comment]: # ({/345be18f-23501347})

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

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

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