# Grafana Webhooks Integration

Integrate Grafana alert rules and contact points with OnCallAlert. When alert conditions trigger, Grafana sends alert state, metric annotations, labels, and dashboard panel snapshots into OnCallAlert. When metrics recover, Grafana sends a resolved event that automatically resolves the incident.

## Step 1: Create a Grafana Integration Key in OnCallAlert

1. In the OnCallAlert web interface, navigate to **Services** and select your service.
2. Select **Integration Keys** &rarr; **Create Integration Key**.
3. Choose **Grafana** as the integration key type and name it (e.g., `Grafana Production`).
4. Copy the webhook URL:
   ```text
   https://oncall.yourcompany.com/api/v2/grafana/incoming?token=<INTEGRATION_KEY>
   ```

## Step 2: Configure Grafana Contact Point

### Grafana 8, 9, 10, and Newer

1. In Grafana, open the side navigation and go to **Alerting &rarr; Contact points**.
2. Click **New contact point**.
3. Set **Name** to `OnCallAlert`.
4. Under **Contact point type**, select **Webhook**.
5. Paste your OnCallAlert webhook URL into the **Url** field.
6. Set the HTTP method to `POST`.
7. Click **Test** &rarr; **Send test notification** to dispatch a test alert and verify receipt in OnCallAlert.
8. Click **Save contact point**.

### Grafana 7 (Legacy Alerting)

1. Navigate to **Alerting &rarr; Notification channels**.
2. Click **Add Channel**.
3. Enter `OnCallAlert` as the name, select type `Webhook`, and paste the webhook URL.
4. Enable **Send on am-resolved** if you want resolved events to close alerts automatically.
5. Save the notification channel.

## Step 3: Link Alert Rules to the Contact Point

1. In Grafana **Alerting &rarr; Notification policies**, set `OnCallAlert` as the default root policy or create specific routing policies matching labels (e.g. `severity = critical`).
2. When rules trigger, OnCallAlert parses the multi-alert payload, displays labels and annotations in a markdown table, and provides links to the originating dashboard panel and silence URL.
