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

# Automation policies

Group checks, tasks, a patch policy and an alert template into an automation policy, assign it to clients, sites or devices, and control inheritance, precedence and exclusions.

## What this is and when to use it

An automation policy is a reusable bundle of monitoring and maintenance: a set of [checks](https://wiki.datadike.com/sonar/administration/automation/checks.md), a set of [automated tasks](https://wiki.datadike.com/sonar/administration/automation/automated-tasks.md), an optional [patch policy](https://wiki.datadike.com/sonar/administration/patching/patch-policy.md) and an optional [alert template](https://wiki.datadike.com/sonar/administration/automation/alerts.md). You build the policy once and assign it where it applies; every device covered by the assignment receives its checks and tasks without being configured one by one.

Use policies for the baseline of each kind of device (for example, all workstations of a client get the same disk, service and clean-up rules) and keep device-level checks and tasks for exceptions.

## Before you start

* A role with **List Automation Policies** to open the list and **Manage Automation Policies** to create, edit, copy, delete and exclude, both in the **Automation & Tasks** group of **Admin Center › Roles**. Adding checks and tasks to a policy also needs **Manage Checks** and **Manage Tasks**.
* To assign a policy, the **Assign Automation Policy** dialog needs **Manage Policies** (group **Policies**), and saving the assignment needs the right to change the target: **Manage Clients** for a client, **Manage Sites** for a site, **Edit Agent** for a device.
* The scripts used by script checks and tasks, in **Management › Scripts**.

## How policies reach a device

A device can receive up to four policies, one from each level:

| Level   | Where it is set                                                                                                  | Applies to                           |
| ------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------------ |
| Device  | **Assign Automation Policy** on the device, field **Policy**                                                     | That device                          |
| Site    | **Assign Automation Policy** on the site, fields **Server Policy** and **Workstation Policy**                    | The site's servers or workstations   |
| Client  | **Assign Automation Policy** on the client, same two fields                                                      | The client's servers or workstations |
| Default | **Admin Center › Settings › General**, section **Defaults**, fields **Server Policy** and **Workstation Policy** | Every server or workstation          |

Which of the two fields applies depends on the device's type (server or workstation). A policy only takes effect while it is **Active**.

**Block policy inheritance** stops policies from higher levels: on a device it ignores the site, client and default policies; on a site it ignores the client and default policies; on a client it ignores the default policy.

A device listed in a policy's exclusions, or belonging to an excluded site or client, does not receive that policy; the other levels still apply.

### Precedence

* **Tasks** add up: the device runs its own tasks plus the tasks of every policy that reaches it, for the platforms each task supports.
* **Checks** are merged by kind, so a device never runs two checks of the same kind: one CPU check, one memory check, one disk check per drive, one ping check per target, one service check per service, one script check per script, one event log check per log and event ID. When two checks of the same kind meet, the first one in this order wins:

  1. checks of **Enforced** policies,
  2. the device's own checks,
  3. checks of the other policies.

  Within each group, the device policy comes first, then site, client and default. A device check that loses to an enforced policy check shows `This check is overriden by a policy` in the device's **CHECKS** tab.

Checks and tasks that only exist for Windows (disk, CPU, memory, service and event log checks, and tasks limited to Windows) are skipped on Linux and macOS devices.

## Steps

### Create a policy

1. Open the **Management** menu in the header and choose **Automations**.
2. Click **New**.
3. In **Add Policy**, fill **Policy Name** and **Description**.
4. Tick **Active** so the policy takes effect once assigned. A new policy is inactive until you tick it.
5. Tick **Enforced** if its checks must win over the devices' own checks. **Enforced** has no effect on the policy's patch policy.
6. Click **Submit**. The confirmation reads `Policy added. Now you can add Tasks and Checks!`

### Add checks and tasks

1. Select the policy in the list. Its **Checks** and **Tasks** tabs open below.
2. In **Checks**, click **+** and choose the check type. Fill the form as described in [Checks](https://wiki.datadike.com/sonar/administration/automation/checks.md).
3. In **Tasks**, click **Add Task** and fill the form as described in [Automated tasks](https://wiki.datadike.com/sonar/administration/automation/automated-tasks.md). Tick the **Supported Platforms** the task applies to.

### Add a patch policy and an alert template

1. In the policy row, click **Create Patch Policy** (or **Modify Patch Policy**) and fill the form described in [Patch approval policy](https://wiki.datadike.com/sonar/administration/patching/patch-policy.md). For the complete procedure to keep Windows devices patched, see [Automate Windows updates](https://wiki.datadike.com/sonar/administration/patching/automate-windows-updates.md).
2. Click **Assign Alert Template** (or **Modify Alert Template**) and choose a template. See [Alerts and alert templates](https://wiki.datadike.com/sonar/administration/automation/alerts.md).

### Assign the policy

* **To a client or a site**: in the **CLIENTS** list of the sidebar, right-click the client or the site and choose **Assign Automation Policy**. Choose the **Server Policy** and the **Workstation Policy**, tick **Block policy inheritance** if needed, and click **Submit**.
* **To a device**: open the device's action menu and choose **Assign Automation Policy**. Choose the **Policy**, tick **Block policy inheritance** if needed, and click **Submit**.
* **As a default**: in **Admin Center › Settings › General**, set **Server Policy** and **Workstation Policy** under **Defaults** and save.

The confirmation reads `Policies Updated Successfully!`

{% hint style="info" %}
A client or site has one policy for servers and one for workstations. When it has both kinds of device, fill in **Server Policy** and **Workstation Policy**, or one kind is left without the policy. Try a new policy on one test device or site before assigning it to a whole client.
{% endhint %}

### Exclude clients, sites or devices

1. In the policy row, click **Show Policy Exclusions (N)**, or right-click the policy and choose **Policy Exclusions**.
2. Add entries to **Excluded Clients**, **Excluded Sites** or **Excluded Agents**.
3. Save. The confirmation reads `Policy exclusions added`.

### Copy, edit, disable or delete

* Click the copy icon (`Create a copy of this policy`) or right-click and choose **Copy** to create a new policy with the same checks and tasks. Tasks with the trigger **On check failure** are not copied.
* Double-click a policy, or right-click and choose **Edit**, to change its name, description, **Active** or **Enforced**.
* Untick **Active** in the list to stop the policy everywhere without deleting it.
* Right-click and choose **Delete** to remove it.

### Run a policy task and follow its status

* In the policy's **Tasks** tab, click **Run** on a task to start it on every device that receives the policy. The confirmation reads `The task was initated on all affected agents`.
* In the **Checks** or **Tasks** tab, click **See Status** to see the result on each device: **Hostname**, **Status**, **More Info** and **Date / Time**, and, for tasks, whether the task is synced with each Windows device.

## What you should see

The policy list shows **Active**, **Enforced**, **Name** (with the **Default Server** or **Default Workstation** badge when it is a default), **Description**, **Relations** (`Show Relations (N)`), **Exclusions** (`Show Policy Exclusions (N)`), **Patch Policy**, **Alert Template** and **Actions**.

**Show Relations (N)** counts the devices that receive the policy. Its dialog lists, in the **Clients** and **Sites** tabs, where the policy is assigned, marked **Applied to Servers** or **Applied to Workstations**, and in the **Agents** tab the devices it is assigned to directly.

## How to verify it worked

1. Open a device that should receive the policy and choose **Edit** in its action menu. The **Automation Policies** tab lists the policy that applies at each level (**Agent policy**, **Site policy**, **Client policy**, **Default policy**), marks inactive ones as **Disabled**, and shows the effective **Alert Template** and **Effective Patch Policy**.
2. Open the device's **CHECKS** and **TASKS** tabs. Policy items show the policy icon (`This check is managed by a policy`, `This task is managed by a policy`).
3. After the next check cycle, **See Status** in the policy lists the device with a result.
4. In **Reports & Audits › Audits**, creating and changing the policy are recorded as **Add Object** and **Modify Object** on a **Policy**.

## Common errors

| Symptom                                                                                                 | Cause                                                                                                | Fix                                                         |
| ------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| Devices do not receive the policy                                                                       | The policy is not **Active**                                                                         | Tick **Active** in the list                                 |
| Only servers (or only workstations) receive it                                                          | The policy was set in **Server Policy** but not in **Workstation Policy**, or the reverse            | Set the field that matches the device type                  |
| A device does not receive a client or default policy                                                    | **Block policy inheritance** is set on the device, its site or its client, or the device is excluded | Review the inheritance flags and **Show Policy Exclusions** |
| A policy check does not appear on a Linux or macOS device                                               | The check type is Windows only, or the script does not support the platform                          | Use ping or script checks for those devices                 |
| A device's own check stopped running                                                                    | An enforced policy has a check of the same kind                                                      | Remove one of them, or make the policy not enforced         |
| **Submit** in **Assign Automation Policy** is disabled with `You don't have permission for this action` | The role lacks **Manage Policies**                                                                   | Add the permission                                          |
| The dialog shows `No Automation Policies have been setup.`                                              | No policy exists yet                                                                                 | Create one in **Management › Automations**                  |
| `Task cannot be run when it's disabled. Enable it first.`                                               | **Run** on a disabled policy task                                                                    | Enable the task                                             |

## Field reference

### Add Policy / Edit Policy

| Field       | What it does                                                 | Accepted values | Default         |
| ----------- | ------------------------------------------------------------ | --------------- | --------------- |
| Policy Name | Identifies the policy. Unique                                | Text            | Empty. Required |
| Description | Free description                                             | Text            | Empty           |
| Active      | The policy takes effect where assigned                       | On or off       | Off             |
| Enforced    | Its checks win over the devices' own checks of the same kind | On or off       | Off             |

### Assign Automation Policy

| Field                    | Shown for            | What it does                                      | Default |
| ------------------------ | -------------------- | ------------------------------------------------- | ------- |
| Server Policy            | Client, site         | Policy for the servers of the client or site      | None    |
| Workstation Policy       | Client, site         | Policy for the workstations of the client or site | None    |
| Policy                   | Device               | Policy for this device                            | None    |
| Block policy inheritance | Client, site, device | Ignores the policies of the levels above          | Off     |

### Policy Exclusions

| Field            | What it does                                          |
| ---------------- | ----------------------------------------------------- |
| Excluded Clients | The policy does not apply to devices of these clients |
| Excluded Sites   | The policy does not apply to devices of these sites   |
| Excluded Agents  | The policy does not apply to these devices            |

## Related pages

* [Checks](https://wiki.datadike.com/sonar/administration/automation/checks.md)
* [Automated tasks](https://wiki.datadike.com/sonar/administration/automation/automated-tasks.md)
* [Patch approval policy](https://wiki.datadike.com/sonar/administration/patching/patch-policy.md)
* [Alerts and alert templates](https://wiki.datadike.com/sonar/administration/automation/alerts.md)
* [Clients and sites](https://wiki.datadike.com/sonar/administration/devices/clients-and-sites.md)
