#!/bin/bash
# Weekly Vault space report — top consumers + fill %, over SSH (read-only).
set -uo pipefail
source "$(dirname "$0")/_lib.sh"
NAME=vault-report
is_disabled "$NAME" && { write_status "$NAME" "Vault space report" "weekly Sun 09:00" scheduled 1 "disabled"; exit 0; }
SSH="ssh -o BatchMode=yes -o ConnectTimeout=10 -i $HOME/.ssh/ahel_control admin@192.168.8.193"

USEPCT=$($SSH "df -h /volume1 2>/dev/null | tail -1 | awk '{print \$5}'") || {
  notify "Vault report" "Ahel Vault unreachable"; write_status "$NAME" "Vault space report" "weekly Sun 09:00" scheduled 0 "Vault unreachable"; exit 1; }
TOP=$($SSH "du -sh /volume1/*/ 2>/dev/null | sort -rh | head -8" 2>/dev/null)

BODY="Ahel Vault ${USEPCT} full.
Top folders:
${TOP}"
notify "💾 Vault weekly report" "$BODY"
write_status "$NAME" "Vault space report" "weekly Sun 09:00" scheduled 1 "Vault ${USEPCT} full"
