Initial commit: Log Analyzer Backend
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
# 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
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
Die API ist dann unter `http://localhost:8080/api` erreichbar.
|
||||
|
||||
## Nutzung
|
||||
|
||||
### Log-Datei hochladen
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/upload \
|
||||
-H "Content-Type: multipart/form-data" \
|
||||
-F "file=@/var/log/iptables.log"
|
||||
```
|
||||
|
||||
### Statistiken abrufen
|
||||
```bash
|
||||
curl "http://localhost:8080/api/stats?limit=20"
|
||||
```
|
||||
|
||||
### LLM-Analyse starten
|
||||
```bash
|
||||
curl -X POST "http://localhost:8080/api/analyze?log_type=firewall&limit=100"
|
||||
```
|
||||
|
||||
### Gesundheitscheck
|
||||
```bash
|
||||
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:** `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.
|
||||
|
||||
## Lizenz
|
||||
MIT
|
||||
Reference in New Issue
Block a user