import { useQuery } from "@tanstack/react-query"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { AlertTriangle, Search, Shield, Eye } from "lucide-react"; import { format } from "date-fns"; import { useState } from "react"; import type { Detection } from "@shared/schema"; export default function Detections() { const [searchQuery, setSearchQuery] = useState(""); const { data: detections, isLoading } = useQuery({ queryKey: ["/api/detections"], refetchInterval: 5000, }); const filteredDetections = detections?.filter((d) => d.sourceIp.toLowerCase().includes(searchQuery.toLowerCase()) || d.anomalyType.toLowerCase().includes(searchQuery.toLowerCase()) ); const getRiskBadge = (riskScore: string) => { const score = parseFloat(riskScore); if (score >= 85) return CRITICO; if (score >= 70) return ALTO; if (score >= 60) return MEDIO; if (score >= 40) return BASSO; return NORMALE; }; const getAnomalyTypeLabel = (type: string) => { const labels: Record = { ddos: "DDoS Attack", port_scan: "Port Scanning", brute_force: "Brute Force", botnet: "Botnet Activity", suspicious: "Suspicious Activity" }; return labels[type] || type; }; return (

Rilevamenti

Anomalie rilevate dal sistema IDS

{/* Search and Filters */}
setSearchQuery(e.target.value)} className="pl-9" data-testid="input-search" />
{/* Detections List */} Rilevamenti ({filteredDetections?.length || 0}) {isLoading ? (
Caricamento...
) : filteredDetections && filteredDetections.length > 0 ? (
{filteredDetections.map((detection) => (
{detection.sourceIp} {getRiskBadge(detection.riskScore)} {getAnomalyTypeLabel(detection.anomalyType)}

{detection.reason}

Risk Score

{parseFloat(detection.riskScore).toFixed(1)}/100

Confidence

{parseFloat(detection.confidence).toFixed(1)}%

Log Count

{detection.logCount}

Rilevato

{format(new Date(detection.detectedAt), "dd/MM HH:mm")}

Prima: {format(new Date(detection.firstSeen), "dd/MM HH:mm:ss")} Ultima: {format(new Date(detection.lastSeen), "dd/MM HH:mm:ss")}
{detection.blocked ? ( Bloccato ) : ( Attivo )}
))}
) : (

Nessun rilevamento trovato

{searchQuery && (

Prova con un altro termine di ricerca

)}
)}
); }