# CLI commands

> Every monitorly command - login, signup, discover, plan, apply, export, test, verify-deploy, status and node list, install and revoke - with flags, permissions and output.

Every command takes `--json` and `--api-url` (or `MONITORLY_API_URL`). See [CLI](https://docs.monitorly.cloud/cli.md) for installation, sign-in and exit codes.

## `monitorly login`

```text
monitorly login [--api-url URL] [--browser | --with-token]
```

Signs in and stores the sign-in in `~/.config/monitorly/credentials` (or under `$XDG_CONFIG_HOME`). On a terminal, or with `--browser`, it signs in through the browser and waits up to 5 minutes; an agent without a terminal can pass the printed address to a person. Otherwise, or with `--with-token`, it reads an API token from stdin:

```sh title="Sign in with a token"
printf '%s\n' "$TOKEN" | monitorly login --api-url https://app.monitorly.cloud --with-token
```

A new browser sign-in revokes the previous one stored in the file. A credentials file readable by others is refused until you `chmod 600` it.

## `monitorly signup`

```text
monitorly signup [--api-url URL]
```

Opens the sign-up page and waits up to 30 minutes while you create the account, confirm the email and sign in; then it continues as `login`.

## `monitorly discover`

```text
monitorly discover [PATH] [--dns] [--out FILE [--force]] [--project NAME] [--json]
```

Reads a repository locally and prints a draft `monitorly.yaml`. Nothing is sent anywhere and nothing is applied. See [`monitorly discover`](https://docs.monitorly.cloud/cli/discover.md).

## `monitorly plan`

```text
monitorly plan [-f FILE] [--prune] [--json]
```

Compares the file (default `monitorly.yaml`, `-` for stdin) with the project and prints what would change: `+ create`, `~ update` with each field's old and new value, `- DELETE`, and warnings:

- `config.drift`: changed in the dashboard since the last apply; applying overwrites it;
- `config.adopts_unmanaged`: a resource made in the dashboard becomes managed by the file;
- `config.unmanaged_same_name`: a new resource has the name of one made in the dashboard.

The file is validated against the server's schema first, with errors pointing into the file (`/checks/0/kind/port is required`). The server keeps the plan for 15 minutes; `plan` itself changes nothing. Exit code 3 when there are changes, 0 when there are none.

`--prune` deletes, in the sections the file has, resources managed by the file that it no longer lists. Resources made in the dashboard are never deleted by a plan.

Needs a project editor, and a token with `…:write` for each section in the file.

## `monitorly apply`

```text
monitorly apply [-f FILE] [--prune] [--yes] [--json]
```

Builds the plan as `plan` does, shows it, and applies exactly that plan. Deletions are shown in capitals and repeated before the prompt. Without `--yes` it asks `[y/N]` on a terminal; without a terminal, or with `--json`, it stops with exit code 3 and applies nothing.

The output lists created resources, and the ping URL of each new heartbeat check: it is shown only here. If the project changed between plan and apply (`config.plan_stale`) or the plan expired, run `apply` again.

## `monitorly export`

```text
monitorly export [PROJECT] [--json] > monitorly.yaml
```

Writes the project's checks, status pages and maintenance windows as a `monitorly.yaml`. Secret header values are written as `secret: keep`, never as values. Resources made in the dashboard get a `ref` derived from their name; the next `plan` adopts them.

## `monitorly test`

```text
monitorly test [-f FILE] [--ref REF]… [--json]
```

Runs checks from the file once on their nodes, without saving anything, and prints each node's result: outcome, status code, time, error and failed assertions. Without `--ref`, every check in the file except heartbeat checks. A header with `secret: keep` uses the stored secret of the saved check with the same `ref`. Exit code 1 if any check does not pass.

## `monitorly verify-deploy`

```text
monitorly verify-deploy [--ref REF]… [--project P] [--json]
```

After a deploy, runs saved checks now on all their nodes and decides each by its quorum in that one round ([How DOWN is decided](https://docs.monitorly.cloud/concepts/quorum.md#verdicts-outside-the-schedule)). Without `--ref`, every check of the projects the token sees, except paused and heartbeat checks. UP and DEGRADED pass; DOWN and UNKNOWN fail the command with exit code 1.

```yaml title="GitHub Actions steps"
- name: Install the monitorly CLI
  run: curl -fsSL https://gw.monitorly.cloud/install-cli.sh | sh
- name: Verify the deploy
  env:
    MONITORLY_TOKEN: ${{ secrets.MONITORLY_TOKEN }}
    MONITORLY_API_URL: https://app.monitorly.cloud
  run: monitorly verify-deploy --ref storefront --ref checkout-api
```

## `monitorly status`

```text
monitorly status [PROJECT] [--json]
```

Checks that are DOWN, DEGRADED or UNKNOWN, since when, and open incidents. The exit code is 0 even when something is down: use `verify-deploy` for a pass or fail.

## `monitorly node list`

```text
monitorly node list [--workspace W] [--json]
```

Nodes that can run the workspace's checks, platform nodes first: name, `platform` or `private`, country, city, state and id. Names and ids from here go into `nodes:` in `monitorly.yaml`. Needs `nodes:read`.

## `monitorly node install`

```text
monitorly node install --ssh DEST --name N [--country CC] [--workspace W] [--docker[=SOCKET|URL]] [--systemd[=failed|UNIT,UNIT]] [--wait-secs S] [--yes] [--dry-run] [--json]
```

Installs a [private node](https://docs.monitorly.cloud/nodes/install.md) on a Linux server over your own `ssh`, with your `~/.ssh/config`, agent and known hosts. It shows the plan first, issues a join token, runs the installer on the server with root or passwordless `sudo`, and waits up to `--wait-secs` (default 120) for the node to come online. `--dry-run` shows the plan and does nothing.

The token travels in the script on ssh's stdin, never on a command line. Needs a workspace owner or admin and `nodes:write`.

`--docker` and `--systemd` go to the installer as they are, so the node also reports the server's containers and systemd services. `--docker` alone reads the Docker socket (access to it equals root on that server); `--docker=http://127.0.0.1:2375` reads a read-only socket proxy instead. `--systemd` alone reports every failed service; `--systemd=failed,nginx.service` also the state of the services named. Install again without them and the node stops watching containers and services.

With a join token from the dashboard instead: `monitorly node install --ssh DEST --join-token TOKEN --gateway-url URL --api-url URL`; pass the token as `MONITORLY_JOIN_TOKEN` to keep it out of the process list.

## `monitorly node revoke`

```text
monitorly node revoke NODE [--workspace W] [--yes] [--json]
```

Revokes a private node by name or id. Checks stop running on it at once; this cannot be undone. Needs a workspace owner or admin and `nodes:write`.
