# Notification Target Management using Spyctl

To learn more about what Notification Targets are, see:

{% content-ref url="/pages/w6sePv65ceOqTJ6cNyQW" %}
[Notification Targets](/concepts/notifications/notification-targets.md)
{% endcontent-ref %}

## Prerequisites

If you have never used Spyctl start [here](/installation/spyctl.md) to learn how to install it, then follow the [Initial Configuration](/installation/spyctl.md) guide.

## Managing Notification Targets

### Create

To create a new Notification Target you can use the `create` command:

{% hint style="info" %}
Note: This will only create a local yaml file for you to edit. It makes no immediate changes to your Spyderbat environment.
{% endhint %}

```bash
spyctl create notification-target -n NAME -T TYPE
```

For example:

```
spyctl create notification-target -n OperationsTeam -T emails > target.yaml
```

This will create a default Notification Target and save it to a file called `target.yaml`

{% code title="target.yaml" %}

```yaml
apiVersion: spyderbat/v1
kind: NotificationTarget
metadata:
  name: OperationsTeam
spec:
  emails:
  - example@example.com
```

{% endcode %}

### Edit

When creating new Notification Targets you will need to edit the default document to point to the proper destination. With spyctl you can use the `edit` command to ensure you don't accidentally introduce syntax errors.

```bash
spyctl edit -f FILENAME
```

If you have already [applied ](#apply)the Notification Target you may edit the resource using the following:

```bash
spyctl edit [OPTIONS] notification-target NAME_OR_UID
```

For example:

```bash
spyctl edit -f target.yaml
```

This will bring up a prompt to select a text editor unless you have already done so previously. Then, using your text editor you may fill in your desired destination or destinations.

If you save without making any changes, nothing happens to the resource or file you're editing. If you save and there were syntax errors, Spyctl will save your draft to a temporary location and re-open it with comments detailing the errors. Finally, if your changes have no syntax errors, Spyctl will update the resource or file you're editing.

{% hint style="info" %}
Note: If you edit a Notification Target in a local file, but the Target has already been [applied](#apply). You will need to apply the file again for the updates to take effect.
{% endhint %}

### Apply

In order for a Notification Target to be usable by the Spyderbat Notifications System you must first apply it using the `apply` command.

```bash
spyctl apply -f FILENAME
```

For example:

```sh
spyctl apply -f target.yaml
```

If the operation is successful, your Notification Target will be ready for use.

### Delete

To remove a Notification Target from the Spyderbat Notifications System you can use the `delete` command.

```bash
spyctl delete [OPTIONS] notification-target NAME_OR_UID
```

For example:

```bash
spyctl delete notification-target OperationsTeam
```

### View or Download

You can use the `get` command to view or download your Notification Targets.

```sh
spyctl get [OPTIONS] notification-targets [NAME_OR_UID]
```

For example:

<pre class="language-bash"><code class="lang-bash"><strong>spyctl get notification-targets
</strong></code></pre>

{% code fullWidth="false" %}

```sh
$ spyctl get notification-targets
Getting notification-targets
NAME              ID                                  AGE    TYPE      DESTINATIONS
OperationsTeam    notif_tgt:XXXXXXXXXXXXXXXXXXXXXX    7d     emails               1
```

{% endcode %}

The default output is a tabular summary of your Notification Targets. To download the Notification Target as yaml or json you can use the `-o` option

<pre class="language-bash"><code class="lang-bash"><strong>spyctl get notification-targets -o yaml OperationsTeam
</strong></code></pre>

{% code fullWidth="false" %}

```
$ spyctl get notification-targets -o yaml OperationsTeam
apiVersion: spyderbat/v1
kind: NotificationTarget
metadata:
  name: OperationsTeam
spec:
  emails:
  - engineer1@example.com
  - engineer2@example.com
```

{% endcode %}

Using the `>` character you can save the document to a file.

<pre class="language-bash"><code class="lang-bash"><strong>spyctl get notification-targets -o yaml OperationsTeam > target.yaml
</strong></code></pre>


---

# 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/reference/spyctl/notification-targets-management-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.
