# =============================================================================
# Alertmanager Configuration for RE Workflow
# =============================================================================

global:
  # Global configuration options
  resolve_timeout: 5m

# Route configuration
route:
  # Default receiver
  receiver: 'default-receiver'
  
  # Group alerts by these labels
  group_by: ['alertname', 'service', 'severity']
  
  # Wait before sending grouped notifications
  group_wait: 30s
  
  # Interval for sending updates for a group
  group_interval: 5m
  
  # Interval for resending notifications
  repeat_interval: 4h

  # Child routes for specific routing
  routes:
    # Critical alerts - immediate notification
    - match:
        severity: critical
      receiver: 'critical-receiver'
      group_wait: 10s
      repeat_interval: 1h

    # Warning alerts
    - match:
        severity: warning
      receiver: 'warning-receiver'
      group_wait: 1m
      repeat_interval: 4h

# Receivers configuration
receivers:
  # Default receiver (logs to console)
  - name: 'default-receiver'
    # Webhook receiver for testing
    webhook_configs:
      - url: 'http://localhost:5000/api/webhooks/alerts'
        send_resolved: true

  # Critical alerts receiver
  - name: 'critical-receiver'
    # Configure email notifications
    # email_configs:
    #   - to: 'devops@royalenfield.com'
    #     from: 'alerts@royalenfield.com'
    #     smarthost: 'smtp.gmail.com:587'
    #     auth_username: 'alerts@royalenfield.com'
    #     auth_password: 'your-app-password'
    #     send_resolved: true
    
    # Slack notifications (uncomment and configure)
    # slack_configs:
    #   - api_url: 'https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK'
    #     channel: '#alerts-critical'
    #     send_resolved: true
    #     title: '{{ .Status | toUpper }}: {{ .CommonAnnotations.summary }}'
    #     text: '{{ .CommonAnnotations.description }}'

    webhook_configs:
      - url: 'http://host.docker.internal:5000/api/webhooks/alerts'
        send_resolved: true

  # Warning alerts receiver
  - name: 'warning-receiver'
    webhook_configs:
      - url: 'http://host.docker.internal:5000/api/webhooks/alerts'
        send_resolved: true

# Inhibition rules - prevent duplicate alerts
inhibit_rules:
  # If critical alert fires, inhibit warning alerts for same alertname
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname', 'service']

