> For the complete documentation index, see [llms.txt](https://docs.spyderbat.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.spyderbat.com/tutorials/notifications/how-to-set-up-agent-health-notifications-in-spyctl.md).

# How to Set up Agent-Health Notifications Using Spyctl

## Overview

The **`spyctl create agent-health-notification-settings`** command in Spyctl allows you to configure notifications for agent health events. This helps you stay informed about the status (Unhealthy, Offline, Online, Healthy) of agents in your environment.

## Prerequisites

Before configuring agent health notifications, ensure you have:

* Install Spyctl ([Installation Guide](/installation/spyctl.md))
* Configure Spyctl with a context ([Spyctl Initial Configuration](/installation/spyctl/spyctl-initial-configuration.md))
* Spyderbat Notifications [Spyderbat Notifications Overview](/concepts/notifications.md)
* What are Notification Targets? ([Notification Targets Management](/reference/spyctl/notification-targets-management-spyctl.md))

***

## Step-by-Step Guide

### Step 1: Identify Notification Targets

Before setting up agent health notifications, ensure you have configured notification targets. These can include:

* Email
* Slack Channel
* Webhook
* PagerDuty

***

### Step 2: Create an Agent Health Notification Setting

Use the below command to create a new notification setting. Once configured, agent health alerts are received in real-time on the chosen targets.

#### Available Options

```
spyctl create  agent-health-notification-settings -h
```

| Option                   | Description                                                                           |
| ------------------------ | ------------------------------------------------------------------------------------- |
| `-a, --apply`            | Apply the agent health notification settings during creation.                         |
| `-n, --name`             | Custom name for the agent health notification settings. **(Required)**                |
| `-d, --description`      | Description of the agent health notification settings.                                |
| `-q, --scope-query TEXT` | SpyQL query on `model_agents` table to determine which agents the setting applies to. |
| `-T, --targets`          | Comma-separated list of notification targets.                                         |
| `--is-disabled`          | Disable the agent health notification settings on creation.                           |
| \`-o, --output \[yaml    | json                                                                                  |
| `-y, --yes`              | Automatically answer yes to all prompts.                                              |

**Creating a agent-health-notification-settings**

```sh
spyctl create agent-health-notification-settings \
  --name "Agent Health Alerts" \
  --description "Alerts for agent health issues" \
  --targets "work-email"
```

This command creates an agent health notification setting named **Agent Health Alerts**, which triggers notifications for unhealthy agents and sends them to the specified targets.

***

### Step 3: Edit an Existing Notification Setting

To modify an existing agent health notification setting, use:

```sh
spyctl edit agent-health-notification-settings <NAME_OR_UID>
```

For example:

```sh
spyctl edit agent-health-notification-settings "Agent-Health Alerts"
```

***

### Step 4: List All Existing Notification Settings

To view all configured agent health notification settings, run:

```sh
spyctl get agent-health-notification-settings
```

To get a particular `agent-health-notification-settings` use \<NAME\_OR\_UID>

```sh
spyctl get agent-health-notification-settings -o json
```

***

### Step 5: Delete an Agent Health Notification Setting

To stop receiving agent health notification, use:

```sh
spyctl delete agent-health-notification-settings <NAME_OR_UID>
```

For example:

```sh
spyctl delete agent-health-notification-settings "Agent Health-Alerts"
```
