#!/bin/bash
# =========================================================
# CRON TRAINING - Addestramento automatico modello ML
# =========================================================

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

echo "=========================================" >> "$LOG_FILE"
echo "[$(date)] Training automatico avviato" >> "$LOG_FILE"
echo "=========================================" >> "$LOG_FILE"

curl -X POST http://localhost:8000/train \
  -H "Content-Type: application/json" \
  -d '{"max_records": 1000000, "hours_back": 24}' \
  --max-time 300 >> "$LOG_FILE" 2>&1

EXIT_CODE=$?

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

echo "" >> "$LOG_FILE"
