# 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"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.spyderbat.com/tutorials/notifications/how-to-set-up-agent-health-notifications-in-spyctl.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
