# Health and actions

> Ask a connected device what it runs, and restart its security sensor, without anyone at the keyboard.

When a device looks quiet, you can ask it directly: which version of the device client it runs, on which operating
system, and whether its security sensor and AI tools agent are running. If the sensor is stuck, you can restart it
from the realm, without anyone at the keyboard.

## Before you begin

- **Privilege:** running an action needs `MODIFY` on the realm's endpoint settings, which `RealmOwner` holds
  ([Who can call](../../api/#who-can-call)).
- **Where:** the API.
- **The device must be connected.** Check `connected` on its [record](../device-records/).

## How it works

An action goes down the device's own session, and the device answers it.

| `kind` | What the device does | What it answers |
|---|---|---|
| `report` | Reports its state | `version`, `os`, and for each part installed, whether it's `running` |
| `status` | Reports the security sensor's state | The sensor, with `running` |
| `restart-dar` | Restarts the security sensor | The sensor, with its state after the restart |

In these answers, and in the `restart-dar` action's name, the API calls the security sensor `dar` and the AI tools
agent `aig`.

The answer is `{ "id", "ok", "detail" }`: `ok` says whether the action held, and `detail` carries what it found, or
why it failed.

## Set it up

Run an action with the device id, the `id` on its [Device records](../device-records/) entry
([Call the API](../../../develop/api/)):

```sh
curl https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/<device id>/do \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{"kind": "report"}'
```

```json
{
  "id": "<action id>",
  "ok": true,
  "detail": { "version": "<version>", "os": "linux", "dar": { "running": true }, "aig": { "running": true } }
}
```

## What the user sees

Nothing. An action runs in the background on the device; no prompt or notice appears. Restarting the sensor pauses
its watching for the moment it takes to start again.

## If it fails

| Answer | When | What to do |
|---|---|---|
| `ok: false`, `no such action: <kind>` | The device doesn't know that `kind` | Use `report`, `status` or `restart-dar` |
| `ok: false` on `status` or `restart-dar` | The device has no security sensor | Reinstall the package on the device |
| `503` | The device isn't connected | Check `connected`, and see the device client's [Troubleshooting](../../enrollment/device-client/#troubleshooting) |
| `504` | The device didn't answer within 30 seconds | Ask again; if it keeps timing out, check the device |
| `404` | No device with that id in this realm | List the realm's devices for its id |
| `403` | You lack `MODIFY` on the realm's endpoint settings | Ask a realm administrator to [grant it](../../api/#who-can-call) |

## Limits and defaults

| What | Value |
|---|---|
| Wait for the device's answer | 30 seconds |
| Devices per action | One; to restart many sensors at once, see [Sensor actions](../../../detection-response/sensors/sensor-actions/) |
| Actions | `report`, `status`, `restart-dar` |
| History | None kept |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| `report` says the sensor isn't `running` | It stopped and hasn't been started yet | Wait a minute, since the client restarts it on its own, or run `restart-dar` |
| `restart-dar` answers, but the sensor stops again | Something on the device stops it | Check the device's own logs ([Device client](../../enrollment/device-client/#set-it-up)) |
| `503` for a device that shows `connected` | It disconnected in between | Ask again once it's connected |

## Audit record

Actions aren't kept: the answer is the only record, and nothing is written to the realm's audit trail. Keep the
answer if you need it later.

## Good to know

- **Only known actions.** A `kind` the device doesn't know is answered `ok: false`, `no such action: <kind>`.
- **No sensor, no sensor actions.** `status` and `restart-dar` on a device without the sensor answer `ok: false`.
- **No lock, wipe or restart of the device itself.** Actions reach the device client's parts only; see
  [Known limitations](../../../reference/known-limitations/).

## Related

- [Device client](../../enrollment/device-client/): what keeps the parts running between your checks.
- [Sensor actions](../../../detection-response/sensors/sensor-actions/): restart or remove many sensors at once.
