Files

19 lines
535 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
AUD=/srv/prime-core/logs/audit.jsonl
[[ -f "$AUD" ]] || exit 0
NOW=$(date +%s)
WINDOW=900
START=$((NOW-WINDOW))
COUNT=$(awk -v s="$START" 'BEGIN{c=0} {if (match($0,/"ts":([0-9]+)/,m)) if (m[1]>=s) c++} END{print c}' "$AUD")
# crude anomaly: too many commands/events in 15m
if [[ "$COUNT" -gt 300 ]]; then
source /srv/prime-core/scripts/prime-env.sh
python3 - <<'PY'
from prime_core.notify import send_telegram
send_telegram('⚠️ Prime audit anomaly: high event volume in last 15m')
PY
fi