#!/bin/bash
# =========================================================
# CRON DETECTION - Rilevamento anomalie automatico
# =========================================================

LOG_FILE="/var/log/ids/detect.log"
mkdir -p /var/log/ids

echo "=========================================" >> "$LOG_FILE"
echo "[$(date)] Detection automatica avviata" >> "$LOG_FILE"
echo "=========================================" >> "$LOG_FILE"

curl -X POST http://localhost:8000/detect \
  -H "Content-Type: application/json" \
  -d '{"max_records": 50000, "hours_back": 1, "risk_threshold": 75, "auto_block": true}' \
  --max-time 120 >> "$LOG_FILE" 2>&1

EXIT_CODE=$?

if [ $EXIT_CODE -eq 0 ]; then
    echo "[$(date)] Detection completata con successo" >> "$LOG_FILE"
else
    echo "[$(date)] Detection fallita (exit code: $EXIT_CODE)" >> "$LOG_FILE"
fi

echo "" >> "$LOG_FILE"
