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

# Alerts and alert templates

Work with alerts raised by overdue devices, failing checks and failing tasks, and configure alert templates: channels, severities, resends, actions, exclusions and where templates apply.

## What this is and when to use it

SONAR raises an alert in three situations:

| Type             | Raised when                                                                 | Severity                                                                                           |
| ---------------- | --------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
| **Availability** | A device has not checked in for longer than its **Overdue after (minutes)** | **Error**                                                                                          |
| **Check**        | A check fails for its **Number of consecutive failures before alert**       | From the check (see [Checks](https://wiki.datadike.com/sonar/administration/automation/checks.md)) |
| **Task**         | An automated task ends with a non-zero return code                          | The task's **Alert Severity**                                                                      |

Each alert can be shown on the dashboard, emailed, sent by SMS, and can start an action (a script on the device or a web hook). An **alert template** decides who is notified, for which severities, how often, and which action runs; it is assigned globally, to a client, a site or an automation policy.

Use this page to follow up alerts day to day and to design the templates that route them.

## Before you start

* A role with **List Alerts** to see alerts and **Manage Alerts** to resolve and snooze them; **List Alert Templates** and **Manage Alert Templates** for templates. They are in the **Alerts** group of **Admin Center › Roles**.
* For email, the mail server set in **Admin Center › Settings › Mail Server**; for SMS, the **SMS** tab. See [Email and SMS notifications](https://wiki.datadike.com/sonar/administration/settings/email-and-sms.md).
* For web hook actions, the web hook created in **Admin Center › Settings › Web Hooks**. See [Webhooks](https://wiki.datadike.com/sonar/administration/settings/webhooks.md).
* For script actions, the script in **Management › Scripts**.

## How the channels are decided

For every alert, SONAR combines three layers:

1. **The item's own settings.** A device has **Get overdue email alerts**, **Get overdue sms alerts** and **Get overdue dashboard alerts** in **Edit › General**. Checks and tasks have the **SMS Alert**, **Email Alert** and **Dashboard Alert** columns in the device's **CHECKS** and **TASKS** tabs.
2. **The alert template that applies to the device.** Its **Email**, **Text** and **Dashboard** switches have three positions: on (always notify, overriding the item), middle (**Not configured**: use the item's setting) and off (never notify, overriding the item). When a template overrides a check or task, the column shows `Setting is overridden by alert template: <name>`. For checks and tasks, the template also filters by severity (**Only email on alert severity**, **Only text on alert severity**, **Only show dashboard alert on severity**).
3. **The global severity switch.** In **Admin Center › Settings › General**, **Receive notifications on:** **Informational Alerts** and **Warning Alerts** decide whether alerts of those severities are emailed, sent by SMS or sent to a web hook at all. Error alerts are always eligible.

Email and SMS go to the template's **Email recipients** and **SMS recipients** when they are set, otherwise to the global recipients of the **Mail Server** and **SMS** tabs.

A device in maintenance mode (**Enable Maintenance Mode** in its action menu) raises no new alerts. Use it for planned work.

## Steps

### Follow up alerts

1. Click the bell in the header. **NOTIFICATIONS** shows how many alerts are open and a few of them, each with **Snooze alert** and **Resolve alert**. The bell refreshes about every minute.
2. Click **VIEW ALL** to open the **Alerts** overview.
3. Filter by **Clients**, **Severity** and **Time** (**1 Day Ago** to **1 Year Ago**, or **Everything**), tick **Include snoozed** or **Include resolved** if needed, and click **Search**. The overview opens with the last 30 days of open alerts.
4. Act on one alert with the buttons of its **Actions** column, or tick several and use **Snooze selected** or **Resolve selected**. **Resolve all** resolves every unresolved alert loaded by the current search.

| Action                                                                     | What it does                                                                                                                                                               |
| -------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Resolve alert**                                                          | Closes the alert. If the problem is still there, the next failure raises a new alert. A manual resolve does not send resolution notifications or run the resolution action |
| **Snooze alert**                                                           | Asks `How many days to snooze alert?` and hides the alert from the bell and from the overview (unless **Include snoozed** is ticked) for that many days                    |
| **Unsnooze alert**                                                         | Lists a snoozed alert again straight away                                                                                                                                  |
| **Show failure action run results** / **Show resolved action run results** | Shows the result of the action run by the template: last run, run time, return code and output                                                                             |

Alerts also close on their own: when the check passes again, when the task succeeds on its next run, or when an overdue device checks in again. A check reset (**Reset Check Status**) resolves its alert too.

### Create an alert template

1. Click **Alerts** in the header. The **Alert Templates** panel opens.
2. Click **New**. **Add Alert Template** opens on **General Settings**.
3. Fill **Name** and leave **Enabled** on. Optionally set **Email From address**, and add recipients with **Add email** and **Add sms number** (SMS numbers in E.164 format, for example `+15555550100`).
4. Click **Next**. In **Alert Actions**, choose the action to run when an alert is raised (**Alert Failure Settings**) and when it resolves (**Alert Resolved Settings**), or leave the script empty for no action. Under **Run actions only on**, keep on only the alert types the action is meant for: **Agents**, **Checks**, **Tasks**.
5. Click **Next**. In **Agent Overdue Settings**, set the **Email**, **Text** and **Dashboard** switches for overdue devices, **Alert again if not resolved after (days)**, and whether to send **Email** or **Text** when the device is back online.
6. Click **Next**. In **Check Settings**, set the same switches for failing checks, the severity filters, the resend interval and the resolution notifications.
7. Click **Next**. In **Automated Task Settings**, do the same for failing tasks.
8. Click **Submit**. The confirmation reads `Alert Template created!`

{% hint style="info" %}
A script action runs on the device through its agent, so it suits check and task alerts. An overdue device cannot be reached by definition: for overdue alerts, use a web hook, and keep **Agents** off under **Run actions only on** when the failure action is a script.
{% endhint %}

### Assign the template

A template does nothing until it is assigned:

* **Globally**: **Admin Center › Settings › General**, section **Defaults**, field **Alert Template**.
* **To a client or a site**: in the **CLIENTS** list of the sidebar, right-click the client or site and choose **Assign Alert Template**, then pick it in **Client Alert Template** or **Site Alert Template** and click **Submit**.
* **To an automation policy**: in **Management › Automations**, click **Assign Alert Template** (or **Modify Alert Template**) in the policy row.

A device uses one template only: the first one found in this order.

1. The template of the device's own policy
2. The template of the site's policy
3. The template of the site
4. The template of the client's policy
5. The template of the client
6. The global template
7. The template of the default policy

Disabled templates and templates that exclude the device are skipped.

### Exclude clients, sites, devices or device types

1. In the **Alert Templates** panel, click **Exclusions (N)** on the template, or right-click it and choose **Alert Exclusions**.
2. Fill **Excluded Clients**, **Excluded Sites** and **Excluded Agents**, or tick **Exclude Workstations** or **Exclude Servers**.
3. Click **Save**. An excluded device falls through to the next template in the order above.

### Enable, disable, edit or delete a template

Use the switch at the start of the row to enable or disable it. Double-click the template, or right-click it, to **Edit** or **Delete** it. **Applied (N)** lists the policies, clients and sites that use it.

## What you should see

The **Alert Templates** panel lists each template with its switch, ticks for **Agent alert settings**, **Check alert settings** and **Task alert settings** when those steps are configured, its name, a **Default** badge for the global template, **Applied (N)**, **Exclusions (N)** and the names of its actions.

The **Alerts** overview shows **Time**, **Client**, **Site**, **Agent**, **Type**, **Severity**, **Message** and **Actions**, plus **Resolved On** when resolved alerts are included. Messages read, for example, `WS-0001 in CLIENT-A, SITE-01 is overdue.`, `WS-0001 has a diskspace check: <description> that failed.` or `WS-0001 has task: <name> that failed.`

## How to verify it worked

1. Open a device covered by the template and choose **Edit** in its action menu. The **Automation Policies** tab shows the effective **Alert Template**.
2. Make a check fail on purpose (see [Checks](https://wiki.datadike.com/sonar/administration/automation/checks.md), "How to verify it worked"). After the configured number of failures, the alert appears in the bell and in the overview if the dashboard channel applies, and the email or SMS arrives if those channels apply.
3. If the template has a failure action, open the alert in the overview and use **Show failure action run results**. For a script action, the device's **HISTORY** tab also shows the run.
4. Fix the cause and run the checks again. The alert closes, the resolution notifications are sent if enabled, and **Show resolved action run results** appears when a resolution action ran.
5. In **Reports & Audits › Audits**, creating and changing a template are recorded as **Add Object** and **Modify Object**.

## Common errors

| Symptom                                                                      | Cause                                                                                                                            | Fix                                                                                          |
| ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| `Name needs to be set`                                                       | The template has no name                                                                                                         | Fill **Name** on **General Settings**                                                        |
| `Failure script timeout is required` / `Resolved script timeout is required` | A script action without timeout                                                                                                  | Enter the timeout in seconds                                                                 |
| `Periodic days must be 0 or greater`                                         | Negative resend interval                                                                                                         | Enter 0 (no resend) or more                                                                  |
| No email for warning or informational alerts                                 | **Receive notifications on:** does not include that severity, or the template's **Only email on alert severity** leaves it out   | Tick the severity in **Admin Center › Settings › General**, or add it to the template filter |
| No email at all                                                              | The device, check or task has no email channel and the template's **Email** is **Not configured**, or the mail server is not set | Enable the channel on the item or set **Email** on in the template; test the mail server     |
| The template has no effect on a device                                       | It is disabled, not assigned where the device inherits it, the device is excluded, or a template earlier in the order applies    | Check **Edit › Automation Policies › Alert Template** on the device                          |
| **Snooze selected** and **Resolve selected** are disabled                    | No alert is ticked, or **Include resolved** is on                                                                                | Tick alerts and untick **Include resolved**                                                  |
| An alert comes back after **Resolve alert**                                  | The check or task is still failing                                                                                               | Fix the cause, or reset the check once it is fixed                                           |
| No alerts at all for a device                                                | It is in maintenance mode                                                                                                        | **Disable Maintenance Mode** in its action menu                                              |

## Field reference

### General Settings

| Field              | What it does                                                         | Default |
| ------------------ | -------------------------------------------------------------------- | ------- |
| Name               | Identifies the template. Required                                    | Empty   |
| Enabled            | The template takes effect where assigned                             | On      |
| Email From address | Sender address for this template's emails, instead of the global one | Empty   |
| Email recipients   | Replace the global email recipients for alerts under this template   | None    |
| SMS recipients     | Replace the global SMS recipients. E.164 format                      | None    |

### Alert Actions

| Field                                                                | What it does                                                                                                                                   | Default                 |
| -------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| Action type (failure and resolved)                                   | **Run script on Agent** runs a library script on the device. **Send a Web Hook** calls a web hook from **Admin Center › Settings › Web Hooks** | **Run script on Agent** |
| Failure script / Resolved Script                                     | Script run when the alert is raised / resolved. Runs once per alert                                                                            | None                    |
| Failure script arguments / Resolved script arguments                 | Arguments for the script. Accept [script variables](https://wiki.datadike.com/sonar/reference/script-variables.md), including alert values     | The script's defaults   |
| Failure script environment vars / Resolved action environment vars   | Environment variables, as `KEY=VALUE`                                                                                                          | The script's defaults   |
| Failure script timeout (seconds) / Resolved script timeout (seconds) | Maximum run time                                                                                                                               | The script's default    |
| Failure Web Hook                                                     | Web hook called when the alert is raised                                                                                                       | None                    |
| Resolved Web Hook                                                    | Web hook called when the alert resolves on its own. Use it together with a **Failure Web Hook**                                                | None                    |
| Run actions only on                                                  | Alert types that run the actions: **Agents** (overdue devices), **Checks**, **Tasks**                                                          | All on                  |

### Agent Overdue Settings, Check Settings, Automated Task Settings

| Field                                             | What it does                                                                                                             | Default                              |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------ |
| Email / Text / Dashboard (Alert Failure Settings) | On: always notify on this channel. Middle (**Not configured**): use the device, check or task setting. Off: never notify | **Not configured**                   |
| Only email on alert severity                      | Checks and tasks. Severities that are emailed                                                                            | **Error** and **Warning** when empty |
| Only text on alert severity                       | Checks and tasks. Severities sent by SMS                                                                                 | **Error** and **Warning** when empty |
| Only show dashboard alert on severity             | Checks and tasks. Severities shown on the dashboard                                                                      | All three when empty                 |
| Alert again if not resolved after (days)          | Resends the email and SMS while the alert stays open. 0 sends once                                                       | 0                                    |
| Email / Text (Alert Resolved Settings)            | Sends a notification when the alert resolves on its own                                                                  | Off                                  |

### Alert Exclusions

| Field                                               | What it does                                        |
| --------------------------------------------------- | --------------------------------------------------- |
| Excluded Clients / Excluded Sites / Excluded Agents | The template does not apply to these devices        |
| Exclude Workstations / Exclude Servers              | The template does not apply to devices of that type |

### Device overdue settings (Edit › General)

| Field                                                                            | What it does                                                                                              |
| -------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| Offline after (minutes)                                                          | Time without contact after which the device is shown as offline. 2 or more                                |
| Overdue after (minutes)                                                          | Time without contact after which the device is overdue and an availability alert can be raised. 3 or more |
| Get overdue email alerts / Get overdue sms alerts / Get overdue dashboard alerts | The device's own channels for availability alerts                                                         |

## Related pages

* [Checks](https://wiki.datadike.com/sonar/administration/automation/checks.md)
* [Automated tasks](https://wiki.datadike.com/sonar/administration/automation/automated-tasks.md)
* [Automation policies](https://wiki.datadike.com/sonar/administration/automation/automation-policies.md)
* [Email and SMS notifications](https://wiki.datadike.com/sonar/administration/settings/email-and-sms.md)
* [Webhooks](https://wiki.datadike.com/sonar/administration/settings/webhooks.md)
