# Alerting

*For more details, please refer to the Alerting feature.*

{% content-ref url="../../../features/key-features/alerting" %}
[alerting](https://docs.datasentinel.io/manual/features/key-features/alerting)
{% endcontent-ref %}

To use the Alerting API, it's necessary to generate an access token.

{% content-ref url="access-token" %}
[access-token](https://docs.datasentinel.io/manual/implementation/platform-usage/api-reference/access-token)
{% endcontent-ref %}

{% hint style="info" %}
A comprehensive toolkit, with practical usage examples, is accessible on [GitHub](https://github.com/datasentinel/datasentinel_toolkit).

This  toolkit comes pre-installed as a default component within the on-premises platform, located at `/datasentinel/soft/datasentinel_toolkit`.
{% endhint %}

## Instance Alerting

## Status

<mark style="color:blue;">`GET`</mark> `https://<<platform-server>>/ds-api/alerting/{pg-instance}/status`

Display Instance Alerting Status

#### Path Parameters

| Name                                          | Type   | Description                                                        |
| --------------------------------------------- | ------ | ------------------------------------------------------------------ |
| pg-instance<mark style="color:red;">\*</mark> | String | Instance name in Datasentinel: **<\<server\_name>>@<\<pg\_name>>** |

#### Headers

| Name                                         | Type   | Description            |
| -------------------------------------------- | ------ | ---------------------- |
| user-token<mark style="color:red;">\*</mark> | String | Generated Access Token |

**Response**

{% tabs %}
{% tab title="200: OK " %}
{% code title="Example" %}

```json
{
    "enabled": true,
    "reason": ""
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}

{% tab title="500: Internal Server Error Internal error" %}

{% endtab %}
{% endtabs %}

```json
// If not enabled, the reason is displayed
{
    "enabled": false,
    "reason": "The reason why the alerting is disabled"
}
```

If instance alerting is inactive, the reason field clarifies the cause. Several possibilities exist:

* Global alerting is turned **off** on the Datasentinel platform.
* An instance-specific silence is in effect.
* A silence is active, covering the instance through its filters.
* No corresponding alerting rule has been identified.

## Enable

<mark style="color:purple;">`PATCH`</mark> `https://<<platform-server>>/ds-api/alerting/{pg-instance}/enable`

Enable Instance Alerting

#### Path Parameters

| Name                                          | Type   | Description                                                        |
| --------------------------------------------- | ------ | ------------------------------------------------------------------ |
| pg-instance<mark style="color:red;">\*</mark> | String | Instance name in Datasentinel: **<\<server\_name>>@<\<pg\_name>>** |

#### Headers

| Name                                         | Type   | Description            |
| -------------------------------------------- | ------ | ---------------------- |
| user-token<mark style="color:red;">\*</mark> | String | Generated Access Token |

**Response**

{% tabs %}
{% tab title="200: OK " %}
{% code title="Example" %}

```json
{
    "enabled": true,
    "reason": ""
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}

{% tab title="500: Internal Server Error Internal error" %}

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Enabling instance alerting might not yield any impact under specific conditions.
{% endhint %}

Several reasons could contribute to this:

* Global alerting is turned **off** on the Datasentinel platform.
* A silence is active, covering the instance through its filters.
* No corresponding alerting rule has been identified.

## Disable

<mark style="color:purple;">`PATCH`</mark> `https://<<platform-server>>/ds-api/alerting/{pg-instance}/disable`

Disable Instance Alerting

#### Path Parameters

| Name                                          | Type   | Description                                                        |
| --------------------------------------------- | ------ | ------------------------------------------------------------------ |
| pg-instance<mark style="color:red;">\*</mark> | String | Instance name in Datasentinel: **<\<server\_name>>@<\<pg\_name>>** |

#### Headers

| Name                                         | Type   | Description            |
| -------------------------------------------- | ------ | ---------------------- |
| user-token<mark style="color:red;">\*</mark> | String | Generated Access Token |

**Response**

{% tabs %}
{% tab title="200: OK " %}

```json
{
    "enabled": false,
    "reason": "A silence has been created for the instance"
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}

{% tab title="500: Internal Server Error Internal error" %}

{% endtab %}
{% endtabs %}

## Problems

<mark style="color:blue;">`GET`</mark> `https://<<platform-server>>/ds-api/alerting/{pg-instance}/problems`

Display Instance Problems

#### Path Parameters

| Name                                          | Type   | Description                                                        |
| --------------------------------------------- | ------ | ------------------------------------------------------------------ |
| pg-instance<mark style="color:red;">\*</mark> | String | Instance name in Datasentinel: **<\<server\_name>>@<\<pg\_name>>** |

#### Headers

| Name                                         | Type   | Description            |
| -------------------------------------------- | ------ | ---------------------- |
| user-token<mark style="color:red;">\*</mark> | String | Generated Access Token |

**Response**

{% tabs %}
{% tab title="200: OK " %}
{% code title="Example" %}

```json
[
    {
        "id": "6d2f5754994556408ecdebc8587c1ccc",
        "event_time": "2022-10-04 16:19:08",
        "notification_type": "PROBLEM",
        "pg_instance": "server@crm-production",
        "check_name": "wal_files",
        "check_state": "WARNING",
        "message": "WAL files: 43 [>=40 - WARNING]",
        "email": true,
        "webhook": false,
        "script": false,
        "start_time": "2022-10-04 16:10:08",
        "server": "server"
    },
    {
        "id": "832c4eb26dd29450259290432194ff81",
        "event_time": "2022-10-04 12:21:10",
        "notification_type": "PROBLEM",
        "pg_instance": "server@crm-production",
        "check_name": "memory_usage",
        "check_state": "CRITICAL",
        "message": "Memory usage: 95% used (1730MB/1835MB) [>=95% - CRITICAL]",
        "email": true,
        "webhook": false,
        "script": false,
        "start_time": "2022-10-04 12:04:06",
        "server": "server"
    },
    {
        "id": "e644076a863f25fc66a0cae682b1b629",
        "event_time": "2022-10-05 10:19:27",
        "notification_type": "PROBLEM",
        "pg_instance": "server@crm-production",
        "check_name": "custom",
        "check_state": "CRITICAL",
        "message": "Custom alert: Daily backup failed : No disk space",
        "email": true,
        "webhook": false,
        "script": false,
        "start_time": "2022-10-05 10:19:27",
        "server": "server"
    },
.../...
]
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}

{% tab title="500: Internal Server Error Internal error" %}

{% endtab %}
{% endtabs %}

## Customized Alerts

## Create

<mark style="color:green;">`POST`</mark> `https://<<platform-server>>/ds-api/alerting/{pg-instance}/problems`

Create Custom Instance Problem

#### Path Parameters

| Name                                          | Type   | Description                                                        |
| --------------------------------------------- | ------ | ------------------------------------------------------------------ |
| pg-instance<mark style="color:red;">\*</mark> | String | Instance name in Datasentinel: **<\<server\_name>>@<\<pg\_name>>** |

#### Headers

| Name                                         | Type   | Description            |
| -------------------------------------------- | ------ | ---------------------- |
| user-token<mark style="color:red;">\*</mark> | String | Generated Access Token |

**Response**

{% tabs %}
{% tab title="201: Created " %}
{% code title="Example" %}

```json
{
    "id": "e644076a863f25fc66a0cae682b1b629",
    "event_time": "2022-10-05 10:19:27",
    "notification_type": "PROBLEM",
    "pg_instance": "server@crm-production",
    "check_name": "custom",
    "check_state": "CRITICAL",
    "message": "Custom alert: Daily backup failed : No disk space",
    "email": true,
    "webhook": false,
    "script": false,
    "start_time": "2022-10-05 10:19:27",
    "server": "server"
}
```

{% endcode %}
{% endtab %}

{% tab title="401: Unauthorized " %}

{% endtab %}

{% tab title="404: Not Found " %}

{% endtab %}

{% tab title="500: Internal Server Error Internal error" %}

{% endtab %}
{% endtabs %}

{% code title="Example" %}

```bash
cat > body.json << EOF
{
    "message" : "Daily backup failed : No disk space"
}
EOF
export TOKEN=<<user_token>>
curl -k --header "user-token: $TOKEN" --header 'Content-Type: application/json' --request POST 'https://<<platform-server>>/ds-api/alerting/<<pg-instance>>/problems' -d @body.json

```

{% endcode %}
