File size: 2,289 Bytes
464c149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-- Network state schema (SQLite dialect, demo)
-- Migrates cleanly to Postgres later: SERIAL -> INTEGER PRIMARY KEY AUTOINCREMENT already
-- SQLite-compatible; swap to Postgres types when you move off the demo DB.

CREATE TABLE IF NOT EXISTS devices (
    device_id      INTEGER PRIMARY KEY AUTOINCREMENT,
    hostname       TEXT,
    ip_address     TEXT UNIQUE,
    device_type    TEXT,   -- router, switch, firewall, host
    vendor         TEXT,
    location       TEXT,
    status         TEXT,   -- up, down, degraded
    last_seen      TEXT    -- ISO8601 timestamp
);

CREATE TABLE IF NOT EXISTS interfaces (
    interface_id   INTEGER PRIMARY KEY AUTOINCREMENT,
    device_id      INTEGER REFERENCES devices(device_id),
    name           TEXT,   -- eth0, Gi0/1, etc.
    status         TEXT,   -- up, down
    speed_mbps     INTEGER
);

CREATE TABLE IF NOT EXISTS traffic_flows (
    flow_id        INTEGER PRIMARY KEY AUTOINCREMENT,
    ts             TEXT,   -- ISO8601 timestamp
    src_ip         TEXT,
    dst_ip         TEXT,
    src_port       INTEGER,
    dst_port       INTEGER,
    protocol       TEXT,
    bytes          INTEGER,
    packets        INTEGER,
    duration_ms    INTEGER,
    device_id      INTEGER REFERENCES devices(device_id),
    label          TEXT    -- benign / attack type
);

CREATE TABLE IF NOT EXISTS alerts (
    alert_id       INTEGER PRIMARY KEY AUTOINCREMENT,
    ts             TEXT,
    device_id      INTEGER REFERENCES devices(device_id),
    severity       TEXT,   -- info, warning, critical
    alert_type     TEXT,   -- port_scan, dos, malware, link_down
    description    TEXT,
    resolved       INTEGER DEFAULT 0  -- 0/1 boolean
);

CREATE TABLE IF NOT EXISTS metrics_timeseries (
    metric_id      INTEGER PRIMARY KEY AUTOINCREMENT,
    ts             TEXT,
    device_id      INTEGER REFERENCES devices(device_id),
    interface_id   INTEGER REFERENCES interfaces(interface_id),
    metric_name    TEXT,   -- latency_ms, packet_loss_pct, bandwidth_util_pct
    value           REAL
);

CREATE INDEX IF NOT EXISTS idx_flows_device_ts ON traffic_flows(device_id, ts);
CREATE INDEX IF NOT EXISTS idx_alerts_device_ts ON alerts(device_id, ts);
CREATE INDEX IF NOT EXISTS idx_metrics_device_ts ON metrics_timeseries(device_id, ts);