poc2_worked
This commit is contained in:
+64
-1
@@ -7,7 +7,9 @@ import time
|
||||
from datetime import datetime, timezone
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from .analytics_cache import AnalyticsSnapshotCache
|
||||
from .config import Config
|
||||
from .live import EventBus, LiveEventPipeline, TrafficHistory
|
||||
from .maintenance import storage_info
|
||||
from .rules import RuleManager
|
||||
from .state import RuntimeStats
|
||||
@@ -67,6 +69,43 @@ def main() -> int:
|
||||
|
||||
routeros_host, routeros_port = _routeros_target(cfg)
|
||||
rule_manager = RuleManager(cfg, pid_provider=lambda: None, suricata_available=False)
|
||||
event_bus = EventBus(
|
||||
history_size=5000,
|
||||
subscriber_queue_size=cfg.websocket_queue_size,
|
||||
)
|
||||
traffic_history = TrafficHistory(
|
||||
"",
|
||||
cfg.traffic_retention_hours,
|
||||
200000,
|
||||
5000,
|
||||
allow_memory_fallback=True,
|
||||
)
|
||||
live_pipeline = LiveEventPipeline(event_bus, traffic_history)
|
||||
analytics_cache = AnalyticsSnapshotCache(
|
||||
store,
|
||||
traffic_history,
|
||||
stop_event,
|
||||
cfg.analytics_snapshot_interval_seconds,
|
||||
)
|
||||
if _bool_env("DEV_SEED_DATA", False):
|
||||
now_ms = int(time.time() * 1000)
|
||||
live_pipeline.publish({
|
||||
"id": "dev-flow",
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"ts_ms": now_ms,
|
||||
"type": "flow",
|
||||
"flow_id": "dev-flow",
|
||||
"src_ip": "192.168.100.10",
|
||||
"src_port": 51515,
|
||||
"dest_ip": "203.0.113.10",
|
||||
"dest_port": 443,
|
||||
"proto": "TCP",
|
||||
"app_proto": "tls",
|
||||
"direction": "outbound",
|
||||
"bytes": 8192,
|
||||
"packets": 12,
|
||||
"flow_state": "established",
|
||||
})
|
||||
|
||||
def health() -> dict:
|
||||
db = store.database_info()
|
||||
@@ -117,6 +156,16 @@ def main() -> int:
|
||||
"status": "up",
|
||||
"details": f"{db['path']}; {db['rows']} incidents; WAL={db['journal_mode']}",
|
||||
},
|
||||
"traffic_history": {
|
||||
"name": "Live traffic history",
|
||||
"status": "up",
|
||||
"details": "Bounded RAM history in web-only development mode",
|
||||
},
|
||||
"analytics_cache": {
|
||||
"name": "Persistent dashboard summaries",
|
||||
"status": "up",
|
||||
"details": f"Redis snapshots for 15m/1h/6h/24h every {cfg.analytics_snapshot_interval_seconds}s",
|
||||
},
|
||||
"storage": {
|
||||
"name": "Persistent storage",
|
||||
"status": "up",
|
||||
@@ -162,7 +211,17 @@ def main() -> int:
|
||||
"runtime": stats.snapshot(),
|
||||
}
|
||||
|
||||
web = WebServer(cfg, store, health, stats=stats, rule_manager=rule_manager)
|
||||
web = WebServer(
|
||||
cfg,
|
||||
store,
|
||||
health,
|
||||
stats=stats,
|
||||
rule_manager=rule_manager,
|
||||
traffic_history=traffic_history,
|
||||
event_bus=event_bus,
|
||||
live_pipeline=live_pipeline,
|
||||
analytics_cache=analytics_cache,
|
||||
)
|
||||
|
||||
def request_stop(_signum=None, _frame=None) -> None:
|
||||
stop_event.set()
|
||||
@@ -170,6 +229,8 @@ def main() -> int:
|
||||
signal.signal(signal.SIGTERM, request_stop)
|
||||
signal.signal(signal.SIGINT, request_stop)
|
||||
|
||||
live_pipeline.start()
|
||||
analytics_cache.start()
|
||||
web.start()
|
||||
print(f"[dev] web-only mode active at http://{cfg.web_bind}:{cfg.web_port}", flush=True)
|
||||
|
||||
@@ -182,6 +243,8 @@ def main() -> int:
|
||||
try:
|
||||
web.stop()
|
||||
finally:
|
||||
live_pipeline.stop()
|
||||
analytics_cache.stop()
|
||||
store.close()
|
||||
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user