Aggiunge monitoraggio ops: health check, log scanner, dashboard e notifiche.
Introduce incidenti con dedup, job Sidekiq ogni 3 min, scan log cron, /up/deep, dashboard /admin/ops e push ntfy; include Sentry opzionale e fix test suite. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
18
infra/scripts/cron/scan_ops_logs.sh
Normal file
18
infra/scripts/cron/scan_ops_logs.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
# Scansiona log Docker recenti e invia pattern sospetti a Rails ops:ingest_logs.
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="${MATCHLIVETV_INFRA:-/opt/matchlivetv/infra}"
|
||||
SINCE="${OPS_LOG_SCAN_SINCE:-10m}"
|
||||
TMP="$(mktemp)"
|
||||
trap 'rm -f "$TMP"' EXIT
|
||||
|
||||
cd "$ROOT"
|
||||
|
||||
docker compose -f docker-compose.prod.yml logs --since "$SINCE" rails sidekiq mediamtx 2>/dev/null > "$TMP" || true
|
||||
|
||||
if [[ ! -s "$TMP" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
"${ROOT}/scripts/cron/run_rails_task.sh" ops:ingest_logs["$TMP"]
|
||||
@@ -4,10 +4,12 @@ set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
RUNNER="${ROOT}/scripts/cron/run_rails_task.sh"
|
||||
SCAN_LOGS="${ROOT}/scripts/cron/scan_ops_logs.sh"
|
||||
LOG_DIR="${MATCHLIVETV_LOG_DIR:-/opt/matchlivetv/log}"
|
||||
LOG_FILE="${LOG_DIR}/cron-replay.log"
|
||||
OPS_LOG_FILE="${LOG_DIR}/cron-ops.log"
|
||||
|
||||
chmod +x "$RUNNER"
|
||||
chmod +x "$RUNNER" "$SCAN_LOGS"
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
MARKER="# matchlivetv-replay-cron"
|
||||
@@ -15,22 +17,18 @@ CRON_BLOCK="${MARKER}
|
||||
30 * * * * ${RUNNER} recordings:cleanup_local >> ${LOG_FILE} 2>&1
|
||||
0 3 * * * ${RUNNER} recordings:purge_expired >> ${LOG_FILE} 2>&1
|
||||
0 8 * * * ${RUNNER} recordings:expiry_warnings >> ${LOG_FILE} 2>&1
|
||||
*/10 * * * * ${SCAN_LOGS} >> ${OPS_LOG_FILE} 2>&1
|
||||
"
|
||||
|
||||
existing="$(crontab -l 2>/dev/null || true)"
|
||||
filtered="$(echo "$existing" | grep -v "$MARKER" | grep -v 'run_rails_task\.sh' || true)"
|
||||
if echo "$existing" | grep -q "$MARKER"; then
|
||||
echo "Crontab replay già presente, aggiorno..."
|
||||
echo "$existing" | awk -v block="$CRON_BLOCK" '
|
||||
BEGIN { skip=0 }
|
||||
/# matchlivetv-replay-cron/ { skip=1; next }
|
||||
skip && /^[^#]/ && $0 !~ /^$/ { skip=0 }
|
||||
skip { next }
|
||||
{ print }
|
||||
END { print block }
|
||||
' | crontab -
|
||||
else
|
||||
(echo "$existing"; echo "$CRON_BLOCK") | crontab -
|
||||
fi
|
||||
{
|
||||
[ -n "$filtered" ] && echo "$filtered"
|
||||
echo "$CRON_BLOCK"
|
||||
} | sed '/^$/d' | crontab -
|
||||
|
||||
echo "Crontab installato:"
|
||||
crontab -l | grep -A3 "$MARKER"
|
||||
|
||||
Reference in New Issue
Block a user