695d715d5b8539b61e0f495c190832fd7abb4e98
Log Analyzer Backend
CPU-LLM-gestütztes Backend zur Auswertung von Firewall- und Proxy-Logs. Parst Dateien, aggregiert Statistiken (Top-Hits, Quellen, Ziele, Ports, URLs) und nutzt ein lokales LLM (via Ollama) für die Analyse.
Features
- Log-Parsing: Unterstützt iptables, pfSense, Cisco ASA, Squid, nginx
- Statistiken: Top Quellen, Ziele, Ports, URLs, Actions, Timeline
- LLM-Analyse: Zusammenfassung und Anomalie-Erkennung via lokalem Ollama-Modell
- REST-API: FastAPI mit automatischer OpenAPI-Doku unter
/docs - Docker-Compose: Schneller Start mit Backend + nginx Reverse Proxy
Architektur
┌──────────────┐ ┌──────────────┐ ┌──────────────────────┐
│ Client │──────▶│ nginx:80 │──────▶│ FastAPI Backend:8000 │
└──────────────┘ └──────────────┘ │ - SQLite (Volumen) │
│ - Log-Parser │
│ - Ollama-Client │
└───────────────────────┘
│
▼
┌──────────────────────┐
│ Ollama (CPU/Host) │
│ http://host.docker │
│ .internal:11434│
└──────────────────────┘
Voraussetzungen
- Docker + Docker Compose
- Laufende Ollama-Instanz auf dem Host (Port 11434) mit Modell
llava:7b - Ports: 8080 (nginx), 11434 (Ollama auf Host)
Installation & Start
# Repository klonen
git clone https://gitea.die-heimatlosen.eu/arch_agent/log-analyzer-backend.git
cd log-analyzer-backend
# Starten
docker-compose up -d --build
Die API ist dann unter http://localhost:8080/api erreichbar.
Nutzung
Log-Datei hochladen
curl -X POST http://localhost:8080/api/upload \
-H "Content-Type: multipart/form-data" \
-F "file=@/var/log/iptables.log"
Statistiken abrufen
curl "http://localhost:8080/api/stats?limit=20"
LLM-Analyse starten
curl -X POST "http://localhost:8080/api/analyze?log_type=firewall&limit=100"
Gesundheitscheck
curl http://localhost:8080/health
API-Endpunkte
| Methode | Endpunkt | Beschreibung |
|---|---|---|
| POST | /api/upload |
Log-Datei hochladen & parsen |
| GET | /api/stats |
Übersicht aller Statistiken |
| GET | /api/stats/sources |
Top Quellen |
| GET | /api/stats/destinations |
Top Ziele |
| GET | /api/stats/ports |
Top Ports |
| POST | /api/analyze |
LLM-Analyse der Logs |
| GET | /health |
Healthcheck |
Umgebungsvariablen
| Variable | Standard | Beschreibung |
|---|---|---|
DATABASE_URL |
sqlite+aiosqlite:///data/logs.db |
SQLite Datenbankpfad |
OLLAMA_URL |
http://host.docker.internal:11434 |
Ollama API URL |
OLLAMA_MODEL |
llava:7b |
LLM Modellname |
Unterstützte Log-Formate
Firewall
- iptables: Kernel-Logzeilen mit
SRC=... DST=... PROTO=... DPT=... - pfSense:
filterlogCSV-ähnliche Zeilen - Cisco ASA:
%ASA-... Built/Teardown/Denied ...
Proxy
- Squid: Native Squid-Logformat (Timestamp, elapsed, client, code, status, size, method, URL)
- nginx: Standard access_log (
$remote_addr - [$time_local] "$request" $status $body_bytes_sent)
Hinweise
- Das Backend erwartet Ollama auf dem Host (nicht im Container). Für Linux ggf.
extra_hosts: ["host.docker.internal:host-gateway"]nutzen. - Große Logdateien werden in Batches von 500 Zeilen verarbeitet.
- Die SQLite-Datenbank wird im Docker-Volumen
logdatapersistiert.
Lizenz
MIT
Description
Languages
Python
59.9%
JavaScript
14.3%
CSS
12.5%
HTML
12.2%
Dockerfile
1.1%