Files

120 lines
4.6 KiB
Markdown

# Log Analyzer Backend + Frontend
CPU-LLM-gestütztes Dashboard zur Auswertung von Firewall- und Proxy-Logs. Parst Dateien, zeigt übersichtliche Statistiken (Top-Hits, Quellen, Ziele, Ports, URLs, Zeitverlauf) 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`
- **Web-Dashboard:** Vue 3 + Chart.js SPA, erreichbar auf Port 80
- **Docker-Compose:** Ein Befehl zum Starten von Backend + Frontend
## Architektur
```
┌──────────────┐ ┌──────────────┐ ┌──────────────────────┐
│ Browser │──────▶│ Frontend:80 │──────▶│ FastAPI Backend:8000 │
└──────────────┘ │ (nginx + │ │ - SQLite (Volumen) │
│ Vue SPA) │ │ - 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: 80 (Dashboard), 11434 (Ollama auf Host)
## Installation & Start
```bash
# 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
```
Das Dashboard ist dann unter `http://localhost` erreichbar. Die API-Doku unter `http://localhost/docs`.
## Nutzung
### Dashboard
1. Browser öffnen: `http://localhost`
2. Log-Datei über das Upload-Feld hochladen
3. Statistiken und Charts werden automatisch geladen (alle 15 Sek. refreshed)
4. LLM-Analyse über den Bereich unten starten
### API (cURL)
#### Log-Datei hochladen
```bash
curl -X POST http://localhost/api/upload \
-H "Content-Type: multipart/form-data" \
-F "file=@/var/log/iptables.log"
```
#### Statistiken abrufen
```bash
curl "http://localhost/api/stats?limit=20"
```
#### LLM-Analyse starten
```bash
curl -X POST "http://localhost/api/analyze?log_type=firewall&limit=100"
```
#### Gesundheitscheck
```bash
curl http://localhost/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 |
| GET | `/docs` | Swagger UI (FastAPI) |
## 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:** `filterlog` CSV-ä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 `logdata` persistiert.
- Das Frontend aktualisiert die Statistiken automatisch alle 15 Sekunden.
## Lizenz
MIT