groups:
  - name: nas_storage
    interval: 120s
    rules:
      - alert: NASPoolDegraded
        expr: nas_pool_healthy == 0
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "NAS pool {{ $labels.pool }} is degraded or faulted"
          description: "Pool {{ $labels.pool }} is not in ONLINE state. Check for failed drives, resilver status, and pool topology. Immediate attention required."

      - alert: NASDiskSMARTWarning
        expr: nas_disk_smart_passed == 0
        for: 1m
        labels:
          severity: critical
        annotations:
          summary: "NAS disk {{ $labels.disk }} SMART test FAILED"
          description: "Disk {{ $labels.disk }} has failed SMART self-test. Disk replacement should be planned."

      - alert: NASDiskWarm
        expr: nas_disk_temperature_celsius > 55 and nas_disk_temperature_celsius <= 60
        for: 10m
        labels:
          severity: medium
        annotations:
          summary: "NAS disk {{ $labels.disk }} temperature > 55C"
          description: "Disk {{ $labels.disk }} at {{ $value }}C for more than 10 minutes. Monitor airflow."

      - alert: NASDiskHot
        expr: nas_disk_temperature_celsius > 60
        for: 10m
        labels:
          severity: critical
        annotations:
          summary: "NAS disk {{ $labels.disk }} temperature > 60C"
          description: "Disk {{ $labels.disk }} at {{ $value }}C for more than 10 minutes. Check chassis airflow and fan operation immediately."

      - alert: NASPoolHighUsage
        expr: nas_pool_usage_ratio > 0.80
        for: 10m
        labels:
          severity: high
        annotations:
          summary: "NAS pool {{ $labels.pool }} usage > 80%"
          description: "Pool {{ $labels.pool }} at {{ $value | humanizePercentage }} capacity. ZFS performance degrades significantly above 80%. Plan capacity expansion or data cleanup."

      - alert: NASPoolScrubErrors
        expr: >
          nas_pool_last_scrub_errors > 0
          and (time() - nas_pool_last_scrub_timestamp) < 7200
        for: 5m
        labels:
          severity: high
        annotations:
          summary: "NAS pool {{ $labels.pool }} recent scrub found {{ $value }} errors"
          description: "A scrub completed within the last 2 hours on pool {{ $labels.pool }} and detected errors. Investigate data integrity and disk health."

  - name: pbs_storage
    interval: 120s
    rules:
      - alert: PBSDatastoreHigh
        expr: pbs_datastore_usage_ratio > 0.85
        for: 10m
        labels:
          severity: high
        annotations:
          summary: "PBS datastore {{ $labels.datastore }} usage > 85%"
          description: "Datastore {{ $labels.datastore }} at {{ $value | humanizePercentage }}. Run garbage collection or adjust pruning schedule."

      - alert: PBSDatastoreSpecialVDEVHigh
        expr: pbs_datastore_usage_ratio > 0.70 and pbs_datastore_usage_ratio <= 0.85
        for: 30m
        labels:
          severity: medium
        annotations:
          summary: "PBS datastore {{ $labels.datastore }} usage > 70% (special VDEV threshold)"
          description: "Datastore {{ $labels.datastore }} at {{ $value | humanizePercentage }}. If using special VDEV, this is the early warning threshold. Monitor closely and plan GC or pruning."
