Compare commits
7 Commits
v0.2.3
...
45c46e0f63
| Author | SHA1 | Date | |
|---|---|---|---|
| 45c46e0f63 | |||
| 4903187a37 | |||
| 96c481c4c1 | |||
| 6eec58b8e7 | |||
| a7ca1214f3 | |||
| 1aab81a7fc | |||
| f8961320c5 |
@@ -18,11 +18,15 @@ FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||
# Build-Argument für Version (wird zur Build-Zeit vom CI/CD gesetzt)
|
||||
ARG VERSION=latest
|
||||
|
||||
# Build-Argumente für UID/GID (Standard: 1000)
|
||||
ARG USER_UID=1000
|
||||
ARG USER_GID=1000
|
||||
|
||||
# Install curl for health checks
|
||||
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Create non-root user
|
||||
RUN groupadd -r watcher -g 1000 && useradd -r -g watcher -u 1000 watcher
|
||||
# Create non-root user with configurable UID/GID
|
||||
RUN groupadd -r watcher -g ${USER_GID} && useradd -r -g watcher -u ${USER_UID} watcher
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=build /app/publish .
|
||||
|
||||
343
Planung/TODO.md
Normal file
343
Planung/TODO.md
Normal file
@@ -0,0 +1,343 @@
|
||||
# Watcher - Probleme und TODO-Liste
|
||||
|
||||
**Stand:** 2025-11-19
|
||||
**Analyse:** Automatische Code-Review
|
||||
|
||||
---
|
||||
|
||||
## 🔴 KRITISCHE PROBLEME (Sofort beheben!)
|
||||
|
||||
### 1. Schwerwiegender Bug: Passwort überschreibt Username
|
||||
- **Datei:** `Watcher/Controllers/UserController.cs:111`
|
||||
- **Problem:** `user.Username = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);`
|
||||
- **Auswirkung:** Beim Passwort-Ändern wird der Username zerstört, Account wird unbrauchbar
|
||||
- **Fix:** Muss `user.Password = ...` sein
|
||||
- **Status:** ❌ Offen
|
||||
- **Priorität:** KRITISCH
|
||||
|
||||
### 2. Path Traversal Schwachstelle
|
||||
- **Datei:** `Watcher/Controllers/DownloadController.cs:24-35`
|
||||
- **Problem:**
|
||||
- Keine Validierung gegen `../` Attacken
|
||||
- Leerer String als Extension erlaubt
|
||||
- Kommentar im Code: "TODO: aktuelles "" für Binaries ist das absolute Gegenteil von sicher"
|
||||
- **Auswirkung:** Angreifer könnten beliebige Dateien herunterladen
|
||||
- **Status:** ❌ Offen
|
||||
- **Priorität:** KRITISCH
|
||||
|
||||
### 3. Ungeschützte Monitoring-Endpoints
|
||||
- **Dateien:**
|
||||
- `Watcher/Controllers/MonitoringController.cs:112,155,173,237,365`
|
||||
- `Watcher/Controllers/HeartbeatController.cs:31`
|
||||
- `Watcher/Controllers/ApiController.cs:26`
|
||||
- **Problem:** KEINE Authentifizierung
|
||||
- **Auswirkung:** Jeder kann:
|
||||
- Fake Server registrieren
|
||||
- Monitoring-Daten manipulieren
|
||||
- Alle Server-Informationen abrufen
|
||||
- Heartbeats senden
|
||||
- **Fix:** API-Key oder Token-basierte Authentifizierung implementieren
|
||||
- **Status:** ❌ Offen
|
||||
- **Priorität:** KRITISCH
|
||||
|
||||
### 4. Command Injection
|
||||
- **Datei:** `Watcher/Controllers/DatabaseController.cs:176-184`
|
||||
- **Problem:** Unvalidierter `fileName` in `sqlite3` Prozess-Aufruf
|
||||
- **Auswirkung:** Potenzielle Command Injection beim Database Restore
|
||||
- **Fix:** Input-Validierung und Sanitization
|
||||
- **Status:** ❌ Offen
|
||||
- **Priorität:** KRITISCH
|
||||
|
||||
---
|
||||
|
||||
## 🟠 HOHE PRIORITÄT
|
||||
|
||||
### 5. HttpClient Resource Leak
|
||||
- **Datei:** `Watcher/Services/UpdateCheckService.cs:24`
|
||||
- **Problem:** `new HttpClient()` im Singleton-Konstruktor
|
||||
- **Auswirkung:** Socket Exhaustion bei vielen Requests möglich
|
||||
- **Fix:** `IHttpClientFactory` verwenden
|
||||
- **Status:** ❌ Offen
|
||||
- **Priorität:** HOCH
|
||||
|
||||
### 6. Default Credentials in Production
|
||||
- **Datei:** `Watcher/Program.cs:127-137`
|
||||
- **Problem:** Standard-User "admin/changeme" wird immer erstellt
|
||||
- **Auswirkung:** Bekannte Credentials, Sicherheitsrisiko
|
||||
- **Fix:**
|
||||
- Beim ersten Start Passwort abfragen
|
||||
- Oder aus Environment Variable lesen
|
||||
- Oder zufälliges Passwort generieren und loggen
|
||||
- **Status:** ❌ Offen
|
||||
- **Priorität:** HOCH
|
||||
|
||||
### 7. Race Conditions in Singleton Stores
|
||||
- **Dateien:**
|
||||
- `Watcher/Services/DashboardStore.cs`
|
||||
- `Watcher/Services/UpdateCheckStore.cs`
|
||||
- **Problem:** Properties werden ohne Thread-Synchronisation von Background Services geschrieben und von Controllern gelesen
|
||||
- **Fix:** Lock-Mechanismus oder Concurrent Collections verwenden
|
||||
- **Status:** ❌ Offen
|
||||
- **Priorität:** HOCH
|
||||
|
||||
### 8. N+1 Query Problem
|
||||
- **Datei:** `Watcher/Controllers/ServerController.cs:206-212`
|
||||
- **Problem:** `SaveChangesAsync()` in foreach-Loop
|
||||
- **Code:**
|
||||
```csharp
|
||||
foreach (var server in servers)
|
||||
{
|
||||
server.IsOnline = (DateTime.UtcNow - server.LastSeen).TotalSeconds <= 120;
|
||||
await _context.SaveChangesAsync(); // In Loop!
|
||||
}
|
||||
```
|
||||
- **Auswirkung:** Ineffizient, potenzielle Database Locks
|
||||
- **Fix:** Alle Änderungen sammeln, einmal am Ende speichern
|
||||
- **Status:** ❌ Offen
|
||||
- **Priorität:** HOCH
|
||||
|
||||
### 9. Synchrone DB-Abfragen in async Methoden
|
||||
- **Datei:** `Watcher/Controllers/UserController.cs:28,53,73,101`
|
||||
- **Problem:** `FirstOrDefault()` statt `FirstOrDefaultAsync()`
|
||||
- **Auswirkung:** Thread-Pool wird blockiert, reduziert Skalierbarkeit
|
||||
- **Fix:** Async-Varianten verwenden
|
||||
- **Status:** ❌ Offen
|
||||
- **Priorität:** HOCH
|
||||
|
||||
### 10. Ineffiziente Database Queries
|
||||
- **Datei:** `Watcher/Controllers/HomeController.cs:77-78`
|
||||
- **Problem:** `ToList()` lädt ALLE Daten vor Filterung
|
||||
- **Code:**
|
||||
```csharp
|
||||
var servers = _context.Servers.ToList();
|
||||
var containers = _context.Containers.ToList();
|
||||
```
|
||||
- **Auswirkung:** Memory-Probleme bei vielen Datensätzen
|
||||
- **Fix:** Filter in LINQ-Query vor `ToList()`
|
||||
- **Status:** ❌ Offen
|
||||
- **Priorität:** HOCH
|
||||
|
||||
### 11. Database Connections nicht immer mit using
|
||||
- **Datei:** `Watcher/Services/DatabaseCheck.cs:33-59`
|
||||
- **Problem:** Connection wird manuell geschlossen, bei Exception könnte sie offen bleiben
|
||||
- **Fix:** `using` Statement verwenden
|
||||
- **Status:** ❌ Offen
|
||||
- **Priorität:** HOCH
|
||||
|
||||
---
|
||||
|
||||
## 🟡 MITTLERE PRIORITÄT
|
||||
|
||||
### Code-Qualität
|
||||
|
||||
#### 12. Generische catch-Blöcke ohne Exception-Logging
|
||||
- **Dateien:**
|
||||
- `Watcher/Services/NetworkCheck.cs:47`
|
||||
- `Watcher/Controllers/MonitoringController.cs:222-228`
|
||||
- **Problem:** Leere catch-Blöcke verschlucken alle Exceptions
|
||||
- **Fix:** Spezifischen Exception-Typ verwenden und Exception loggen
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
#### 13. Code-Duplikation in UserController
|
||||
- **Datei:** `Watcher/Controllers/UserController.cs:64-90 und 93-119`
|
||||
- **Problem:** Zwei fast identische Methoden `Edit()` und `UserSettings()`
|
||||
- **Fix:** Gemeinsame Logik extrahieren
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
#### 14. Sehr große Controller-Methode
|
||||
- **Datei:** `Watcher/Controllers/MonitoringController.cs:237-362`
|
||||
- **Problem:** ServiceDetection mit 125 Zeilen, viele Verantwortlichkeiten
|
||||
- **Fix:** In kleinere Methoden aufteilen, Service-Klasse extrahieren
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
#### 15. Magic Numbers
|
||||
- **Dateien:**
|
||||
- `Watcher/Controllers/ServerController.cs:210` - `120` Sekunden hardcodiert
|
||||
- `Watcher/Services/NetworkCheck.cs:35` - `"8.8.8.8"` hardcodiert
|
||||
- `Watcher/Services/NetworkCheck.cs:40` - `3000` ms Timeout hardcodiert
|
||||
- **Fix:** Als Konstanten oder Konfiguration auslagern
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
#### 16. Duplizierte Endpoint-Logik
|
||||
- **Datei:** `Watcher/Controllers/MonitoringController.cs:421-481`
|
||||
- **Problem:** GetCpuUsageData, GetRamUsageData, GetGpuUsageData sind nahezu identisch
|
||||
- **Fix:** Generische Methode mit Parameter
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
#### 17. Synchrone I/O in async Methoden
|
||||
- **Datei:** `Watcher/Controllers/DatabaseController.cs:46,69,137,149,151,163,174`
|
||||
- **Problem:** `File.ReadAllBytes()`, `File.Exists()` etc. sind synchron
|
||||
- **Fix:** Async File I/O verwenden
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
### Sicherheit
|
||||
|
||||
#### 18. Kein Brute-Force Schutz
|
||||
- **Datei:** `Watcher/Controllers/AuthController.cs:36-72`
|
||||
- **Problem:** Login hat keine Rate-Limiting, Account Lockout oder CAPTCHA
|
||||
- **Fix:** Rate-Limiting Middleware oder Account Lockout implementieren
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
#### 19. SQL Injection Potential
|
||||
- **Datei:** `Watcher/Controllers/DatabaseController.cs:91`
|
||||
- **Problem:** String-Interpolation für SQL-Query: `$"SELECT * FROM {tableName}"`
|
||||
- **Hinweis:** tableName kommt aus sqlite_master, aber schlechte Praxis
|
||||
- **Fix:** Parametrisierte Queries verwenden
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
#### 20. Fehlende IP-Adress-Validierung
|
||||
- **Datei:** `Watcher/Controllers/MonitoringController.cs:129,159,262`
|
||||
- **Problem:** IP-Adressen werden nicht validiert
|
||||
- **Fix:** Regex oder IPAddress.TryParse verwenden
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
### Architektur
|
||||
|
||||
#### 21. Kein Repository Pattern
|
||||
- **Problem:** DbContext direkt in allen Controllern
|
||||
- **Auswirkung:** Schwer testbar, keine Abstraktionsschicht
|
||||
- **Fix:** Repository Pattern oder CQRS implementieren
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
#### 22. Hardcodierte Connection Strings
|
||||
- **Dateien:**
|
||||
- `Watcher/Services/DatabaseCheck.cs:33`
|
||||
- `Watcher/Controllers/SystemController.cs:37`
|
||||
- **Problem:** `"Data Source=./persistence/watcher.db"` hardcodiert
|
||||
- **Fix:** Aus Configuration/appsettings.json lesen
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
#### 23. Keine Dependency Inversion
|
||||
- **Problem:** Keine Interfaces für Repositories, direkte DbContext-Abhängigkeit
|
||||
- **Fix:** Interface-basierte Dependency Injection
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
### Performanz
|
||||
|
||||
#### 24. Fehlende Database Indizes
|
||||
- **Problem:** Keine expliziten Indizes für häufig abgefragte Felder
|
||||
- **Beispiele:** Server.IPAddress, Container.ContainerId
|
||||
- **Fix:** Indizes in DbContext konfigurieren
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
#### 25. Keine Caching-Strategie
|
||||
- **Problem:** Metrics werden jedes Mal neu aus DB geladen
|
||||
- **Fix:** In-Memory Cache für Current Metrics implementieren
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
#### 26. Mehrfache SaveChanges in Loop
|
||||
- **Datei:** `Watcher/Controllers/MonitoringController.cs:327,349,359`
|
||||
- **Problem:** SaveChanges wird in Loop aufgerufen
|
||||
- **Fix:** Batch-Updates am Ende
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
---
|
||||
|
||||
## 🔵 NIEDRIGE PRIORITÄT / WARTBARKEIT
|
||||
|
||||
### 27. Keine Unit Tests
|
||||
- **Problem:** Keine Test-Dateien in der Codebase
|
||||
- **Auswirkung:** Keine automatisierte Qualitätssicherung
|
||||
- **Fix:** xUnit/NUnit Test-Suite aufbauen
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
### 28. Fehlende Integration Tests
|
||||
- **Problem:** Kritische Flows wie Login, Monitoring-Daten-Empfang sind ungetestet
|
||||
- **Fix:** Integration Tests schreiben
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
### 29. Unvollständige TODOs im Code
|
||||
- **Dateien:**
|
||||
- `MonitoringController.cs:287` - "TODO entfernen wenn fertig getestet"
|
||||
- `MonitoringController.cs:352` - "//Todo" (Metrics für Container entfernen)
|
||||
- `MonitoringController.cs:525` - "//TODO" (CalculateMegabit korrekt implementieren)
|
||||
- `DownloadController.cs:28` - "TODO: aktuelles "" für Binaries ist das absolute Gegenteil von sicher"
|
||||
- `DatabaseCheck.cs:61` - "// TODO: LogEvent erstellen"
|
||||
- `SystemMangement.cs:20` - "// Todo: Umstellen auf einmal alle 24h"
|
||||
- **Fix:** TODOs abarbeiten oder entfernen
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
### 30. Fehlende XML-Dokumentation
|
||||
- **Problem:** Keine `///` Kommentare für öffentliche APIs
|
||||
- **Fix:** XML-Kommentare für Controllers und Services hinzufügen
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
### 31. Console.WriteLine in Production
|
||||
- **Dateien:**
|
||||
- `Program.cs:121,125,137,141`
|
||||
- `MonitoringController.cs:288-293`
|
||||
- **Problem:** Console.WriteLine statt strukturiertes Logging
|
||||
- **Fix:** ILogger verwenden
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
### 32. Inkonsistente Namenskonventionen
|
||||
- **Datei:** `MonitoringController.cs:53-81`
|
||||
- **Problem:** MetricDto Properties in UPPERCASE (CPU_Load, RAM_Size)
|
||||
- **Fix:** PascalCase verwenden (CpuLoad, RamSize)
|
||||
- **Status:** ❌ Offen
|
||||
|
||||
---
|
||||
|
||||
## 📊 STATISTIK
|
||||
|
||||
- **Kritische Probleme:** 4
|
||||
- **Hohe Priorität:** 7
|
||||
- **Mittlere Priorität:** 18
|
||||
- **Niedrige Priorität:** 6
|
||||
- **Gesamt:** 35 Probleme
|
||||
|
||||
---
|
||||
|
||||
## 🎯 EMPFOHLENE REIHENFOLGE
|
||||
|
||||
### Sprint 1 - Kritische Sicherheit (Sofort)
|
||||
1. Bug in UserController.cs Zeile 111 beheben
|
||||
2. Authentifizierung für Monitoring-Endpoints
|
||||
3. Path Traversal Validierung in DownloadController
|
||||
4. Command Injection in DatabaseController beheben
|
||||
|
||||
### Sprint 2 - Stabilität & Performance (Woche 1-2)
|
||||
5. HttpClientFactory implementieren
|
||||
6. N+1 Query Probleme beheben
|
||||
7. Async/Await korrekt verwenden
|
||||
8. Database Connection Management
|
||||
|
||||
### Sprint 3 - Sicherheit & Konfiguration (Woche 3-4)
|
||||
9. Default Credentials entfernen/anpassbar machen
|
||||
10. Input-Validierung verbessern
|
||||
11. Brute-Force Protection
|
||||
12. Thread-Safety in Stores
|
||||
|
||||
### Sprint 4 - Architektur (Monat 2)
|
||||
13. Repository Pattern einführen
|
||||
14. Code-Duplikation eliminieren
|
||||
15. Große Methoden refactoren
|
||||
16. Magic Numbers entfernen
|
||||
|
||||
### Sprint 5 - Qualität (Monat 3)
|
||||
17. Test-Suite aufbauen (Unit + Integration)
|
||||
18. Statische Code-Analyse einrichten
|
||||
19. TODOs abarbeiten
|
||||
20. Dokumentation verbessern
|
||||
|
||||
---
|
||||
|
||||
## 🔧 TOOLS & HILFSMITTEL
|
||||
|
||||
### Empfohlene Tools
|
||||
- **Statische Analyse:** SonarQube, Roslyn Analyzers
|
||||
- **Security Scanning:** OWASP Dependency Check, Snyk
|
||||
- **Testing:** xUnit, Moq, FluentAssertions
|
||||
- **Code Coverage:** Coverlet, ReportGenerator
|
||||
- **Performance:** BenchmarkDotNet, MiniProfiler
|
||||
|
||||
### Code-Qualität Metriken
|
||||
- **Zyklomatische Komplexität:** < 10 pro Methode
|
||||
- **Zeilen pro Methode:** < 50
|
||||
- **Test Coverage:** > 80%
|
||||
- **Code Duplication:** < 5%
|
||||
|
||||
---
|
||||
|
||||
**Letzte Aktualisierung:** 2025-11-19
|
||||
**Erstellt durch:** Automatische Code-Analyse
|
||||
189
README.md
189
README.md
@@ -12,66 +12,16 @@
|
||||
Die Software besteht aus zwei Hauptkomponenten:
|
||||
|
||||
- **Host Agent**: Sammelt Hardware-Metriken (CPU, GPU, RAM, Festplatte, Netzwerk) von den überwachten Servern
|
||||
- **Zentrale Monitoring-Software**: Web-basiertes Dashboard zur Visualisierung und Verwaltung der gesammelten Daten mit konfigurierbaren Alarmschwellen
|
||||
- **Zentrale Monitoring-Software**: Web-basiertes Dashboard zur Visualisierung und Verwaltung der gesammelten Daten
|
||||
|
||||
## ✨ Hauptfunktionen
|
||||
|
||||
### Server-Management
|
||||
- Hinzufügen, bearbeiten und löschen von Servern
|
||||
- Hardware-Spezifikationen erfassen (CPU, GPU, RAM, Festplatte)
|
||||
- Server-Verifikationssystem
|
||||
- Online/Offline-Status-Tracking via Heartbeat
|
||||
- Konfigurierbare Alarmschwellen pro Server
|
||||
|
||||
### Monitoring & Metriken
|
||||
- Echtzeit-Metrikerfassung: CPU, GPU, RAM, Festplatte, Netzwerk
|
||||
- Automatische Datenaufbewahrung mit konfigurierbarer Retention (Standard: 30 Tage)
|
||||
- Historische Datenspeicherung mit Zeitstempel
|
||||
- REST API-Endpunkte für Metrik-Submission
|
||||
- Swagger/OpenAPI-Dokumentation unter `/api/v1/swagger`
|
||||
|
||||
### Container-Management
|
||||
- Docker-Container-Tracking pro Server
|
||||
- Container-Image-Registry
|
||||
- Container-Status-Überwachung
|
||||
- Service Discovery für Docker-Container
|
||||
|
||||
### Sicherheit & Authentifizierung
|
||||
- Lokale Benutzerauthentifizierung mit BCrypt-Hashing
|
||||
- Cookie-basierte Session-Verwaltung
|
||||
- Rollenbasierte Zugriffskontrolle
|
||||
- Standard-Admin-Benutzer (Username: `admin`, Passwort: `changeme` - bitte ändern!)
|
||||
|
||||
### Logging & Diagnostik
|
||||
- Strukturiertes Logging mit Serilog
|
||||
- Tägliche Log-Dateien: `logs/watcher-<datum>.log`
|
||||
- Health-Check-Endpunkte
|
||||
- Datenbank-Export-Funktionalität (SQL-Dumps)
|
||||
|
||||
## 🛠️ Technologie-Stack
|
||||
|
||||
**Backend:**
|
||||
- ASP.NET Core 8.0 (C#)
|
||||
- Entity Framework Core 8.0
|
||||
- Serilog 9.0 für Logging
|
||||
|
||||
**Datenbank:**
|
||||
- SQLite (Standard, dateibasiert)
|
||||
- MySQL-Unterstützung (konfigurierbar)
|
||||
|
||||
**Frontend:**
|
||||
- Razor Views (CSHTML)
|
||||
- Bootstrap / CSS
|
||||
- jQuery, jQuery Validation
|
||||
|
||||
**API & Dokumentation:**
|
||||
- Swagger/Swashbuckle 9.0.6
|
||||
- REST API
|
||||
|
||||
**Container & Deployment:**
|
||||
- Docker (Multi-Arch: AMD64, ARM64)
|
||||
- Docker Compose
|
||||
- Gitea CI/CD
|
||||
### Hauptfunktionen
|
||||
- Echtzeit-Hardware-Monitoring (CPU, GPU, RAM, Festplatte, Netzwerk)
|
||||
- Docker-Container-Überwachung mit Service Discovery
|
||||
- Web-basiertes Dashboard mit historischen Daten
|
||||
- Konfigurierbare Alarmschwellen
|
||||
- REST API mit Swagger-Dokumentation
|
||||
- Automatische Datenaufbewahrung (konfigurierbar)
|
||||
- Rootless Container-Betrieb für erhöhte Sicherheit
|
||||
|
||||
## 🚀 Installation & Start
|
||||
|
||||
@@ -81,111 +31,70 @@ Die Software besteht aus zwei Hauptkomponenten:
|
||||
|
||||
### Schnellstart
|
||||
|
||||
1. **docker-compose.yaml erstellen** oder die bereitgestellte verwenden:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
watcher:
|
||||
image: git.triggermeelmo.com/watcher/watcher-server:latest
|
||||
container_name: watcher
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 200M
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- WATCHER_VERSION=latest
|
||||
- UPDATE_CHECK_ENABLED=true
|
||||
- UPDATE_CHECK_INTERVAL_HOURS=24
|
||||
- METRIC_RETENTION_DAYS=30
|
||||
- METRIC_CLEANUP_ENABLED=true
|
||||
- METRIC_CLEANUP_INTERVAL_HOURS=24
|
||||
ports:
|
||||
- "5000:5000"
|
||||
volumes:
|
||||
- ./watcher-volumes/data:/app/persistence
|
||||
- ./watcher-volumes/dumps:/app/wwwroot/downloads/sqlite
|
||||
- ./watcher-volumes/logs:/app/logs
|
||||
1. **Repository klonen oder docker-compose.yaml herunterladen**
|
||||
```bash
|
||||
git clone https://git.triggermeelmo.com/Watcher/watcher.git
|
||||
cd watcher
|
||||
```
|
||||
|
||||
2. **Container starten:**
|
||||
2. **Umgebungsvariablen konfigurieren (optional)**
|
||||
```bash
|
||||
# .env Datei erstellen
|
||||
cp .env.example .env
|
||||
|
||||
# Eigene UID/GID eintragen (für korrekte Dateiberechtigungen)
|
||||
echo "USER_UID=$(id -u)" >> .env
|
||||
echo "USER_GID=$(id -g)" >> .env
|
||||
```
|
||||
|
||||
3. **Verzeichnisse mit korrekten Rechten erstellen**
|
||||
```bash
|
||||
mkdir -p data/db data/dumps data/logs
|
||||
chown -R $(id -u):$(id -g) data/
|
||||
```
|
||||
|
||||
4. **Container starten**
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
3. **Dashboard aufrufen:**
|
||||
5. **Dashboard aufrufen**
|
||||
```
|
||||
http://localhost:5000
|
||||
```
|
||||
|
||||
4. **Standardanmeldung:**
|
||||
6. **Standardanmeldung**
|
||||
- Benutzername: `admin`
|
||||
- Passwort: `changeme`
|
||||
- ⚠️ **Wichtig:** Bitte Passwort nach dem ersten Login ändern!
|
||||
- ⚠️ **Wichtig:** Passwort nach dem ersten Login ändern!
|
||||
|
||||
## ⚙️ Konfiguration
|
||||
### Konfiguration
|
||||
|
||||
### Umgebungsvariablen
|
||||
#### Wichtige Umgebungsvariablen
|
||||
|
||||
| Variable | Beschreibung | Standard |
|
||||
|----------|--------------|----------|
|
||||
| `WATCHER_VERSION` | Anwendungsversion | `latest` |
|
||||
| `UPDATE_CHECK_ENABLED` | Update-Prüfung aktivieren | `true` |
|
||||
| `UPDATE_CHECK_INTERVAL_HOURS` | Update-Prüfungs-Intervall | `24` |
|
||||
| `USER_UID` | User-ID für Container (Dateiberechtigungen) | `1000` |
|
||||
| `USER_GID` | Gruppen-ID für Container | `1000` |
|
||||
| `IMAGE_VERSION` | Docker Image Version | `latest` |
|
||||
| `METRIC_RETENTION_DAYS` | Datenspeicherdauer (Tage) | `30` |
|
||||
| `METRIC_CLEANUP_ENABLED` | Automatische Datenbereinigung | `true` |
|
||||
| `METRIC_CLEANUP_INTERVAL_HOURS` | Bereinigungs-Intervall | `24` |
|
||||
| `DATABASE:CONNECTIONSTRINGS:SQLITE` | Benutzerdefinierter SQLite-Pfad | - |
|
||||
| `FRONTEND_REFRESH_INTERVAL_SECONDS` | Dashboard Aktualisierungsrate | `30` |
|
||||
|
||||
### Volumes
|
||||
Vollständige Liste: siehe `docker-compose.yaml`
|
||||
|
||||
- `/app/persistence` - SQLite-Datenbank
|
||||
- `/app/wwwroot/downloads/sqlite` - Datenbank-Exports
|
||||
- `/app/logs` - Anwendungslogs
|
||||
#### Volumes
|
||||
|
||||
## 🔧 Entwicklung
|
||||
- `./data/db` → `/app/persistence` - SQLite-Datenbank
|
||||
- `./data/dumps` → `/app/wwwroot/downloads/sqlite` - Datenbank-Exports
|
||||
- `./data/logs` → `/app/logs` - Anwendungslogs
|
||||
|
||||
### Lokales Build
|
||||
#### Sicherheit
|
||||
|
||||
```bash
|
||||
# Dependencies wiederherstellen
|
||||
dotnet restore
|
||||
|
||||
# Build
|
||||
dotnet build --configuration Release
|
||||
|
||||
# Tests ausführen
|
||||
dotnet test
|
||||
|
||||
# Anwendung starten
|
||||
dotnet run --project Watcher
|
||||
```
|
||||
|
||||
### Docker-Build
|
||||
|
||||
```bash
|
||||
# Multi-Arch Build
|
||||
docker buildx build \
|
||||
--platform linux/amd64,linux/arm64 \
|
||||
-t watcher-server:latest \
|
||||
--push .
|
||||
```
|
||||
|
||||
## 📁 Projektstruktur
|
||||
|
||||
```
|
||||
/Watcher
|
||||
├── Controllers/ # MVC & API Controllers
|
||||
├── Models/ # Entity-Modelle
|
||||
├── Views/ # Razor-Templates
|
||||
├── Services/ # Background-Services & Stores
|
||||
├── Data/ # Entity Framework Context
|
||||
├── Migrations/ # EF Core Migrations
|
||||
├── ViewModels/ # View Models
|
||||
├── wwwroot/ # Statische Assets
|
||||
├── persistence/ # SQLite-Datenbank
|
||||
└── logs/ # Anwendungslogs
|
||||
```
|
||||
Der Container läuft als **non-root user** mit konfigurierbarer UID/GID:
|
||||
- Standard: `1000:1000`
|
||||
- Anpassbar über `USER_UID` und `USER_GID` in `.env`
|
||||
- Empfehlung: Eigene UID/GID verwenden für korrekte Dateiberechtigungen
|
||||
|
||||
## 📝 Lizenz
|
||||
|
||||
|
||||
@@ -27,6 +27,6 @@ public class ApiController : Controller
|
||||
public async Task<IActionResult> GetAllServers()
|
||||
{
|
||||
var Servers = await _context.Servers.OrderBy(s => s.Id).ToListAsync();
|
||||
return Ok();
|
||||
return Ok(Servers);
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,8 @@ public class MetricDto
|
||||
|
||||
public class DockerServiceDto
|
||||
{
|
||||
public required int Server_id { get; set; } // Vom Watcher-Server zugewiesene ID des Hosts
|
||||
public int Server_id { get; set; } // Vom Watcher-Server zugewiesene ID des Hosts (optional, falls der Agent diese bereits kennt)
|
||||
public string? IpAddress { get; set; } // IP-Adresse des Servers (wird verwendet, falls Server_id nicht gesetzt oder 0 ist)
|
||||
public required JsonElement Containers { get; set; }
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ public class MonitoringController : Controller
|
||||
}
|
||||
|
||||
|
||||
// Endpoint, an den der Agent seine Hardwareinformationen schickt
|
||||
// Endpoint, an den der Agent seine Hardwareinformationen schickt (Registrierung Schritt 2)
|
||||
[HttpPost("hardware-info")]
|
||||
public async Task<IActionResult> Register([FromBody] HardwareDto dto)
|
||||
{
|
||||
@@ -138,15 +139,19 @@ public class MonitoringController : Controller
|
||||
// Änderungen in Datenbank speichern
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// Success
|
||||
// Success - Server-ID und IP-Adresse zurückgeben
|
||||
_logger.LogInformation("Agent für '{server}' erfolgreich registriert.", server.Name);
|
||||
return Ok();
|
||||
return Ok(new
|
||||
{
|
||||
id = server.Id,
|
||||
ipAddress = server.IPAddress
|
||||
});
|
||||
}
|
||||
_logger.LogError("Kein Server für Registrierung gefunden");
|
||||
return NotFound("No Matching Server found.");
|
||||
}
|
||||
|
||||
// Endpoint, an dem sich ein Agent initial registriert
|
||||
// Endpoint, an dem sich ein Agent seine ID abholt (Registrierung Schritt 1)
|
||||
[HttpGet("register")]
|
||||
public async Task<IActionResult> GetServerIdByIp([FromQuery] string IpAddress)
|
||||
{
|
||||
@@ -180,17 +185,29 @@ public class MonitoringController : Controller
|
||||
return BadRequest(new { error = "Ungültiger Payload", details = errors });
|
||||
}
|
||||
|
||||
// Server in Datenbank finden
|
||||
var server = await _context.Servers
|
||||
.FirstOrDefaultAsync(s => s.IPAddress == dto.IpAddress);
|
||||
// Debug-Logging
|
||||
_logger.LogDebug("Metric Request empfangen: ServerId={ServerId}, IpAddress={IpAddress}",
|
||||
dto.ServerId, dto.IpAddress ?? "null");
|
||||
|
||||
if (server != null)
|
||||
// Server in Datenbank finden (priorisiert IP-Adresse, dann ID)
|
||||
_logger.LogInformation("ServerID: {ServerId}", dto.ServerId);
|
||||
var server = await FindServerByIpOrId(dto.ServerId);
|
||||
|
||||
if (server == null)
|
||||
{
|
||||
_logger.LogError("Kein Server mit IP '{IpAddress}' oder ID {ServerId} gefunden",
|
||||
dto.IpAddress, dto.ServerId);
|
||||
return NotFound(new {
|
||||
error = "Server not found",
|
||||
details = $"Server mit ID {dto.ServerId} existiert nicht. Bitte zuerst registrieren."
|
||||
});
|
||||
}
|
||||
|
||||
// neues Metric-Objekt erstellen
|
||||
var newMetric = new Metric
|
||||
{
|
||||
Timestamp = DateTime.UtcNow,
|
||||
ServerId = dto.ServerId,
|
||||
ServerId = server.Id, // Verwende die tatsächliche Server-ID aus der DB
|
||||
CPU_Load = SanitizeInput(dto.CPU_Load),
|
||||
CPU_Temp = SanitizeInput(dto.CPU_Temp),
|
||||
GPU_Load = SanitizeInput(dto.GPU_Load),
|
||||
@@ -205,29 +222,25 @@ public class MonitoringController : Controller
|
||||
NET_In = CalculateMegabit(dto.NET_In),
|
||||
NET_Out = CalculateMegabit(dto.NET_Out)
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
// Metric Objekt in Datenbank einfügen
|
||||
_context.Metrics.Add(newMetric);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
_logger.LogInformation("Monitoring-Daten für '{server}' empfangen", server.Name);
|
||||
_logger.LogInformation("Monitoring-Daten für Server '{ServerName}' (ID: {ServerId}) in Datenbank geschrieben",
|
||||
server.Name, server.Id);
|
||||
return Ok();
|
||||
}
|
||||
catch
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Alert triggern
|
||||
|
||||
_logger.LogError("Metric für {server} konnte nicht in Datenbank geschrieben werden.", server.Name);
|
||||
return BadRequest();
|
||||
_logger.LogError(ex, "Metric für Server '{ServerName}' (ID: {ServerId}) konnte nicht gespeichert werden",
|
||||
server.Name, server.Id);
|
||||
return StatusCode(500, new { error = "Database error", details = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogError("Kein Server für eingegangenen Monitoring-Payload gefunden");
|
||||
return NotFound("No Matching Server found.");
|
||||
|
||||
}
|
||||
|
||||
// Endpoint, an dem Agents Ihre laufenden Services registrieren
|
||||
[HttpPost("service-discovery")]
|
||||
public async Task<IActionResult> ServiceDetection([FromBody] DockerServiceDto dto)
|
||||
@@ -244,21 +257,33 @@ public class MonitoringController : Controller
|
||||
return BadRequest(new { error = "Invalid Payload", details = errors });
|
||||
}
|
||||
|
||||
// Prüfen, ob der Server existiert
|
||||
var serverExists = await _context.Servers.AnyAsync(s => s.Id == dto.Server_id);
|
||||
if (!serverExists)
|
||||
// Debug-Logging für eingehende Requests
|
||||
_logger.LogDebug("Service-Discovery Request empfangen: Server_id={ServerId}, IpAddress={IpAddress}",
|
||||
dto.Server_id, dto.IpAddress ?? "null");
|
||||
|
||||
// Server in Datenbank finden (priorisiert IP-Adresse, dann ID)
|
||||
var server = await FindServerByIpOrId(dto.Server_id);
|
||||
|
||||
if (server == null)
|
||||
{
|
||||
_logger.LogError($"Server with ID {dto.Server_id} does not exist.");
|
||||
return BadRequest(new { error = "Server not found", details = $"Server with ID {dto.Server_id} does not exist. Please register the server first." });
|
||||
_logger.LogError("Server with IP '{IpAddress}' or ID {ServerId} does not exist.",
|
||||
dto.IpAddress, dto.Server_id);
|
||||
return BadRequest(new {
|
||||
error = "Server not found",
|
||||
details = $"Server with IP '{dto.IpAddress}' or ID {dto.Server_id} does not exist. Please register the server first."
|
||||
});
|
||||
}
|
||||
|
||||
// Server ID für die weitere Verarbeitung setzen
|
||||
int serverId = server.Id;
|
||||
|
||||
List<Container> newContainers =
|
||||
JsonSerializer.Deserialize<List<Container>>(dto.Containers.GetRawText())
|
||||
?? new List<Container>();
|
||||
|
||||
foreach (Container container in newContainers)
|
||||
{
|
||||
container.ServerId = dto.Server_id;
|
||||
container.ServerId = serverId;
|
||||
// Debug Logs
|
||||
// TODO entfernen wenn fertig getestet
|
||||
Console.WriteLine("---------");
|
||||
@@ -272,7 +297,7 @@ public class MonitoringController : Controller
|
||||
|
||||
// Liste aller Container, die bereits der übergebenen ServerId zugewiesen sind
|
||||
List<Container> existingContainers = _context.Containers
|
||||
.Where(c => c.ServerId == dto.Server_id)
|
||||
.Where(c => c.ServerId == serverId)
|
||||
.ToList();
|
||||
|
||||
|
||||
@@ -291,7 +316,7 @@ public class MonitoringController : Controller
|
||||
existingContainer.Image = container.Image;
|
||||
existingContainer.IsRunning = true;
|
||||
|
||||
_logger.LogInformation("Container '{containerName}' (ID: {containerId}) already exists for Server {serverId}, updated.", container.Name, container.ContainerId, dto.Server_id);
|
||||
_logger.LogInformation("Container '{containerName}' (ID: {containerId}) already exists for Server {serverId}, updated.", container.Name, container.ContainerId, serverId);
|
||||
}
|
||||
// Container auf einen Host/Server registrieren
|
||||
else
|
||||
@@ -393,6 +418,7 @@ public class MonitoringController : Controller
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet("cpu-usage")]
|
||||
public async Task<IActionResult> GetCpuUsageData(int serverId, int hours = 1)
|
||||
{
|
||||
@@ -413,6 +439,7 @@ public class MonitoringController : Controller
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet("ram-usage")]
|
||||
public async Task<IActionResult> GetRamUsageData(int serverId, int hours = 1)
|
||||
{
|
||||
@@ -433,6 +460,7 @@ public class MonitoringController : Controller
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet("gpu-usage")]
|
||||
public async Task<IActionResult> GetGpuUsageData(int serverId, int hours = 1)
|
||||
{
|
||||
@@ -453,6 +481,7 @@ public class MonitoringController : Controller
|
||||
return Ok(data);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpGet("current-metrics/{serverId}")]
|
||||
public async Task<IActionResult> GetCurrentMetrics(int serverId)
|
||||
{
|
||||
@@ -509,9 +538,41 @@ public class MonitoringController : Controller
|
||||
// Degree Input auf zwei Nachkommastellen runden
|
||||
public static double SanitizeInput(double metricInput)
|
||||
{
|
||||
Math.Round(metricInput, 2);
|
||||
return Math.Round(metricInput, 2);
|
||||
}
|
||||
|
||||
// ==================== HELPER METHODS ====================
|
||||
|
||||
/// <summary>
|
||||
/// Findet einen Server anhand IP-Adresse oder ID.
|
||||
/// Priorisiert IP-Adresse, fällt dann auf ID zurück.
|
||||
/// </summary>
|
||||
/// <param name="ipAddress">IP-Adresse des Servers (bevorzugt)</param>
|
||||
/// <param name="serverId">Server-ID (Fallback)</param>
|
||||
/// <returns>Server-Objekt oder null wenn nicht gefunden</returns>
|
||||
private async Task<Server> FindServerByIpOrId(int serverId)
|
||||
{
|
||||
// WICHTIG: >= 0 da Server-IDs bei 0 starten können
|
||||
if (serverId >= 0)
|
||||
{
|
||||
var server = await _context.Servers
|
||||
.FirstOrDefaultAsync(s => s.Id == serverId);
|
||||
|
||||
if (server != null)
|
||||
{
|
||||
_logger.LogDebug("Server gefunden via ID: {ServerName}", server.Name);
|
||||
return server;
|
||||
} else {
|
||||
// Server nicht gefunden
|
||||
_logger.LogWarning("Server nicht gefunden: ID={ServerId}", serverId);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
_logger.LogWarning("Ungültige ID abgefragt!");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return metricInput;
|
||||
}
|
||||
|
||||
private List<Container> ParseServiceDiscoveryInput(int serverId, List<Container> containers)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Watcher.Data;
|
||||
using Watcher.ViewModels;
|
||||
|
||||
@@ -20,12 +21,12 @@ public class UserController : Controller
|
||||
|
||||
// Anzeigen der User-Informationen
|
||||
[Authorize]
|
||||
public IActionResult Info()
|
||||
public async Task<IActionResult> Info()
|
||||
{
|
||||
var claims = User.Claims.Select(c => new { c.Type, c.Value }).ToList();
|
||||
var Identity_User = User.Identity?.Name;
|
||||
|
||||
var user = _context.Users.FirstOrDefault(u => u.Username == Identity_User);
|
||||
var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == Identity_User);
|
||||
if (user == null) return NotFound();
|
||||
|
||||
// Anzeigedaten
|
||||
@@ -47,10 +48,10 @@ public class UserController : Controller
|
||||
// Edit-Form anzeigen
|
||||
[Authorize]
|
||||
[HttpGet]
|
||||
public IActionResult Edit()
|
||||
public async Task<IActionResult> Edit()
|
||||
{
|
||||
var username = User.Identity?.Name;
|
||||
var user = _context.Users.FirstOrDefault(u => u.Username == username);
|
||||
var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == username);
|
||||
if (user == null) return NotFound();
|
||||
|
||||
|
||||
@@ -65,12 +66,12 @@ public class UserController : Controller
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public IActionResult Edit(EditUserViewModel model)
|
||||
public async Task<IActionResult> Edit(EditUserViewModel model)
|
||||
{
|
||||
if (!ModelState.IsValid) return View(model);
|
||||
|
||||
var username = User.Identity?.Name;
|
||||
var user = _context.Users.FirstOrDefault(u => u.Username == username);
|
||||
var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == username);
|
||||
if (user == null) return NotFound();
|
||||
|
||||
user.Username = model.Username;
|
||||
@@ -80,7 +81,7 @@ public class UserController : Controller
|
||||
user.Password = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);
|
||||
}
|
||||
|
||||
_context.SaveChanges();
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// Eventuell hier das Auth-Cookie erneuern, wenn Username sich ändert
|
||||
|
||||
@@ -93,12 +94,12 @@ public class UserController : Controller
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public IActionResult UserSettings(EditUserViewModel model)
|
||||
public async Task<IActionResult> UserSettings(EditUserViewModel model)
|
||||
{
|
||||
if (!ModelState.IsValid) return View(model);
|
||||
|
||||
var username = User.Identity?.Name;
|
||||
var user = _context.Users.FirstOrDefault(u => u.Username == username);
|
||||
var user = await _context.Users.FirstOrDefaultAsync(u => u.Username == username);
|
||||
if (user == null) return NotFound();
|
||||
|
||||
var databaseProvider = _context.Database.ProviderName;
|
||||
@@ -108,10 +109,10 @@ public class UserController : Controller
|
||||
// Passwort ändern
|
||||
if (!string.IsNullOrWhiteSpace(model.NewPassword))
|
||||
{
|
||||
user.Username = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);
|
||||
user.Password = BCrypt.Net.BCrypt.HashPassword(model.NewPassword);
|
||||
}
|
||||
|
||||
_context.SaveChanges();
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
// Eventuell hier das Auth-Cookie erneuern, wenn Username sich ändert
|
||||
|
||||
|
||||
@@ -41,5 +41,19 @@ public class AppDbContext : DbContext
|
||||
optionsBuilder.UseSqlite(connStr);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
// Server IDs bei 0 starten lassen (statt Standard 1)
|
||||
modelBuilder.Entity<Server>()
|
||||
.Property(s => s.Id)
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
// SQLite-spezifische Konfiguration: AUTOINCREMENT startet bei 0
|
||||
modelBuilder.Entity<Server>()
|
||||
.ToTable(tb => tb.HasCheckConstraint("CK_Server_Id", "Id >= 0"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
395
Watcher/Migrations/20251117142850_StartServerIdsAtZero.Designer.cs
generated
Normal file
395
Watcher/Migrations/20251117142850_StartServerIdsAtZero.Designer.cs
generated
Normal file
@@ -0,0 +1,395 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Watcher.Data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Watcher.Migrations
|
||||
{
|
||||
[DbContext(typeof(AppDbContext))]
|
||||
[Migration("20251117142850_StartServerIdsAtZero")]
|
||||
partial class StartServerIdsAtZero
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.6");
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Container", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ContainerId")
|
||||
.HasColumnType("TEXT")
|
||||
.HasAnnotation("Relational:JsonPropertyName", "id");
|
||||
|
||||
b.Property<string>("Image")
|
||||
.HasColumnType("TEXT")
|
||||
.HasAnnotation("Relational:JsonPropertyName", "image");
|
||||
|
||||
b.Property<int?>("ImageId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsRunning")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT")
|
||||
.HasAnnotation("Relational:JsonPropertyName", "name");
|
||||
|
||||
b.Property<int>("ServerId")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasAnnotation("Relational:JsonPropertyName", "Server_id");
|
||||
|
||||
b.Property<int?>("TagId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ImageId");
|
||||
|
||||
b.HasIndex("ServerId");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("Containers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.ContainerMetric", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("CPU_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int?>("ContainerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("RAM_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("ContainerMetrics");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Image", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Tag")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Images");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int?>("ContainerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Level")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Message")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ContainerId");
|
||||
|
||||
b.HasIndex("ServerId");
|
||||
|
||||
b.ToTable("LogEvents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Metric", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("CPU_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CPU_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DISK_Usage")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Temp")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Vram_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GPU_Vram_Usage")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("NET_In")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("NET_Out")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Load")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RAM_Size")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int?>("ServerId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Metrics");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Server", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("CpuCores")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<double>("CpuLoadCritical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CpuLoadWarning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CpuTempCritical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("CpuTempWarning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<string>("CpuType")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("CreatedAt")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("DiskSpace")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("DiskTempCritical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DiskTempWarning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DiskUsageCritical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("DiskUsageWarning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GpuLoadCritical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GpuLoadWarning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GpuTempCritical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("GpuTempWarning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<string>("GpuType")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("IPAddress")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<bool>("IsOnline")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<bool>("IsVerified")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("LastSeen")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<double>("RamLoadCritical")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RamLoadWarning")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<double>("RamSize")
|
||||
.HasColumnType("REAL");
|
||||
|
||||
b.Property<int?>("TagId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("Servers", t =>
|
||||
{
|
||||
t.HasCheckConstraint("CK_Server_Id", "Id >= 0");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Tag", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Tags");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("LastLogin")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Container", b =>
|
||||
{
|
||||
b.HasOne("Watcher.Models.Image", null)
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("ImageId");
|
||||
|
||||
b.HasOne("Watcher.Models.Server", "Server")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Watcher.Models.Tag", null)
|
||||
.WithMany("Containers")
|
||||
.HasForeignKey("TagId");
|
||||
|
||||
b.Navigation("Server");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.LogEvent", b =>
|
||||
{
|
||||
b.HasOne("Watcher.Models.Container", "Container")
|
||||
.WithMany()
|
||||
.HasForeignKey("ContainerId");
|
||||
|
||||
b.HasOne("Watcher.Models.Server", "Server")
|
||||
.WithMany()
|
||||
.HasForeignKey("ServerId");
|
||||
|
||||
b.Navigation("Container");
|
||||
|
||||
b.Navigation("Server");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Server", b =>
|
||||
{
|
||||
b.HasOne("Watcher.Models.Tag", null)
|
||||
.WithMany("Servers")
|
||||
.HasForeignKey("TagId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Image", b =>
|
||||
{
|
||||
b.Navigation("Containers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Tag", b =>
|
||||
{
|
||||
b.Navigation("Containers");
|
||||
|
||||
b.Navigation("Servers");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
43
Watcher/Migrations/20251117142850_StartServerIdsAtZero.cs
Normal file
43
Watcher/Migrations/20251117142850_StartServerIdsAtZero.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Watcher.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class StartServerIdsAtZero : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "CK_Server_Id",
|
||||
table: "Servers",
|
||||
sql: "Id >= 0");
|
||||
|
||||
// Bestehende Server-IDs um 1 verringern (1 -> 0, 2 -> 1, etc.)
|
||||
migrationBuilder.Sql(@"
|
||||
-- Bestehende Server-IDs anpassen, falls Server existieren
|
||||
UPDATE Servers SET Id = Id - 1 WHERE EXISTS (SELECT 1 FROM Servers);
|
||||
UPDATE Metrics SET ServerId = ServerId - 1 WHERE ServerId IS NOT NULL;
|
||||
UPDATE Containers SET ServerId = ServerId - 1 WHERE ServerId IS NOT NULL;
|
||||
|
||||
-- sqlite_sequence anpassen oder initialisieren
|
||||
-- Falls Eintrag existiert: seq - 1, ansonsten: INSERT mit seq = -1
|
||||
-- Der nächste AUTOINCREMENT wird dann 0 sein
|
||||
INSERT OR REPLACE INTO sqlite_sequence (name, seq)
|
||||
VALUES ('Servers',
|
||||
COALESCE((SELECT seq - 1 FROM sqlite_sequence WHERE name = 'Servers'), -1)
|
||||
);
|
||||
");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "CK_Server_Id",
|
||||
table: "Servers");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,7 +288,10 @@ namespace Watcher.Migrations
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("Servers");
|
||||
b.ToTable("Servers", t =>
|
||||
{
|
||||
t.HasCheckConstraint("CK_Server_Id", "Id >= 0");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Watcher.Models.Tag", b =>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
services:
|
||||
watcher:
|
||||
image: git.triggermeelmo.com/watcher/watcher-server:${IMAGE_VERSION:-latest}
|
||||
image: git.triggermeelmo.com/watcher/watcher-server:latest
|
||||
container_name: watcher
|
||||
|
||||
# Resource Management
|
||||
@@ -9,14 +9,11 @@ services:
|
||||
limits:
|
||||
memory: 200M
|
||||
cpus: '0.5'
|
||||
reservations:
|
||||
memory: 100M
|
||||
cpus: '0.25'
|
||||
|
||||
restart: unless-stopped
|
||||
|
||||
# Security
|
||||
user: "1000:1000"
|
||||
# Security - User/Group ID aus Umgebungsvariablen
|
||||
user: "${USER_UID:-1000}:${USER_GID:-1000}"
|
||||
|
||||
# Health Check
|
||||
healthcheck:
|
||||
@@ -28,16 +25,13 @@ services:
|
||||
|
||||
# Environment
|
||||
environment:
|
||||
# Non-Root User
|
||||
- USER_UID=1000 # Standard 1000
|
||||
- USER_GID=1000 # Standard 1000
|
||||
|
||||
# Timezone
|
||||
- TZ=Europe/Berlin
|
||||
|
||||
# Application Version (wird aus Image-Tag übernommen)
|
||||
- WATCHER_VERSION=${IMAGE_VERSION:-latest}
|
||||
|
||||
# ASP.NET Core
|
||||
- ASPNETCORE_ENVIRONMENT=Production
|
||||
- ASPNETCORE_URLS=http://+:5000
|
||||
|
||||
# Update Check
|
||||
- UPDATE_CHECK_ENABLED=true
|
||||
- UPDATE_CHECK_INTERVAL_HOURS=24
|
||||
|
||||
Reference in New Issue
Block a user