---
# Alertmanager configuration for Home Monitoring Suite.
# Routes firing alerts to the AI investigator webhook.

global:
  resolve_timeout: 5m

route:
  receiver: ai-investigator
  group_by: [alertname, severity]
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h

  routes:
    # Info-severity alerts — log only, no notification (not actionable)
    - matchers:
        - severity="info"
      receiver: blackhole
      continue: false

    # Media workload alerts — expected during Plex/Tdarr processing, daily repeat
    - matchers:
        - media_workload="true"
      receiver: ai-investigator
      group_wait: 60s
      group_interval: 30m
      repeat_interval: 24h

    # High and critical alerts get shorter group_wait
    - matchers:
        - severity="critical"
      receiver: ai-investigator
      group_wait: 15s
      repeat_interval: 6h

    - matchers:
        - severity="high"
      receiver: ai-investigator
      group_wait: 20s
      repeat_interval: 8h

receivers:
  - name: blackhole
    # Intentionally empty — silently drops info-severity alerts

  - name: ai-investigator
    webhook_configs:
      - url: "http://host.docker.internal:8099/webhook/alertmanager"
        send_resolved: true
        max_alerts: 10
        # Webhook authentication: The investigator checks X-Webhook-Secret
        # header if HM_AI_WEBHOOK_SECRET is set. Alertmanager v0.31.x does
        # not support http_config.headers — upgrade to v0.28+ with the
        # headers field, or leave HM_AI_WEBHOOK_SECRET empty to disable.

# Inhibition rules — suppress downstream alerts when root cause fires
inhibit_rules:
  # PVE node down suppresses all guest/Docker alerts on the same node
  - source_matchers:
      - alertname="PVENodeDown"
    target_matchers:
      - alertname=~"PVEGuest.*|DockerContainer.*|DockerHost.*"
    equal: [node]

  # Cluster not quorate suppresses individual node down alerts
  - source_matchers:
      - alertname="PVEClusterNotQuorate"
    target_matchers:
      - alertname="PVENodeDown"

  # Media host memory high suppresses individual media container memory alerts
  # (root cause is host-level, container alerts are redundant)
  - source_matchers:
      - alertname="DockerMediaHostMemoryHigh"
    target_matchers:
      - alertname="DockerMediaContainerHighMemory"

  # Crontab completely empty suppresses individual entry alerts
  - source_matchers:
      - alertname="CronAllEntriesMissing"
    target_matchers:
      - alertname="CronEntryMissing"
    equal: [host]
