

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

# API des canaux de notification d'alerte
<a name="v12-Grafana-API-AlertingNotificationChannels"></a>

Utilisez l'API Alerting Notification Channels pour créer, mettre à jour, supprimer et récupérer des canaux de notification.

L'identifiant (id) d'un canal de notification est une valeur numérique à incrémentation automatique et n'est unique que par espace de travail. L'identifiant unique (uid) d'un canal de notification peut être utilisé pour identifier de manière unique un dossier entre plusieurs espaces de travail. Il est généré automatiquement si vous n'en fournissez pas lors de la création d'un canal de notification. L'uid permet d'avoir des URL cohérentes pour accéder aux canaux de notification et lors de la synchronisation des canaux de notification entre plusieurs espaces de travail Amazon Managed Grafana. 

**Note**  
Pour utiliser une API Grafana avec votre espace de travail Amazon Managed Grafana, vous devez disposer d'un jeton de compte de service valide. Vous l'incluez dans le `Authorization` champ de la demande d'API.

## Accédez à tous les canaux de notification
<a name="v12-Grafana-API-AlertNotificationChannels-getall"></a>

Renvoie tous les canaux de notification que l'utilisateur authentifié est autorisé à consulter.

```
GET /api/alert-notifications
```

**Exemple de demande**

```
GET /api/alert-notifications HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**Exemple de réponse**

```
HTTP/1.1 200
Content-Type: application/json

[
  {
    "id": 1,
    "uid": "sns-uid",
    "name": "test",
    "type": "sns",
    "isDefault": false,
    "sendReminder": false,
    "disableResolveMessage": false,
    "frequency": "",
    "created": "2023-09-08T19:57:56Z",
    "updated": "2023-09-08T19:57:56Z",
    "settings": {
      "authProvider": "default",
      "autoResolve": true,
      "httpMethod": "POST",
      "messageFormat": "json",
      "severity": "critical",
      "topic": "<SNS-TOPIC-ARN>",
      "uploadImage": false
    },
    "secureFields": {}
  }
]
```

## Obtenir tous les canaux de notification (recherche)
<a name="v12-Grafana-API-AlertNotificationChannels-getlookup"></a>

Renvoie tous les canaux de notification, mais avec des informations moins détaillées. Accessible par tout utilisateur authentifié, il est principalement utilisé pour fournir des canaux de notification d'alerte dans l'interface utilisateur de la console de l'espace de travail Grafana lors de la configuration des règles d'alerte.

```
GET /api/alert-notifications/lookup
```

**Exemple de demande**

```
GET /api/alert-notifications/lookup HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**Exemple de réponse**

```
HTTP/1.1 200
Content-Type: application/json

[
  {
    "id": 1,
    "uid": "sns-uid",
    "name": "test",
    "type": "sns",
    "isDefault": false
  },
  {
    "id": 2,
    "uid": "slack-uid",
    "name": "Slack",
    "type": "slack",
    "isDefault": false
  }
]
```

## Obtenez tous les canaux de notification par UID
<a name="v12-Grafana-API-AlertNotificationChannels-getbyUID"></a>

```
GET /api/alert-notifications/uid/:uid
```

**Exemple de demande**

```
GET /api/alert-notifications/uid/sns-uid HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**Exemple de réponse**

```
HTTP/1.1 200
Content-Type: application/json

{
  "id": 1,
  "uid": "sns-uid",
  "name": "test",
  "type": "sns",
  "isDefault": false,
  "sendReminder": false,
  "disableResolveMessage": false,
  "frequency": "",
  "created": "2023-09-08T19:57:56Z",
  "updated": "2023-09-08T19:57:56Z",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  },
  "secureFields": {}
}
```

## Obtenez tous les canaux de notification par identifiant
<a name="v12-Grafana-API-AlertNotificationChannels-getbyId"></a>

```
GET /api/alert-notifications/:id
```

**Exemple de demande**

```
GET /api/alert-notifications/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**Exemple de réponse**

```
HTTP/1.1 200
Content-Type: application/json

{
  "id": 1,
  "uid": "sns-uid",
  "name": "test",
  "type": "sns",
  "isDefault": false,
  "sendReminder": false,
  "disableResolveMessage": false,
  "frequency": "",
  "created": "2023-09-08T19:57:56Z",
  "updated": "2023-09-08T19:57:56Z",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  },
  "secureFields": {}
}
```

## Créer un canal de notification
<a name="v12-Grafana-API-AlertNotificationChannels-Create"></a>

Pour savoir quels canaux de notification sont pris en charge par Amazon Managed Grafana, consultez la liste des notificateurs pris en charge dans. [Travailler avec les points de contact](alert-contact-points.md)

Dans la version 12 de Grafana, utilisez l'API Alerting Provisioning pour créer des points de contact. L'ancien `/api/alert-notifications` point de terminaison n'est plus disponible.

**Exemple de demande**

```
POST /api/v1/provisioning/contact-points HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890

{
  "uid": "new-sns-uid",
  "name": "sns alert notification",
  "type": "sns",
  "isDefault": false,
  "sendReminder": false,
  "settings": {
    "topic_arn": "<SNS-TOPIC-ARN>",
    "subject": "<SUBJECT>"
  }
}
```

## Mettre à jour le canal de notification par UID
<a name="v12-Grafana-API-AlertNotificationChannels-UpdatebyUID"></a>

```
PUT /api/alert-notifications/uid/:uid
```

**Exemple de demande**

```
PUT /api/alert-notifications/uid/sns-uid HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890

{
  "uid": "sns-uid", // optional
  "name": "sns alert notification",  //Required
  "type":  "sns", //Required
  "isDefault": false,
  "sendReminder": true,
  "frequency": "15m",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  }
}
```

**Exemple de réponse**

```
HTTP/1.1 200
Content-Type: application/json

{
  "id": 1,
  "uid": "sns-uid",
  "name": "sns alert notification",
  "type": "sns",
  "isDefault": false,
  "sendReminder": true,
  "frequency": "15m",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  },
  "created": "2017-01-01 12:34",
  "updated": "2017-01-01 12:34"
}
```

## Mettre à jour le canal de notification par identifiant
<a name="v12-Grafana-API-AlertNotificationChannels-UpdatebyId"></a>

```
PUT /api/alert-notifications/:id
```

**Exemple de demande**

```
PUT /api/alert-notifications/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890

{
  "id": 1,
  "uid": "sns-uid", // optional
  "name": "sns alert notification",  //Required
  "type":  "sns", //Required
  "isDefault": false,
  "sendReminder": true,
  "frequency": "15m",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  }
}
```

**Exemple de réponse**

```
HTTP/1.1 200
Content-Type: application/json

{
  "id": 1,
  "uid": "sns-uid",
  "name": "sns alert notification",
  "type": "sns",
  "isDefault": false,
  "sendReminder": true,
  "frequency": "15m",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  },
  "created": "2017-01-01 12:34",
  "updated": "2017-01-01 12:34"
}
```

## Supprimer le canal de notification par UID
<a name="v12-Grafana-API-AlertNotificationChannels-DeletebyUID"></a>

```
DELETE /api/alert-notifications/uid/:uid
```

**Exemple de demande**

```
DELETE /api/alert-notifications/uid/sns-uid HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**Exemple de réponse**

```
HTTP/1.1 200
Content-Type: application/json

{
  "message": "Notification deleted"
}
```

## Supprimer le canal de notification par identifiant
<a name="v12-Grafana-API-AlertNotificationChannels-DeletebyId"></a>

```
DELETE /api/alert-notifications/:id
```

**Exemple de demande**

```
DELETE /api/alert-notifications/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890
```

**Exemple de réponse**

```
HTTP/1.1 200
Content-Type: application/json

{
  "message": "Notification deleted"
}
```

## Canal de notification de test
<a name="v12-Grafana-API-AlertNotificationChannels-Test"></a>

Envoie un message de notification de test pour le type de canal de notification et les paramètres spécifiés.

```
POST /api/alert-notifications/test
```

**Exemple de demande**

```
POST /api/alert-notifications/test HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer 1234abcd567exampleToken890

{
  "type":  "sns",
  "settings": {
    "authProvider": "default",
    "autoResolve": true,
    "httpMethod": "POST",
    "messageFormat": "json",
    "severity": "critical",
    "topic": "<SNS-TOPIC-ARN>",
    "uploadImage": false
  }
}
```

**Exemple de réponse**

```
HTTP/1.1 200
Content-Type: application/json

{
  "message": "Test notification sent"
}
```