# Sensor actions

> Restart or remove the security sensors on your realm's devices, up to a hundred at once; upgrading from the realm isn't working yet.

The security sensor on each device sometimes needs a restart after a configuration change, or removing from a
machine you're retiring. You do it from the realm, for one device or up to a hundred at once. Upgrading a sensor from
the realm is accepted but doesn't reach the device yet: upgrade it with the device package instead (see below).

## Before you begin

- **Who:** an administrator of the realm, in a group holding `RealmOwner` on the realm or a realm above it (see
  [Delegated administration](../../../platform/realms/delegated-administration/)). Detection & Response doesn't yet
  tell `RealmViewer` apart from `RealmOwner`: a viewer can restart and remove sensors too.
- **Where:** the API.
- **First:** the sensor ids of the devices; the sensors list gives them.

## How it works

| Action | Endpoint | What happens |
|---|---|---|
| Restart | `POST https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/agents/restart` | Each connected sensor restarts and comes back with the realm's configuration |
| Remove | `POST https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/agents/remove` | Each sensor's registration is removed; its device must enroll again to report |
| Upgrade (not working yet) | `POST https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/agents/upgrade` | Accepted and queued, but the device refuses it, so `upgrade/progress` ends `failed` |

Each takes `{"agents": [...]}`, the sensor ids, and answers each one done or failed, with why.

## Set it up

The sensors list gives each sensor's status, operating system and version; one device's
[device view](../../security-log/device-view/) gathers everything about it. Through the API
([Call the API](../../../develop/api/)), restart two sensors:

```sh
curl https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/agents/restart \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{"agents": ["<sensor id>", "<sensor id>"]}'
```

```json
{ "done": ["<sensor id>"], "failed": [{ "agent": "<sensor id>", "reason": "<why>" }] }
```

### Upgrading a sensor

The sensor ships inside the device package, and its version moves with the package. To upgrade it, install the new
device package on the device, as when you enrolled it (see
[Device enrollment](../../../endpoint-management/enrollment/device-enrollment/)). The `upgrade` call is accepted today, but the device refuses the upgrade, and
`POST https://foobar.cvyuh.com/api/v0/endpoint/dar/v1/agents/upgrade/progress` reports it as `failed`. Each sensor's
version is in the sensors list.

## What happens when it fails

| In `failed` | Why | What to do |
|---|---|---|
| `not an agent of this realm` | The id isn't one of your realm's sensors | Check the id in the sensors list; nothing was done to it |
| A reason saying the sensor isn't active | The device isn't connected | Try again when its status is `active` |
| A `400` for the whole call | No ids, more than 100, or an id that isn't a sensor id | Send 1 to 100 sensor ids |

## Limits and defaults

| Limit | Value |
|---|---|
| Sensors per action | 1 to 100 |
| Sensor id | 3 to 9 digits |

## Good to know

- **Only your realm's devices.** An id that isn't your realm's is answered in `failed`, and nothing is done to it.
- **Removing a sensor isn't removing the device.** The device stays enrolled but stops reporting here. To take the
  whole device out of the realm, use [Device removal](../../../endpoint-management/revoke-and-remove/removal/), which
  removes its sensor too.

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| A sensor shows `disconnected` | The device is off, offline, or revoked | Check the device in [Health and actions](../../../endpoint-management/devices/health-and-actions/); a revoked device stays disconnected |
| A sensor shows `never` | Its device enrolled but has never connected | Check the device client is running on it |
| An upgrade stays `failed` | Upgrading from the realm isn't working yet | Install the new device package on the device |

## Audit record

None yet. Restarts and removals aren't recorded in the realm's audit trail.

## Related

- [Active response](../../response/active-response/): act on what the sensor found.
- [Device view](../../security-log/device-view/): one sensor, and everything it reported.
- [Health and actions](../../../endpoint-management/devices/health-and-actions/): ask one device what it runs.
