ids.alfacom.it/deployment/run_cleanup.sh
marco370 791b7caa4d Add automatic cleanup for old detections and IP blocks
Implement automated detection cleanup after 48 hours and IP unblocking after 2 hours using systemd timers and Python scripts.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: 3809a8a0-8dd5-4b5a-9e32-9e075dab335e
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/L6QSDnx
2025-11-25 10:40:44 +00:00

49 lines
1.3 KiB
Bash

#!/bin/bash
# =========================================================
# IDS - Cleanup Detections Runner
# =========================================================
# Esegue cleanup automatico delle detections secondo regole:
# - Cancella detections non anomale dopo 48h
# - Sblocca IP bloccati se non più anomali dopo 2h
#
# Uso: ./run_cleanup.sh
# =========================================================
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# Carica variabili ambiente
if [ -f "$PROJECT_ROOT/.env" ]; then
set -a
source "$PROJECT_ROOT/.env"
set +a
else
echo "❌ File .env non trovato in $PROJECT_ROOT"
exit 1
fi
# Log
LOG_FILE="/var/log/ids/cleanup.log"
mkdir -p /var/log/ids
echo "=========================================" >> "$LOG_FILE"
echo "[$(date)] Cleanup automatico avviato" >> "$LOG_FILE"
echo "=========================================" >> "$LOG_FILE"
# Esegui cleanup
cd "$PROJECT_ROOT"
python3 python_ml/cleanup_detections.py >> "$LOG_FILE" 2>&1
EXIT_CODE=$?
if [ $EXIT_CODE -eq 0 ]; then
echo "[$(date)] Cleanup completato con successo" >> "$LOG_FILE"
else
echo "[$(date)] Cleanup fallito (exit code: $EXIT_CODE)" >> "$LOG_FILE"
fi
echo "" >> "$LOG_FILE"
exit $EXIT_CODE