global:
  resolve_timeout: 5m
  # SMTP configuration for email alerts
  # Using MailHog for development - update for production:
  #   smtp_smarthost: 'smtp.example.com:587'
  #   smtp_auth_username: 'alerts@example.com'
  #   smtp_auth_password: 'your-password'
  #   smtp_require_tls: true
  smtp_from: 'alerts@changemaker.local'
  smtp_smarthost: 'mailhog-changemaker:1025'
  smtp_auth_username: ''
  smtp_auth_password: ''
  smtp_require_tls: false

# Templates for notification content
templates:
  - '/etc/alertmanager/*.tmpl'

# Route alerts to appropriate receivers based on severity
route:
  group_by: ['alertname', 'cluster', 'service']
  group_wait: 10s
  group_interval: 10s
  repeat_interval: 12h
  receiver: 'default'

  routes:
    # Critical alerts go to both Gotify and email
    - match:
        severity: critical
      receiver: 'critical-alerts'
      group_wait: 0s
      group_interval: 5m
      repeat_interval: 4h

    # Warning alerts go to Gotify + email
    - match:
        severity: warning
      receiver: 'warning-alerts'
      group_wait: 30s
      repeat_interval: 12h

    # Info alerts - Gotify with lower priority
    - match:
        severity: info
      receiver: 'info-alerts'
      repeat_interval: 24h

# Alert receivers
receivers:
  # Default receiver (catches all unmatched)
  - name: 'default'
    email_configs:
      - to: 'admin@changemaker.local'
        headers:
          Subject: '[Changemaker] {{ .GroupLabels.alertname }}'

  # Critical alerts - email + Gotify push
  - name: 'critical-alerts'
    email_configs:
      - to: 'admin@changemaker.local'
        headers:
          Subject: 'CRITICAL Alert: {{ .GroupLabels.alertname }}'
        html: |
          <h2 style="color: #d32f2f;">Critical Alert Triggered</h2>
          {{ range .Alerts }}
          <p><strong>Alert:</strong> {{ .Labels.alertname }}</p>
          <p><strong>Severity:</strong> {{ .Labels.severity }}</p>
          <p><strong>Summary:</strong> {{ .Annotations.summary }}</p>
          <p><strong>Description:</strong> {{ .Annotations.description }}</p>
          <p><strong>Started:</strong> {{ .StartsAt }}</p>
          <hr>
          {{ end }}
    # Gotify push notifications (configure GOTIFY_APP_TOKEN in .env)
    # Uncomment and set the token to enable:
    # webhook_configs:
    #   - url: 'http://gotify-changemaker:80/message?token=YOUR_GOTIFY_APP_TOKEN'
    #     send_resolved: true
    #     http_config:
    #       follow_redirects: true

  # Warning alerts - email + optional Gotify
  - name: 'warning-alerts'
    email_configs:
      - to: 'admin@changemaker.local'
        headers:
          Subject: 'Warning: {{ .GroupLabels.alertname }}'
    # webhook_configs:
    #   - url: 'http://gotify-changemaker:80/message?token=YOUR_GOTIFY_APP_TOKEN'

  # Info alerts - email only
  - name: 'info-alerts'
    email_configs:
      - to: 'admin@changemaker.local'
        headers:
          Subject: 'Info: {{ .GroupLabels.alertname }}'

# Inhibition rules (prevent spam)
inhibit_rules:
  # If a critical alert is firing, suppress related warnings
  - source_match:
      severity: 'critical'
    target_match:
      severity: 'warning'
    equal: ['alertname', 'instance']

  # If disk is critical, suppress disk warning
  - source_match:
      alertname: 'DiskSpaceCritical'
    target_match:
      alertname: 'DiskSpaceLow'
    equal: ['instance']
