feat: exclusive pilot — spool flush and verify script

Replay spool on each monitor loop; sac_post_payload refactor;
pilot-verify-exclusive.sh and --check-sac hints for exclusive mode.
This commit is contained in:
PTah
2026-05-27 13:25:47 +10:00
parent f1c4adcc13
commit 3a1c9655ca
4 changed files with 119 additions and 27 deletions
+41
View File
@@ -0,0 +1,41 @@
#!/bin/bash
# Проверка готовности хоста к пилоту UseSAC=exclusive (фаза 2.1).
set -euo pipefail
CONFIG="${CONFIG_FILE:-/etc/ssh-monitor.conf}"
MONITOR="${SSH_MONITOR_BIN:-/usr/local/bin/ssh-monitor}"
if [ -f "$CONFIG" ]; then
# shellcheck disable=SC1090
. "$CONFIG"
fi
fail=0
ok() { printf '[OK] %s\n' "$1"; }
bad() { printf '[FAIL] %s\n' "$1"; fail=1; }
mode="$(printf '%s' "${UseSAC:-off}" | tr '[:upper:]' '[:lower:]')"
[ "$mode" = "exclusive" ] || bad "UseSAC должен быть exclusive (сейчас: ${UseSAC:-off})"
[ -n "${SAC_URL:-}" ] && [ -n "${SAC_API_KEY:-}" ] || bad "Задайте SAC_URL и SAC_API_KEY"
[ -x "$MONITOR" ] || bad "Не найден $MONITOR"
[ -f "${MONITOR%/*}/sac-client.sh" ] || bad "Нет sac-client.sh рядом с ssh-monitor"
if "$MONITOR" --check-sac; then
ok "--check-sac"
else
bad "--check-sac"
fi
spool="${SAC_SPOOL_DIR:-/var/lib/ssh-monitor/sac-spool}"
pending=0
if [ -d "$spool" ]; then
pending=$(find "$spool" -maxdepth 1 -name '*.json' 2>/dev/null | wc -l)
fi
printf ' Spool %s: %s файл(ов)\n' "$spool" "$pending"
if [ "$fail" -eq 0 ]; then
printf '\nПилот exclusive: хост готов. Сгенерируйте SSH/sudo событие и проверьте только в SAC UI.\n'
exit 0
fi
printf '\nИсправьте ошибки выше.\n'
exit 1