> For the complete documentation index, see [llms.txt](https://wiki.datadike.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.datadike.com/sonar/deploy-operate/troubleshooting.md).

# Troubleshoot agents

Diagnose agents that show Offline, Overdue or Remote Offline, stuck pending actions and installer errors, with log locations and service commands per OS.

## What this is and when to use it

Use this page when a device does not report, reports late, cannot be reached for remote control, or an installation fails. It starts from what the console shows, then moves to the device: its services, its log and its network path to SONAR.

## Before you start

* Your role lets you see the device in **Dashboard › Sysadmin**. The **Debug** tab needs **View Debug Logs**; **Agents › Pending Actions** needs **List Pending Actions**, and cancelling one needs **Manage Pending Actions**; **Restart Remote Service** needs **Use Mesh**.
* For checks on the device itself, you need administrator rights on Windows or `root` on Linux and macOS.

## How the console decides a device's status

The agent sends a heartbeat to SONAR every 30 to 60 seconds over its connection to the API address. **Last Response**, in the device list, is the time SONAR received the last one. The time is taken by SONAR on arrival, so the device's own clock has no effect on the status.

**Agent Status** compares **Last Response** with two thresholds set per device in **Edit** (device action menu):

| Status      | Meaning                                                                                            |
| ----------- | -------------------------------------------------------------------------------------------------- |
| **Online**  | Last contact more recent than **Offline after (minutes)**                                          |
| **Offline** | No contact for longer than **Offline after (minutes)**                                             |
| **Overdue** | No contact for longer than **Overdue after (minutes)**. Overdue alerts are raised from this status |

The thresholds can be long, so **Last Response** is the quicker signal: a **Last Response** more than a few minutes old means the agent is not connected right now, whatever the status says.

The **Filters** panel of the device list groups devices by fixed windows under **Availability**: **Online**, **Offline 12+ hours**, **Offline 24+ hours**, **Offline 7+ days**, **Overdue** and **Maintenance Mode**.

The details panel adds the state of the remote access agent: **Remote Online**, **Remote Offline** or **Remote Unknown**.

## Steps

### A device shows Offline or Overdue

1. **Is the device on and connected?** Check it is powered on and on a network. A device that is shut down or asleep shows **Offline** and then **Overdue** by design.
2. **Is the agent service running?** On the device:

   | Platform | Check                                                                   | Start or restart                                                       |
   | -------- | ----------------------------------------------------------------------- | ---------------------------------------------------------------------- |
   | Windows  | `sc query sonarrmm`, or **Sonar Agent Service** in the Services console | `net start sonarrmm`, or `net stop sonarrmm` then `net start sonarrmm` |
   | Linux    | `systemctl status sonaragent`                                           | `sudo systemctl restart sonaragent`                                    |
   | macOS    | `sudo launchctl print system/sonaragent`                                | `sudo launchctl kickstart -k system/sonaragent`                        |

   If the service does not exist, the agent was uninstalled: install it again.
3. **Can the device reach SONAR?** From the device, test 443/tcp to the API address — `Test-NetConnection api.example.com -Port 443` on Windows, `curl` on Linux and macOS. A proxy or TLS inspection in the path can let HTTPS through while breaking the long-lived WebSocket connection. See [Network requirements](https://wiki.datadike.com/sonar/deploy-operate/network-requirements.md).
4. **What does the agent log say?** Read the last lines of the log (see [Agent logs](#agent-logs)). Connection errors to the API address point to the network; errors right after start point to the local configuration.
5. After a fix, restart the agent service. **Last Response** updates within a minute and **Agent Status** returns to **Online**.

### A device shows Remote Offline

**Remote Offline** means the SONAR agent is connected but the remote access agent is not. **Take Control** is disabled until the remote access agent reconnects.

1. Select the device. While the agent is **Online** and the remote access agent is offline, the details panel header offers **Restart Remote Service**.
2. Click it. SONAR asks the agent to restart the remote access agent on the device (*Attempting to repair Mesh Agent*), and reports *Repaired mesh agent on \<hostname>* when done.
3. If the pill does not turn to **Remote Online** within a few minutes, restart the remote access agent on the device:

   | Platform | Command                                               |
   | -------- | ----------------------------------------------------- |
   | Windows  | `net stop "Mesh Agent"` then `net start "Mesh Agent"` |
   | Linux    | `sudo systemctl restart meshagent`                    |
   | macOS    | `sudo launchctl kickstart -k system/meshagent`        |
4. If it still stays offline, check that the device reaches the remote access address on 443/tcp with WebSocket upgrades allowed.
5. If the remote access agent is missing from the device, reinstall the SONAR agent (see [Reinstall over an existing agent](#reinstall-over-an-existing-agent)).

On macOS, *Operation not permitted* in **Terminal** or **File Browser** inside a user's Desktop, Documents or Downloads is a permissions matter, not a connection one. See [Install the agent on macOS](https://wiki.datadike.com/sonar/deploy-operate/install-agent-macos.md#folders-macos-protects).

### Pending actions do not complete

**Agents › Pending Actions** (**All Pending Actions**) lists work SONAR holds for devices: agent updates (*Agent update to \<version>*), scheduled reboots (*Device pending reboot*), software installs (*\<name> software install*), and other queued jobs. For one device, use **Pending Agent Actions** in its action menu, or look at the **Pending Actions** column of the device list.

1. Open the list and find the device.
2. Check the **Due** column. An agent update is due at the next update cycle, at 35 minutes past the hour; a scheduled reboot at the time it was set for.
3. A pending action stays pending while the device is offline. Bring the device back online first (see above).
4. For a completed software install, **View output** shows what the installer printed (**Pending Action Output Details**).
5. To drop an action, right-click its row, choose **Cancel Action** and confirm **Delete this pending action?**. Cancelling a scheduled reboot also removes it from the device.
6. **Show N Completed** and **Hide N Completed** switch the completed actions in and out of the list.

See [Update agents](https://wiki.datadike.com/sonar/deploy-operate/agent-updates.md) for how agent updates are closed.

### Read the Debug tab

The **Debug** tab of the details panel shows what SONAR recorded about the device, newest first, up to the last 1000 entries.

1. Select the device and open **Debug**.
2. Choose a **Log Level**: **Info** (the default), **Warning**, **Error** or **Critical**.
3. Optionally choose a **Log Type**: **Agent Update**, **Agent Issues**, **Windows Updates**, **System Issues** or **Scripting**.
4. Use **Search** to filter the rows, or **CSV** to export them.

Entries of type **Agent Update** and **Agent Issues** are where update and connection problems of the device are recorded on the SONAR side.

### Agent logs

| Platform | Log file                                                                                                           |
| -------- | ------------------------------------------------------------------------------------------------------------------ |
| Windows  | `C:\Program Files\Sonar\agent.log` (`C:\Program Files (x86)\Sonar\agent.log` for a 32-bit agent on 64-bit Windows) |
| Linux    | `/var/log/sonaragent.log`                                                                                          |
| macOS    | `/var/log/sonaragent.log`                                                                                          |

For verbose output, stop the service and run the agent in the foreground with debug logging, then stop it with Ctrl+C and start the service again:

| Platform                  | Commands                                                                                                                                                                                                                        |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Windows (elevated prompt) | `net stop sonarrmm`, then `"C:\Program Files\Sonar\sonarrmm.exe" -m rpc -log debug -logto stdout`, then `net start sonarrmm`                                                                                                    |
| Linux                     | `sudo systemctl stop sonaragent`, then `sudo /usr/local/bin/sonaragent -m svc -log debug -logto stdout`, then `sudo systemctl start sonaragent`                                                                                 |
| macOS                     | `sudo launchctl bootout system /Library/LaunchDaemons/sonaragent.plist`, then `sudo /opt/sonaragent/sonaragent -m svc -log debug -logto stdout`, then `sudo launchctl bootstrap system /Library/LaunchDaemons/sonaragent.plist` |

On Windows, running `"C:\Program Files\Sonar\sonarrmm.exe"` without arguments shows a **Sonar RMM** box with the agent version and the state of the agent and remote access agent services.

### Reinstall over an existing agent

| Platform | What to do                                                                                                                                                                                             |
| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Windows  | Uninstall first: `"C:\Program Files\Sonar\uninstall.exe" /S`, then run a new installer. An installer run over an existing agent offers to remove it (interactive) or exits without installing (silent) |
| Linux    | Run the install script again. It removes the previous agent and remote access agent before installing                                                                                                  |
| macOS    | Run the install command again. It removes the previous agent and remote access agent before installing                                                                                                 |

A reinstalled device registers as a new device record. Remove the old record, now offline, with **Remove Agent**. See [Remove agents](https://wiki.datadike.com/sonar/deploy-operate/remove-agents.md).

Reinstalling is also how optional features are changed on a Windows device: generate an installer with the new selection.

## How to verify it worked

* In **Dashboard › Sysadmin**, the device shows **Agent Status** **Online** and a **Last Response** of a moment ago.
* In the details panel, the pill reads **Remote Online** and **Take Control** is enabled.
* In **Agents › Pending Actions**, the device's actions move to completed.
* On the device, the agent log shows no new connection errors after the restart.

## Common errors

| Symptom or message                                                                                                                         | Cause                                                                             | Fix                                                                                                                      |
| ------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| *Installer token has expired. Please generate a new one.*                                                                                  | The installer or deployment link passed its expiry, or its deployment was deleted | Generate a new installer or deployment                                                                                   |
| *Old installer detected (version …). Latest version is … Please generate a new installer from the RMM*                                     | The installer was generated before the current agent version                      | Generate a new installer                                                                                                 |
| *This application requires a 64-bit Windows operating system.*                                                                             | 64-bit installer on 32-bit Windows                                                | Use a **32-bit** installer                                                                                               |
| *Existing installation found* (message box), or *Existing installation found and must be removed before attempting to reinstall.* (silent) | An agent, or what is left of one, is already on the Windows device                | Uninstall with `uninstall.exe /S`, then install again                                                                    |
| *Sonar RMM Is Already Installed*                                                                                                           | The PowerShell installer found the `sonarrmm` service                             | Uninstall first, or leave the device as it is                                                                            |
| *Waiting for network* repeated, then *Unable to connect to server*                                                                         | The PowerShell installer cannot reach the API address on 443/tcp                  | Fix the network path; see [Network requirements](https://wiki.datadike.com/sonar/deploy-operate/network-requirements.md) |
| *Unable to download the mesh agent from the RMM.* / *Failed to download mesh agent*                                                        | The installer could not get the remote access agent through the API address       | Check connectivity to the API address, then run the installer again                                                      |
| *Invalid URL (must contain https or http)*                                                                                                 | The `-api` value of a manual command was edited or truncated                      | Copy the command again from the console                                                                                  |
| *ERROR: Must be run as root* / *must run as root*                                                                                          | Linux script or macOS agent run without root                                      | Run with `sudo`                                                                                                          |
| *This install script only supports systemd*                                                                                                | Linux distribution without systemd                                                | Not supported; see [Endpoint requirements](https://wiki.datadike.com/sonar/deploy-operate/requirements.md)               |
| *ERROR: Display detected. Installer only supports running headless, i.e from ssh.*                                                         | Linux script started from a graphical session                                     | Run over SSH, from a text console, or after `unset DISPLAY`                                                              |
| *ERROR: Unable to download sonar agent*                                                                                                    | The Linux device cannot download from the API address                             | Check 443/tcp and name resolution                                                                                        |
| **Agent offline** dialog, *… cannot be contacted*                                                                                          | The device did not answer when you chose **Remove Agent**                         | See [Remove agents](https://wiki.datadike.com/sonar/deploy-operate/remove-agents.md)                                     |
| *Unable to contact the agent*                                                                                                              | An action needed an answer from the device and none came                          | Check **Agent Status** and **Last Response**; bring the device back online                                               |
| Device **Online** but **Remote Offline**                                                                                                   | The remote access agent is stopped or cannot reach the remote access address      | **Restart Remote Service**, then check the network path                                                                  |
| Device shows twice in the list                                                                                                             | It was reinstalled and the old record kept                                        | Remove the offline record with **Remove Agent**                                                                          |

## Related pages

* [Network requirements](https://wiki.datadike.com/sonar/deploy-operate/network-requirements.md)
* [Update agents](https://wiki.datadike.com/sonar/deploy-operate/agent-updates.md)
* [Remove agents](https://wiki.datadike.com/sonar/deploy-operate/remove-agents.md)
* [Device details](https://wiki.datadike.com/sonar/administration/devices/device-details.md)
* [The device list](https://wiki.datadike.com/sonar/administration/devices/device-list.md)
