Fix error when hybrid detector models are not loaded
Correctly check if the hybrid detector models are loaded by verifying the presence of `isolation_forest` instead of a non-existent `is_trained` attribute in `python_ml/main.py`. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: c8073c39-409d-45f4-a3e8-e48ce4d71e32 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/RJGlbTt
This commit is contained in:
parent
a7f55b68d7
commit
5feb691122
4
.replit
4
.replit
@ -14,6 +14,10 @@ run = ["npm", "run", "start"]
|
||||
localPort = 5000
|
||||
externalPort = 80
|
||||
|
||||
[[ports]]
|
||||
localPort = 37811
|
||||
externalPort = 3001
|
||||
|
||||
[[ports]]
|
||||
localPort = 41303
|
||||
externalPort = 3002
|
||||
|
||||
@ -1,316 +0,0 @@
|
||||
--
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
\restrict UITgYlDbn3FDig178InOifbbQhEG07ZXvVH8zocALMJzCXxRMUhf6alhjmVCnYn
|
||||
|
||||
-- Dumped from database version 16.9 (415ebe8)
|
||||
-- Dumped by pg_dump version 16.10
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
SET idle_in_transaction_session_timeout = 0;
|
||||
SET client_encoding = 'UTF8';
|
||||
SET standard_conforming_strings = on;
|
||||
SELECT pg_catalog.set_config('search_path', '', false);
|
||||
SET check_function_bodies = false;
|
||||
SET xmloption = content;
|
||||
SET client_min_messages = warning;
|
||||
SET row_security = off;
|
||||
|
||||
SET default_tablespace = '';
|
||||
|
||||
SET default_table_access_method = heap;
|
||||
|
||||
--
|
||||
-- Name: detections; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.detections (
|
||||
id character varying DEFAULT gen_random_uuid() NOT NULL,
|
||||
source_ip text NOT NULL,
|
||||
risk_score numeric(5,2) NOT NULL,
|
||||
confidence numeric(5,2) NOT NULL,
|
||||
anomaly_type text NOT NULL,
|
||||
reason text,
|
||||
log_count integer NOT NULL,
|
||||
first_seen timestamp without time zone NOT NULL,
|
||||
last_seen timestamp without time zone NOT NULL,
|
||||
blocked boolean DEFAULT false NOT NULL,
|
||||
blocked_at timestamp without time zone,
|
||||
detected_at timestamp without time zone DEFAULT now() NOT NULL,
|
||||
country text,
|
||||
country_code text,
|
||||
city text,
|
||||
organization text,
|
||||
as_number text,
|
||||
as_name text,
|
||||
isp text
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: network_analytics; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.network_analytics (
|
||||
id character varying DEFAULT gen_random_uuid() NOT NULL,
|
||||
date timestamp without time zone NOT NULL,
|
||||
hour integer,
|
||||
total_packets integer DEFAULT 0 NOT NULL,
|
||||
total_bytes bigint DEFAULT 0 NOT NULL,
|
||||
unique_ips integer DEFAULT 0 NOT NULL,
|
||||
normal_packets integer DEFAULT 0 NOT NULL,
|
||||
normal_bytes bigint DEFAULT 0 NOT NULL,
|
||||
normal_unique_ips integer DEFAULT 0 NOT NULL,
|
||||
top_normal_ips text,
|
||||
attack_packets integer DEFAULT 0 NOT NULL,
|
||||
attack_bytes bigint DEFAULT 0 NOT NULL,
|
||||
attack_unique_ips integer DEFAULT 0 NOT NULL,
|
||||
attacks_by_country text,
|
||||
attacks_by_type text,
|
||||
top_attackers text,
|
||||
traffic_by_country text,
|
||||
created_at timestamp without time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: network_logs; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.network_logs (
|
||||
id character varying DEFAULT gen_random_uuid() NOT NULL,
|
||||
router_id character varying NOT NULL,
|
||||
"timestamp" timestamp without time zone NOT NULL,
|
||||
source_ip text NOT NULL,
|
||||
destination_ip text,
|
||||
source_port integer,
|
||||
destination_port integer,
|
||||
protocol text,
|
||||
action text,
|
||||
bytes integer,
|
||||
packets integer,
|
||||
logged_at timestamp without time zone DEFAULT now() NOT NULL,
|
||||
router_name text DEFAULT 'unknown'::text NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: routers; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.routers (
|
||||
id character varying DEFAULT gen_random_uuid() NOT NULL,
|
||||
name text NOT NULL,
|
||||
ip_address text NOT NULL,
|
||||
api_port integer DEFAULT 8728 NOT NULL,
|
||||
username text NOT NULL,
|
||||
password text NOT NULL,
|
||||
enabled boolean DEFAULT true NOT NULL,
|
||||
last_sync timestamp without time zone,
|
||||
created_at timestamp without time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: schema_version; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.schema_version (
|
||||
id integer DEFAULT 1 NOT NULL,
|
||||
version integer DEFAULT 0 NOT NULL,
|
||||
applied_at timestamp without time zone DEFAULT now() NOT NULL,
|
||||
description text
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: training_history; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.training_history (
|
||||
id character varying DEFAULT gen_random_uuid() NOT NULL,
|
||||
model_version text NOT NULL,
|
||||
records_processed integer NOT NULL,
|
||||
features_count integer NOT NULL,
|
||||
accuracy numeric(5,2),
|
||||
training_duration integer,
|
||||
status text NOT NULL,
|
||||
notes text,
|
||||
trained_at timestamp without time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: whitelist; Type: TABLE; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE public.whitelist (
|
||||
id character varying DEFAULT gen_random_uuid() NOT NULL,
|
||||
ip_address text NOT NULL,
|
||||
comment text,
|
||||
reason text,
|
||||
created_by text,
|
||||
active boolean DEFAULT true NOT NULL,
|
||||
created_at timestamp without time zone DEFAULT now() NOT NULL
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: detections detections_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.detections
|
||||
ADD CONSTRAINT detections_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: network_analytics network_analytics_date_hour_key; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.network_analytics
|
||||
ADD CONSTRAINT network_analytics_date_hour_key UNIQUE (date, hour);
|
||||
|
||||
|
||||
--
|
||||
-- Name: network_analytics network_analytics_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.network_analytics
|
||||
ADD CONSTRAINT network_analytics_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: network_logs network_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.network_logs
|
||||
ADD CONSTRAINT network_logs_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: routers routers_ip_address_unique; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.routers
|
||||
ADD CONSTRAINT routers_ip_address_unique UNIQUE (ip_address);
|
||||
|
||||
|
||||
--
|
||||
-- Name: routers routers_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.routers
|
||||
ADD CONSTRAINT routers_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: schema_version schema_version_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.schema_version
|
||||
ADD CONSTRAINT schema_version_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: training_history training_history_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.training_history
|
||||
ADD CONSTRAINT training_history_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: whitelist whitelist_ip_address_unique; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.whitelist
|
||||
ADD CONSTRAINT whitelist_ip_address_unique UNIQUE (ip_address);
|
||||
|
||||
|
||||
--
|
||||
-- Name: whitelist whitelist_pkey; Type: CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.whitelist
|
||||
ADD CONSTRAINT whitelist_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: country_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX country_idx ON public.detections USING btree (country);
|
||||
|
||||
|
||||
--
|
||||
-- Name: detected_at_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX detected_at_idx ON public.detections USING btree (detected_at);
|
||||
|
||||
|
||||
--
|
||||
-- Name: detection_source_ip_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX detection_source_ip_idx ON public.detections USING btree (source_ip);
|
||||
|
||||
|
||||
--
|
||||
-- Name: network_analytics_date_hour_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX network_analytics_date_hour_idx ON public.network_analytics USING btree (date, hour);
|
||||
|
||||
|
||||
--
|
||||
-- Name: network_analytics_date_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX network_analytics_date_idx ON public.network_analytics USING btree (date);
|
||||
|
||||
|
||||
--
|
||||
-- Name: risk_score_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX risk_score_idx ON public.detections USING btree (risk_score);
|
||||
|
||||
|
||||
--
|
||||
-- Name: router_id_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX router_id_idx ON public.network_logs USING btree (router_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: source_ip_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX source_ip_idx ON public.network_logs USING btree (source_ip);
|
||||
|
||||
|
||||
--
|
||||
-- Name: timestamp_idx; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX timestamp_idx ON public.network_logs USING btree ("timestamp");
|
||||
|
||||
|
||||
--
|
||||
-- Name: network_logs network_logs_router_id_routers_id_fk; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.network_logs
|
||||
ADD CONSTRAINT network_logs_router_id_routers_id_fk FOREIGN KEY (router_id) REFERENCES public.routers(id);
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
\unrestrict UITgYlDbn3FDig178InOifbbQhEG07ZXvVH8zocALMJzCXxRMUhf6alhjmVCnYn
|
||||
|
||||
@ -682,7 +682,7 @@ if __name__ == "__main__":
|
||||
# Prova a caricare modello esistente
|
||||
if USE_HYBRID_DETECTOR:
|
||||
# Hybrid detector: già caricato all'inizializzazione (riga 69)
|
||||
if ml_detector and ml_detector.is_trained:
|
||||
if ml_detector and ml_detector.isolation_forest is not None:
|
||||
print("[ML] ✓ Hybrid detector models loaded and ready")
|
||||
else:
|
||||
print("[ML] ⚠ Hybrid detector initialized but no models found (will train on-demand)")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user