# Prometheus Alertmanager Integration

Connect Prometheus Alertmanager to OnCallAlert to trigger and resolve incidents directly from Prometheus alert rules.

## Step 1: Create a Prometheus Integration Key

1. In OnCallAlert, navigate to the target service.
2. Click **Integration Keys &rarr; Create Integration Key**.
3. Select **Prometheus Alertmanager** and provide a label.
4. Copy the webhook URL:
   ```text
   https://oncall.yourcompany.com/api/v2/prometheusalertmanager/incoming?token=<INTEGRATION_KEY>
   ```

## Step 2: Update alertmanager.yml

Add a webhook receiver and route in your Prometheus Alertmanager configuration file (`alertmanager.yml`):

```yaml
global:
  resolve_timeout: 5m

route:
  group_by: ['alertname', 'cluster', 'service']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h
  receiver: 'oncallalert'

receivers:
  - name: 'oncallalert'
    webhook_configs:
      - url: 'https://oncall.yourcompany.com/api/v2/prometheusalertmanager/incoming?token=YOUR_INTEGRATION_KEY'
        send_resolved: true
```

Set `send_resolved: true` so Alertmanager notifies OnCallAlert when the alert condition clears.

## Step 3: Reload Alertmanager

Reload Alertmanager configuration:

```bash
curl -X POST http://alertmanager:9093/-/reload
```

## Alert Processing & Deduplication

- **Deduplication**: OnCallAlert computes a deduplication key using the Alertmanager alert fingerprint and generator URL. Multiple firings update the active incident rather than creating duplicate notifications.
- **Auto-Resolution**: When Alertmanager sends `status: "resolved"`, OnCallAlert closes the incident and records the resolution in the alert activity log.
