---
title: "Move all hosts monitored by a cluster to another cluster"
description: "Moving all hosts monitored by one collector cluster to another is necessary when removing a collector cluster. This can be done using Opsview's REST API or by carefully updating the database, followed by applying changes."
url: "https://docs.itrsgroup.com/docs/faq/opsview/4921342013085-opsview-move-all-hosts-monitored-by-a-cluster-to-another-cluster/index.html"
---
This article explains how to move all the hosts monitored by a [collector cluster](https://docs.itrsgroup.com/docs/faq/opsview/4920301079581-opsview-collector-cluster/index.html) to another collector cluster.

You may want to do this when removing a collector cluster.

## API query

**Learn to use Opsview's API**

For more information about using Opsview's REST API, refer to the [Opsview API documentation](https://docs.itrsgroup.com/docs/opsview/current/rest-api/rest-api-background/api-introduction/index.html).

### Prerequisites

- Another suitable collector cluster exists
- `jq` is installed

### Process

1. Log in to the [orchestrator](https://docs.itrsgroup.com/docs/faq/opsview/4920429084957-opsview-orchestrator/index.html) as `root`.
2. Use `opsview_rest` to move all the hosts monitored by the original cluster to another cluster:

```
/opt/opsview/coreutils/bin/opsview_rest --username=<admin> --password=<password> --pretty --data-format=json get 'config/monitoringcluster?s.name=<original_cluster>' | jq '.list[].monitors[].ref' | xargs -I REF opsview_rest  --username=<admin> --password=<password> put REF --content-file=<( echo "{ monitored_by => {name => '<new_cluster>'} }")
```

Replace the variables in angle brackets (`<>`) according to the following table:

| Variable | Value |
| --- | --- |
| `<admin>` | Username of an administrator user |
| `<password>` | Administrator user’s password |
| `<original_cluster>` | Name of the original collector cluster |
| `<new_cluster>` | Name of the new collector cluster |

This query works by getting the host configuration endpoints of all the hosts monitored by `<original_cluster>` and then updating them to be monitored by `<new_cluster>`.

3. [Apply Changes](https://docs.itrsgroup.com/docs/faq/opsview/4920514560797-opsview-apply-changes/index.html).

## Database

**Proceed with caution**

We do not recommend making any direct changes to the Opsview databases. Wherever possible, you should use the API instead.

Changes to the Opsview databases can irreparably damage your Opsview installation.

Always take appropriate backup precautions before making any direct changes to the Opsview databases.

### Prerequisites

- Another suitable collector cluster exists

### Process

1. [Access the opsview database using the MySQL console.](https://docs.itrsgroup.com/docs/faq/opsview/4921146151453-opsview-access-the-opsview-databases/index.html)
2. Identify the `id` of the cluster currently monitoring the hosts:

```
SELECT * FROM monitoringclusters where name = '<original_cluster_name>\G
```

Replace `<original_cluster_name>` with the name of the cluster currently monitoring the hosts.

3. Identify the `id` of the cluster you want to move the hosts to:

```
SELECT * FROM monitoringclusters where name = '<new_cluster_name>\G
```

Replace `<new_cluster_name>` with the name of the cluster you want to monitor the hosts.

4. Update the `monitored_by` field of the hosts so they are monitored by the new cluster:

```
UPDATE hosts SET monitored_by = <new_cluster_id> where monitored_by = <original_cluster_id>;
```

Replace `<new_cluster_id>` with the `id` of the new cluster. Replace `<original_cluster_id>` with the `id` of the original cluster.

5. [Apply Changes](https://docs.itrsgroup.com/docs/faq/opsview/4920514560797-opsview-apply-changes/index.html).
   You must Apply Changes even if you do not see a prompt to do so in the UI.


