> 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/administration/automation/checks.md). Agents can also search and read this documentation through its [MCP server](https://wiki.datadike.com/~gitbook/mcp).

# Checks

Monitor devices with checks (CPU load, disk space, memory, ping, Windows service, event log, script): thresholds, failure counts, intervals, run now, reset, run history and alerts.

## What this is and when to use it

A check is a test the agent runs on the device at a regular interval: is the disk too full, is the CPU or memory too busy, does a host answer ping, is a Windows service running, has an event been written to a Windows event log, does a script return success. The agent sends each result to SONAR, which marks the check **Passing** or failing with a severity, keeps a run history, and raises an alert when a check fails a set number of times in a row.

Checks are defined on one device, in its **CHECKS** tab, or in an [automation policy](https://wiki.datadike.com/sonar/administration/automation/automation-policies.md), which applies them to every device that inherits it. Use policies for the checks every device of a kind needs, and device checks for exceptions.

## Before you start

* A role with **List Checks** to see checks, **Manage Checks** to add, edit, delete and reset them, and **Run Checks** for **Run Checks Now**. They are in the **Checks & Monitoring** group of **Admin Center › Roles**.
* Access to the device's client or site.
* For a script check, the script in **Management › Scripts**, supporting the device's platform. A script check fails when the script exits with a code other than 0, unless that code is listed as informational or warning.
* On a device, Linux and macOS offer **Ping Check** and **Script Check**. The other five types are for Windows devices.

## Steps

### Add a check to a device

1. Open **Dashboard › Sysadmin**, select the device and open its **CHECKS** tab.
2. Click **New** and choose the type: **Disk Space Check**, **Ping Check**, **CPU Load Check**, **Memory Check**, **Windows Service Check**, **Script Check** or **Event Log Check**.
3. Fill the form (see the field reference for each type).
4. Set **Number of consecutive failures before alert**: how many failing results in a row raise an alert.
5. Leave **Run this check every (seconds)** at `0` to follow the device's own check interval, or set a value for this check only.
6. Click **Save**.
7. In the check's row, tick the **SMS Alert**, **Email Alert** and **Dashboard Alert** columns for the channels that must be used when it fails.

To add checks to many devices at once, add them to a policy instead: open **Management › Automations**, select the policy and use its **Checks** tab. The forms are the same, and policy forms offer all seven types.

### Run checks now

Click **Run Checks Now** in the **CHECKS** tab, or choose **Run Checks** in the device's action menu. The agent runs all its checks immediately instead of waiting for the next interval. The confirmation reads `Checks will now be run on <device>`.

### Reset a failing check

A reset marks a failing check as passing and resolves its open alert, without waiting for the next result.

* One check: right-click it and choose **Reset Check Status**. The confirmation reads `The check status was reset`.
* All checks of the device: click **Reset All Checks Status** and confirm. The confirmation reads `All checks status were reset`.

If the problem is still there, the next run fails again and a new alert opens.

### See the run history

Click **Show Run History** in the check's **More Info** column. The graph plots each result over **Last 24 Hours**, **Last 7 Days**, **Last 30 Days** or **Everything**:

* CPU, memory and disk checks plot the percentage, with the **Warning Threshold** and **Error Threshold** lines. Disk checks plot the free space.
* Ping, service, event log and script checks plot **Passing** or **Failing**. Hovering a point of a script check shows its return code, output and run time.

The history is kept for the number of days set in **Admin Center › Settings › Retention** (see [Data retention](https://wiki.datadike.com/sonar/administration/settings/retention.md)).

### Edit or delete

Double-click a device check, or right-click it and choose **Edit** or **Delete**. Checks that come from a policy show the shield icon (`This check is managed by a policy`) and are changed in the policy.

## How results are evaluated

| Check               | Fails when                                                                                                                              | Severity                                                                                                                                 |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| **CPU Load**        | The average of the last 15 samples is above a threshold                                                                                 | **Error** above **Error Threshold (%)**, otherwise **Warning** above **Warning Threshold (%)**                                           |
| **Memory**          | Same as CPU, for memory use                                                                                                             | Same as CPU                                                                                                                              |
| **Disk Space**      | The free space is below a threshold, or the disk does not exist                                                                         | **Error** below **Error Threshold Remaining (%)** or for a missing disk, otherwise **Warning** below **Warning Threshold Remaining (%)** |
| **Ping**            | The host does not answer                                                                                                                | The check's **Alert Severity**                                                                                                           |
| **Windows Service** | The service is not running (see the pass options)                                                                                       | The check's **Alert Severity**                                                                                                           |
| **Event Log**       | **Log contains**: at least **Number of events found before alert** matching events are found. **Log does not contain**: fewer are found | The check's **Alert Severity**                                                                                                           |
| **Script**          | The exit code is not 0                                                                                                                  | **Informational** or **Warning** if the code is in the matching list, otherwise **Error**                                                |

A threshold left at `0` is not evaluated. At least one threshold must be set.

When a check keeps failing for **Number of consecutive failures before alert** results, SONAR raises a check alert. Where it is delivered depends on the **SMS Alert**, **Email Alert** and **Dashboard Alert** settings of the check and on the alert template that applies to the device; an alert template can force these settings, and the check row then shows `Setting is overridden by alert template: <name>`. The first passing result resolves the alert. See [Alerts and alert templates](https://wiki.datadike.com/sonar/administration/automation/alerts.md).

A check can also start an automated task when it fails: create a task with the trigger **On check failure** and select the check. The task appears in the check's **Assigned Tasks** column. See [Automated tasks](https://wiki.datadike.com/sonar/administration/automation/automated-tasks.md).

## What you should see

Each check row shows the three alert columns, a policy icon for policy checks (or `This check is overriden by a policy` when a policy check of the same kind replaces a device check), the status (**Passing**, **Informational**, **Warning** or **Error**), **Description**, **More Info**, **Last Run** and **Assigned Tasks**. **Last Run** shows **Never** until the first result.

**More Info** carries the latest detail: the average load, the disk usage, the service state, the ping summary, the first characters of a script's output (click it for **Script Output**) or **Last Output** for event logs (click it for the list of events found).

## How to verify it worked

1. Click **Run Checks Now**, wait a few seconds and click the refresh button of the tab. **Last Run** shows the current time and the status reflects the result.
2. Open **Show Run History** and check that the new point is there.
3. To test alerting, make the check fail on purpose, for example with a disk check whose **Warning Threshold Remaining (%)** is above the current free space and **Number of consecutive failures before alert** at 1. After the next run, the device's **CHECKS STATUS** in the device list changes and the alert appears in the **Alerts** overview, if the check or its alert template enables the dashboard channel.
4. Restore the threshold, run the checks again and confirm the alert is resolved.

## Common errors

| Symptom                                                                                          | Cause                                                                                                  | Fix                                                                         |
| ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------- |
| **New** is greyed out with `You don't have permission for this action`                           | The role lacks **Manage Checks**                                                                       | Add the permission                                                          |
| `Warning Threshold or Error Threshold need to be set`                                            | Both thresholds are 0                                                                                  | Set at least one                                                            |
| `Warning Threshold must be less than Error Threshold`                                            | CPU or memory warning above error                                                                      | CPU and memory rise towards the error threshold; set warning lower          |
| `Warning Threshold must be more than Error Threshold`                                            | Disk warning below error                                                                               | Disk thresholds are free space; set warning higher                          |
| `A disk check for Drive <disk> already exists!`                                                  | The device or policy already checks that disk                                                          | Edit the existing check                                                     |
| `A cpuload check for this agent already exists` / `A memory check for this agent already exists` | Only one CPU and one memory check per device or policy                                                 | Edit the existing check                                                     |
| `Please enter a valid IP address or domain name`                                                 | Ping target is not an IP address or domain name                                                        | Correct **Hostname or IP**                                                  |
| `Invalid Event ID`                                                                               | Event ID is empty or not a number                                                                      | Enter a number, or `*` for every event ID                                   |
| `Checks are already running on <device>`                                                         | A run is already in progress                                                                           | Wait and refresh                                                            |
| `Unable to contact the agent`                                                                    | The device is offline                                                                                  | Checks run again when it reconnects                                         |
| A script check form shows only a short message                                                   | No script supports the device's platform                                                               | Add or adjust a script in **Management › Scripts**                          |
| No alert although the check fails                                                                | Fewer failures than the configured count, or no channel enabled for the check or in the alert template | Check **Number of consecutive failures before alert** and the alert columns |

## Field reference

### Common fields

| Field                                       | What it does                                                                                   | Accepted values                           | Default     |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------- | ----------------------------------------- | ----------- |
| Number of consecutive failures before alert | Failing results in a row before an alert is raised                                             | 1 to 10                                   | 1           |
| Run this check every (seconds)              | Interval for this check. `0` uses the device's check interval, set with **Edit** on the device | Seconds                                   | 0           |
| Alert Severity                              | Ping, service, event log only. Severity of the failure                                         | **Informational**, **Warning**, **Error** | **Warning** |

### Disk Space Check

| Field                           | What it does                                                                             | Accepted values            | Default     |
| ------------------------------- | ---------------------------------------------------------------------------------------- | -------------------------- | ----------- |
| Disk                            | Drive to monitor. On a device, the list shows its drives. Cannot be changed after saving | Drive letter, `A:` to `Z:` | First drive |
| Warning Threshold Remaining (%) | Warning below this free space                                                            | 0 to 99                    | 25          |
| Error Threshold Remaining (%)   | Error below this free space                                                              | 0 to 99                    | 10          |

### CPU Load Check and Memory Check

| Field                 | What it does               | Accepted values | Default                   |
| --------------------- | -------------------------- | --------------- | ------------------------- |
| Warning Threshold (%) | Warning above this average | 0 to 99         | 70                        |
| Error Threshold (%)   | Error above this average   | 0 to 99         | 90 for CPU, 85 for memory |

### Ping Check

| Field            | What it does                  | Accepted values           | Default         |
| ---------------- | ----------------------------- | ------------------------- | --------------- |
| Descriptive Name | Name shown in **Description** | Text                      | Empty. Required |
| Hostname or IP   | Target pinged from the device | IPv4, IPv6 or domain name | Empty. Required |

### Windows Service Check

| Field                                      | What it does                                                                                         | Accepted values | Default       |
| ------------------------------------------ | ---------------------------------------------------------------------------------------------------- | --------------- | ------------- |
| Service                                    | On a device, the service to watch, chosen from the device's services. Cannot be changed after saving | A service       | First service |
| Choose from defaults / Enter manually      | Policies only. Pick from a list of common services, or type **Service Name** and **Display Name**    | Choice          | None          |
| PASS if service is in 'Start Pending' mode | Treats a starting service as passing                                                                 | On or off       | Off           |
| PASS if service doesn't exist              | Treats a missing service as passing, useful in policies                                              | On or off       | Off           |
| Restart service if it's stopped            | The agent starts the service when it finds it stopped                                                | On or off       | Off           |

### Event Log Check

| Field                                                         | What it does                                                   | Accepted values                                                               | Default          |
| ------------------------------------------------------------- | -------------------------------------------------------------- | ----------------------------------------------------------------------------- | ---------------- |
| Descriptive Name                                              | Name shown in **Description**                                  | Text                                                                          | Empty. Required  |
| Event log to query                                            | Log searched                                                   | **Application**, **System**, **Security**                                     | **Application**  |
| Fail When                                                     | Whether finding events is a failure or a success               | **Log contains**, **Log does not contain**                                    | **Log contains** |
| Event ID (Use \* to match every event ID)                     | Event ID to match                                              | A number, or `*`                                                              | Empty. Required  |
| Event source                                                  | When ticked, only events from this source match                | Text                                                                          | Off              |
| Message contains string                                       | When ticked, only events whose message contains the text match | Text                                                                          | Off              |
| How many previous days to search (Enter 0 for the entire log) | Search window                                                  | 0 to 9999                                                                     | 1                |
| Event Type                                                    | Level of the events to match                                   | **Information**, **Warning**, **Error**, **Success Audit**, **Failure Audit** | **Information**  |
| Number of events found before alert                           | Matching events needed for **Log contains** to fail            | Whole number                                                                  | 1                |

### Script Check

The dialog is titled **Add Policy Check** (or **Edit Policy Check**) on devices and on policies.

| Field                                                     | What it does                                  | Accepted values                                                                              | Default               |
| --------------------------------------------------------- | --------------------------------------------- | -------------------------------------------------------------------------------------------- | --------------------- |
| Select script                                             | Script to run. Cannot be changed after saving | Library scripts supporting the platform                                                      | None. Required        |
| Policy Arguments (press Enter after typing each argument) | Arguments passed to the script                | Text, with [script variables](https://wiki.datadike.com/sonar/reference/script-variables.md) | The script's defaults |
| Environment vars                                          | Environment variables, as `KEY=VALUE`         | Text, with script variables                                                                  | The script's defaults |
| Informational return codes                                | Exit codes that mean an informational failure | Whole numbers                                                                                | None                  |
| Warning return codes                                      | Exit codes that mean a warning                | Whole numbers                                                                                | None                  |
| Policy Timeout (seconds)                                  | Maximum run time of the script                | Seconds                                                                                      | The script's default  |

## Related pages

* [Automation policies](https://wiki.datadike.com/sonar/administration/automation/automation-policies.md)
* [Alerts and alert templates](https://wiki.datadike.com/sonar/administration/automation/alerts.md)
* [Automated tasks](https://wiki.datadike.com/sonar/administration/automation/automated-tasks.md)
* [Device details](https://wiki.datadike.com/sonar/administration/devices/device-details.md)
* [Data retention](https://wiki.datadike.com/sonar/administration/settings/retention.md)
