Compare commits
2 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
30a72f5fa3 | |
|
|
c50e0d7c47 |
|
|
@ -19,13 +19,12 @@ ENV/
|
||||||
data/*.db
|
data/*.db
|
||||||
data/*.log
|
data/*.log
|
||||||
data/backup.db
|
data/backup.db
|
||||||
|
logs/*.log
|
||||||
|
logs/*.log.*
|
||||||
|
|
||||||
# Sensitive Config (optional - keep structure but remove secrets)
|
# Sensitive Config (optional - keep structure but remove secrets)
|
||||||
# config/config.yaml
|
# config/config.yaml
|
||||||
|
|
||||||
# Docker
|
|
||||||
*.log
|
|
||||||
|
|
||||||
# OS
|
# OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,144 @@
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
Alle wichtigen Änderungen an diesem Projekt werden in dieser Datei dokumentiert.
|
||||||
|
|
||||||
|
Das Format basiert auf [Keep a Changelog](https://keepachangelog.com/de/1.0.0/).
|
||||||
|
|
||||||
|
## Versionierung
|
||||||
|
|
||||||
|
- **Große Änderungen** (neue Features, Breaking Changes): +0.1 (z.B. 0.1 → 0.2)
|
||||||
|
- **Kleine Änderungen** (Bugfixes, kleinere Verbesserungen): +0.0.1 (z.B. 0.1 → 0.1.1)
|
||||||
|
- **Major Release** (1.x): Nur auf Anweisung
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
### In Arbeit
|
||||||
|
- Entwicklung läuft im `develop` Branch
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## [0.1.1] - 2026-02-16
|
||||||
|
|
||||||
|
### Changed - Verbesserte Funktionalität
|
||||||
|
|
||||||
|
- 📝 **Verbessertes Logging-System**
|
||||||
|
- Separates `logs/` Verzeichnis (statt `data/`)
|
||||||
|
- Automatische Log-Rotation mit `RotatingFileHandler`
|
||||||
|
- Maximale Größe: 10 MB pro Datei
|
||||||
|
- Backup-Count: 5 Dateien
|
||||||
|
- Separate Error-Logs (`error.log`) mit vollständigem Traceback
|
||||||
|
- Konfigurierbare Log-Größe und Rotation in `config.yaml`
|
||||||
|
- Bessere Console-Ausgabe (kürzeres Format)
|
||||||
|
|
||||||
|
### Technical Details
|
||||||
|
- `app/main.py`: Implementierung von RotatingFileHandler
|
||||||
|
- `config/config.yaml`: Neue Logging-Optionen (max_bytes, backup_count, error_file)
|
||||||
|
- `docker-compose.yml`: Volume-Mapping für logs/ Verzeichnis
|
||||||
|
- `.gitignore`: Log-Dateien und Rotationen ausgeschlossen
|
||||||
|
|
||||||
|
### Dateien
|
||||||
|
```
|
||||||
|
logs/
|
||||||
|
├── watchdog.log # Haupt-Log (alle Meldungen)
|
||||||
|
├── watchdog.log.1-5 # Rotierte Backups
|
||||||
|
├── error.log # Error-Log (nur Fehler)
|
||||||
|
└── error.log.1-5 # Rotierte Error-Backups
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## [0.1.0] - 2024-02-16
|
||||||
|
|
||||||
|
### Added - Neue Features
|
||||||
|
- ✨ **OPNsense Monitoring System** - Vollständiges Monitoring-System
|
||||||
|
- DHCP Lease Überwachung (filterbar nach Interface)
|
||||||
|
- Neue Geräte Erkennung via ARP (mit Known-Devices Abgleich)
|
||||||
|
- Interface Status Monitoring (up/down)
|
||||||
|
- Gateway Status Monitoring
|
||||||
|
|
||||||
|
- 🖥️ **Web Dashboard**
|
||||||
|
- Login-System mit Passwort-Schutz (Flask-Login)
|
||||||
|
- Responsive Bootstrap 5 Interface
|
||||||
|
- Echtzeit Event-Tabelle mit Auto-Refresh (10s)
|
||||||
|
- Filterung nach Event-Typ und Interface
|
||||||
|
- Statistik-Übersicht (Gesamt, Heute, Letzte Stunde, Bekannte Geräte)
|
||||||
|
|
||||||
|
- 📧 **E-Mail Benachrichtigungen**
|
||||||
|
- SMTP Support mit TLS
|
||||||
|
- HTML-formatierte E-Mails
|
||||||
|
- Event-spezifische Templates
|
||||||
|
- Startup-Benachrichtigung
|
||||||
|
- Intelligente Filterung (nur unbekannte Geräte bei new_device)
|
||||||
|
|
||||||
|
- 💾 **SQLite Datenbank**
|
||||||
|
- Events Tabelle mit vollständiger Event-Historie
|
||||||
|
- Known Devices Tabelle (auto-populated)
|
||||||
|
- Automatische Retention (alte Events löschen)
|
||||||
|
- Indizierung für schnelle Queries
|
||||||
|
|
||||||
|
- 🔧 **Konfiguration**
|
||||||
|
- Vollständig über `config/config.yaml` konfigurierbar
|
||||||
|
- OPNsense API Integration
|
||||||
|
- Monitoring-Intervall anpassbar
|
||||||
|
- Interface-Filterung
|
||||||
|
- Event-Toggles (einzeln an/ausschaltbar)
|
||||||
|
|
||||||
|
- 🐳 **Docker Support**
|
||||||
|
- Dockerfile mit Python 3.11-slim
|
||||||
|
- docker-compose.yml mit Healthcheck
|
||||||
|
- Volume-Mapping für config & data
|
||||||
|
- Auto-Restart
|
||||||
|
|
||||||
|
- 📚 **Dokumentation**
|
||||||
|
- Vollständige README mit Setup-Anleitung
|
||||||
|
- OPNsense API Setup Guide
|
||||||
|
- Troubleshooting Sektion
|
||||||
|
- CLAUDE.md für KI-assistierte Entwicklung
|
||||||
|
|
||||||
|
### Technical Details
|
||||||
|
- **Backend:** Python 3.11, Flask 3.0.0, APScheduler 3.10.4
|
||||||
|
- **Database:** SQLite mit JSON-Support
|
||||||
|
- **Frontend:** Bootstrap 5, Vanilla JavaScript
|
||||||
|
- **API Client:** Requests mit OPNsense REST API
|
||||||
|
- **Auth:** Flask-Login mit Werkzeug password hashing
|
||||||
|
- **Email:** SMTP mit HTML/MIME multipart
|
||||||
|
|
||||||
|
### Initial Files
|
||||||
|
```
|
||||||
|
watchdog-docker/
|
||||||
|
├── Dockerfile
|
||||||
|
├── docker-compose.yml
|
||||||
|
├── requirements.txt
|
||||||
|
├── README.md
|
||||||
|
├── CHANGELOG.md
|
||||||
|
├── CLAUDE.md
|
||||||
|
├── .gitignore
|
||||||
|
├── config/
|
||||||
|
│ └── config.yaml
|
||||||
|
├── app/
|
||||||
|
│ ├── main.py
|
||||||
|
│ ├── opnsense_api.py
|
||||||
|
│ ├── monitor.py
|
||||||
|
│ ├── database.py
|
||||||
|
│ ├── email_handler.py
|
||||||
|
│ └── templates/
|
||||||
|
│ ├── login.html
|
||||||
|
│ └── dashboard.html
|
||||||
|
└── data/
|
||||||
|
└── .gitkeep
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Legende
|
||||||
|
|
||||||
|
- **Added** - Neue Features
|
||||||
|
- **Changed** - Änderungen an bestehender Funktionalität
|
||||||
|
- **Deprecated** - Bald zu entfernende Features
|
||||||
|
- **Removed** - Entfernte Features
|
||||||
|
- **Fixed** - Bugfixes
|
||||||
|
- **Security** - Sicherheits-Fixes
|
||||||
|
|
||||||
|
[Unreleased]: https://tea.ffw-ak-ff.de/FFW-VG-AK-FF/watchdog-docker/compare/v0.1.1...HEAD
|
||||||
|
[0.1.1]: https://tea.ffw-ak-ff.de/FFW-VG-AK-FF/watchdog-docker/compare/v0.1.0...v0.1.1
|
||||||
|
[0.1.0]: https://tea.ffw-ak-ff.de/FFW-VG-AK-FF/watchdog-docker/releases/tag/v0.1.0
|
||||||
32
CLAUDE.md
32
CLAUDE.md
|
|
@ -4,7 +4,10 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
||||||
|
|
||||||
## Project Overview
|
## Project Overview
|
||||||
|
|
||||||
Watchdog Docker v0.1 - OPNsense monitoring system with web dashboard and email notifications. Monitors DHCP leases, new devices (ARP), interface status changes, and gateway status changes.
|
Watchdog Docker - OPNsense monitoring system with web dashboard and email notifications. Monitors DHCP leases, new devices (ARP), interface status changes, and gateway status changes.
|
||||||
|
|
||||||
|
**Current Version:** See [VERSION](VERSION) file
|
||||||
|
**Changelog:** [CHANGELOG.md](CHANGELOG.md)
|
||||||
|
|
||||||
## Tech Stack
|
## Tech Stack
|
||||||
|
|
||||||
|
|
@ -81,8 +84,10 @@ python -c "from werkzeug.security import generate_password_hash; print(generate_
|
||||||
|
|
||||||
## Key Files
|
## Key Files
|
||||||
|
|
||||||
|
- **VERSION** - Current version number (single source of truth)
|
||||||
|
- **CHANGELOG.md** - Complete version history and changes
|
||||||
- **config/config.yaml** - ALL settings (OPNsense, monitoring, web, email, database)
|
- **config/config.yaml** - ALL settings (OPNsense, monitoring, web, email, database)
|
||||||
- **app/main.py** - Flask app entry point
|
- **app/main.py** - Flask app entry point (loads VERSION file)
|
||||||
- **app/monitor.py** - Core monitoring logic with state tracking
|
- **app/monitor.py** - Core monitoring logic with state tracking
|
||||||
- **app/database.py** - SQLite operations
|
- **app/database.py** - SQLite operations
|
||||||
- **app/email_handler.py** - Email notifications with HTML templates
|
- **app/email_handler.py** - Email notifications with HTML templates
|
||||||
|
|
@ -97,7 +102,7 @@ All settings in `config/config.yaml`:
|
||||||
- Web port, secret key, admin password hash
|
- Web port, secret key, admin password hash
|
||||||
- SMTP settings, recipients
|
- SMTP settings, recipients
|
||||||
- Database path, retention days
|
- Database path, retention days
|
||||||
- Logging level
|
- **Logging:** level (DEBUG/INFO/WARNING/ERROR), file paths, rotation settings
|
||||||
|
|
||||||
## Important Notes
|
## Important Notes
|
||||||
|
|
||||||
|
|
@ -107,6 +112,27 @@ All settings in `config/config.yaml`:
|
||||||
- **Email Logic:** Only send emails for unknown devices (new_device event with known=False)
|
- **Email Logic:** Only send emails for unknown devices (new_device event with known=False)
|
||||||
- **Retention:** Old events auto-cleanup based on retention_days (default 90)
|
- **Retention:** Old events auto-cleanup based on retention_days (default 90)
|
||||||
- **Password:** Admin password must be werkzeug scrypt hash in config.yaml
|
- **Password:** Admin password must be werkzeug scrypt hash in config.yaml
|
||||||
|
- **Logging:** Uses RotatingFileHandler with separate main log and error log, auto-rotation at 10MB
|
||||||
|
|
||||||
|
## Versioning
|
||||||
|
|
||||||
|
### Version Schema
|
||||||
|
- **Big changes** (new features, breaking changes): +0.1 (e.g., 0.1.0 → 0.2.0)
|
||||||
|
- **Small changes** (bugfixes, minor improvements): +0.0.1 (e.g., 0.1.0 → 0.1.1)
|
||||||
|
- **Major release** (1.x): Only on instruction
|
||||||
|
|
||||||
|
### Git Workflow
|
||||||
|
- **main** - Stable releases only
|
||||||
|
- **develop** - Active development (current working branch)
|
||||||
|
- Feature branches for larger features
|
||||||
|
|
||||||
|
### Making Changes
|
||||||
|
1. Work in `develop` branch
|
||||||
|
2. Update VERSION file with new version number
|
||||||
|
3. Update CHANGELOG.md with changes (follow Keep a Changelog format)
|
||||||
|
4. Commit changes with descriptive message
|
||||||
|
5. Push to develop
|
||||||
|
6. Merge to main when stable and tested
|
||||||
|
|
||||||
## Code Style
|
## Code Style
|
||||||
|
|
||||||
|
|
|
||||||
112
README.md
112
README.md
|
|
@ -1,7 +1,9 @@
|
||||||
# Watchdog Docker v0.1
|
# Watchdog Docker
|
||||||
|
|
||||||
Docker Container für OPNsense Monitoring mit Web-Interface und E-Mail-Benachrichtigungen.
|
Docker Container für OPNsense Monitoring mit Web-Interface und E-Mail-Benachrichtigungen.
|
||||||
|
|
||||||
|
**Aktuelle Version:** Siehe [VERSION](VERSION) | **Changelog:** [CHANGELOG.md](CHANGELOG.md)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- 🔍 **DHCP Lease Monitoring** - Überwachung neuer IP-Vergaben
|
- 🔍 **DHCP Lease Monitoring** - Überwachung neuer IP-Vergaben
|
||||||
|
|
@ -151,6 +153,8 @@ watchdog-docker/
|
||||||
├── docker-compose.yml # Docker Compose Konfiguration
|
├── docker-compose.yml # Docker Compose Konfiguration
|
||||||
├── requirements.txt # Python Dependencies
|
├── requirements.txt # Python Dependencies
|
||||||
├── README.md # Diese Datei
|
├── README.md # Diese Datei
|
||||||
|
├── VERSION # Aktuelle Version
|
||||||
|
├── CHANGELOG.md # Versionshistorie
|
||||||
├── config/
|
├── config/
|
||||||
│ └── config.yaml # Hauptkonfiguration
|
│ └── config.yaml # Hauptkonfiguration
|
||||||
├── app/
|
├── app/
|
||||||
|
|
@ -162,9 +166,12 @@ watchdog-docker/
|
||||||
│ └── templates/
|
│ └── templates/
|
||||||
│ ├── login.html # Login-Seite
|
│ ├── login.html # Login-Seite
|
||||||
│ └── dashboard.html # Dashboard
|
│ └── dashboard.html # Dashboard
|
||||||
└── data/ # Auto-generiert beim ersten Start
|
├── data/ # Datenbank (auto-generiert)
|
||||||
├── watchdog.db # SQLite Datenbank
|
│ └── watchdog.db # SQLite Datenbank
|
||||||
└── watchdog.log # Log-Datei
|
└── logs/ # Log-Dateien (auto-generiert)
|
||||||
|
├── watchdog.log # Haupt-Log (mit Rotation)
|
||||||
|
├── error.log # Error-Log (nur Fehler)
|
||||||
|
└── *.log.* # Rotierte Backups (bis zu 5 pro Typ)
|
||||||
```
|
```
|
||||||
|
|
||||||
## API Endpoints
|
## API Endpoints
|
||||||
|
|
@ -229,13 +236,66 @@ Jede E-Mail enthält:
|
||||||
- IP, MAC, Hostname (bei Geräten)
|
- IP, MAC, Hostname (bei Geräten)
|
||||||
- Detaillierte Beschreibung
|
- Detaillierte Beschreibung
|
||||||
|
|
||||||
|
## Logging-System
|
||||||
|
|
||||||
|
### Log-Dateien
|
||||||
|
|
||||||
|
Das System erstellt separate Log-Dateien im `logs/` Verzeichnis:
|
||||||
|
|
||||||
|
| Datei | Inhalt | Log-Level |
|
||||||
|
|-------|--------|-----------|
|
||||||
|
| `watchdog.log` | Alle Meldungen (INFO, WARNING, ERROR) | Konfigurierbar |
|
||||||
|
| `error.log` | Nur Fehler mit vollständigem Traceback | ERROR + |
|
||||||
|
|
||||||
|
### Automatische Log-Rotation
|
||||||
|
|
||||||
|
- **Maximale Größe:** 10 MB pro Log-Datei
|
||||||
|
- **Backup-Count:** 5 rotierte Dateien
|
||||||
|
- **Gesamt:** ~50 MB pro Log-Typ (6 Dateien inkl. aktuellem)
|
||||||
|
|
||||||
|
Alte Logs werden automatisch als `.log.1`, `.log.2`, etc. archiviert.
|
||||||
|
|
||||||
|
### Log-Level Konfiguration
|
||||||
|
|
||||||
|
In `config/config.yaml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
logging:
|
||||||
|
level: "INFO" # Optionen: DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||||
|
```
|
||||||
|
|
||||||
|
**Empfohlene Einstellungen:**
|
||||||
|
- **Produktion:** `INFO` - Normale Betriebsmeldungen
|
||||||
|
- **Debugging:** `DEBUG` - Detaillierte Informationen für Fehlersuche
|
||||||
|
- **Minimal:** `WARNING` - Nur Warnungen und Fehler
|
||||||
|
|
||||||
|
### Log-Ansicht
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Aktuelle Logs ansehen
|
||||||
|
tail -f logs/watchdog.log
|
||||||
|
|
||||||
|
# Nur Fehler ansehen
|
||||||
|
tail -f logs/error.log
|
||||||
|
|
||||||
|
# Docker Logs (Container)
|
||||||
|
docker-compose logs -f watchdog
|
||||||
|
|
||||||
|
# Letzte 100 Zeilen
|
||||||
|
tail -n 100 logs/watchdog.log
|
||||||
|
```
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
### Container startet nicht
|
### Container startet nicht
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Logs prüfen
|
# Container Logs prüfen
|
||||||
docker-compose logs
|
docker-compose logs -f
|
||||||
|
|
||||||
|
# Lokale Log-Dateien prüfen
|
||||||
|
tail -f logs/watchdog.log
|
||||||
|
tail -f logs/error.log
|
||||||
|
|
||||||
# Container Status
|
# Container Status
|
||||||
docker-compose ps
|
docker-compose ps
|
||||||
|
|
@ -291,6 +351,11 @@ docker-compose ps
|
||||||
logging:
|
logging:
|
||||||
level: "DEBUG"
|
level: "DEBUG"
|
||||||
```
|
```
|
||||||
|
Danach Container neu starten und Logs prüfen:
|
||||||
|
```bash
|
||||||
|
docker-compose restart
|
||||||
|
tail -f logs/watchdog.log
|
||||||
|
```
|
||||||
|
|
||||||
## Update
|
## Update
|
||||||
|
|
||||||
|
|
@ -334,6 +399,34 @@ cp config/config.yaml config/config.yaml.backup
|
||||||
- ⚠️ Verwende HTTPS für das Web-Interface (z.B. mit Reverse Proxy)
|
- ⚠️ Verwende HTTPS für das Web-Interface (z.B. mit Reverse Proxy)
|
||||||
- ⚠️ Speichere keine API-Secrets in Git (nutze `.env` Dateien)
|
- ⚠️ Speichere keine API-Secrets in Git (nutze `.env` Dateien)
|
||||||
|
|
||||||
|
## Versionierung & Entwicklung
|
||||||
|
|
||||||
|
### Versionsschema
|
||||||
|
|
||||||
|
Das Projekt folgt einem angepassten Semantic Versioning Schema:
|
||||||
|
|
||||||
|
- **Große Änderungen** (neue Features, Breaking Changes): **+0.1**
|
||||||
|
- Beispiel: `0.1.0` → `0.2.0`
|
||||||
|
- Trigger: Neue Monitoring-Features, API-Änderungen, UI-Redesign
|
||||||
|
|
||||||
|
- **Kleine Änderungen** (Bugfixes, kleinere Verbesserungen): **+0.0.1**
|
||||||
|
- Beispiel: `0.1.0` → `0.1.1`
|
||||||
|
- Trigger: Bugfixes, Performance-Verbesserungen, Dokumentations-Updates
|
||||||
|
|
||||||
|
- **Major Release** (1.x): **Nur auf Anweisung**
|
||||||
|
- Production-Ready Status
|
||||||
|
- Vollständig getestet und stabil
|
||||||
|
|
||||||
|
### Git Workflow
|
||||||
|
|
||||||
|
- **`main`** - Stable Release Branch (nur getestete Versionen)
|
||||||
|
- **`develop`** - Development Branch (aktive Entwicklung)
|
||||||
|
- **Feature Branches** - Für größere Features (`feature/feature-name`)
|
||||||
|
|
||||||
|
### Changelog
|
||||||
|
|
||||||
|
Alle Änderungen werden in [CHANGELOG.md](CHANGELOG.md) dokumentiert. Das Format folgt [Keep a Changelog](https://keepachangelog.com/de/1.0.0/).
|
||||||
|
|
||||||
## Entwicklung
|
## Entwicklung
|
||||||
|
|
||||||
### Lokale Entwicklung ohne Docker
|
### Lokale Entwicklung ohne Docker
|
||||||
|
|
@ -374,9 +467,4 @@ MIT License
|
||||||
|
|
||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
### v0.1 (Initial Release)
|
Siehe [CHANGELOG.md](CHANGELOG.md) für vollständige Versionshistorie.
|
||||||
- OPNsense Monitoring (DHCP, Devices, Interfaces, Gateways)
|
|
||||||
- Web Dashboard mit Echtzeit-Updates
|
|
||||||
- E-Mail Benachrichtigungen
|
|
||||||
- SQLite Datenbank
|
|
||||||
- Docker Support
|
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,6 @@ class EmailHandler:
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<p><strong>Status:</strong> Aktiv</p>
|
<p><strong>Status:</strong> Aktiv</p>
|
||||||
<p><strong>Zeitpunkt:</strong> {datetime.now().strftime('%d.%m.%Y %H:%M:%S')}</p>
|
<p><strong>Zeitpunkt:</strong> {datetime.now().strftime('%d.%m.%Y %H:%M:%S')}</p>
|
||||||
<p><strong>Version:</strong> 0.1</p>
|
|
||||||
<hr>
|
<hr>
|
||||||
<p>OPNsense Monitoring ist aktiv und überwacht folgende Events:</p>
|
<p>OPNsense Monitoring ist aktiv und überwacht folgende Events:</p>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
@ -116,7 +115,7 @@ class EmailHandler:
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<p>Watchdog Docker v0.1 - Automatische Benachrichtigung</p>
|
<p>Watchdog Docker - Automatische Benachrichtigung</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
@ -223,7 +222,7 @@ class EmailHandler:
|
||||||
{details_html}
|
{details_html}
|
||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<p>Watchdog Docker v0.1 - Automatische Benachrichtigung</p>
|
<p>Watchdog Docker - Automatische Benachrichtigung</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
63
app/main.py
63
app/main.py
|
|
@ -11,19 +11,58 @@ from database import Database
|
||||||
from monitor import OPNsenseMonitor
|
from monitor import OPNsenseMonitor
|
||||||
from email_handler import EmailHandler
|
from email_handler import EmailHandler
|
||||||
|
|
||||||
|
# Load version
|
||||||
|
with open('VERSION', 'r') as f:
|
||||||
|
VERSION = f.read().strip()
|
||||||
|
|
||||||
# Load configuration
|
# Load configuration
|
||||||
with open('config/config.yaml', 'r') as f:
|
with open('config/config.yaml', 'r') as f:
|
||||||
config = yaml.safe_load(f)
|
config = yaml.safe_load(f)
|
||||||
|
|
||||||
# Setup logging
|
# Setup logging
|
||||||
logging.basicConfig(
|
from logging.handlers import RotatingFileHandler
|
||||||
level=getattr(logging, config['logging']['level']),
|
import os
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
||||||
handlers=[
|
# Create logs directory if it doesn't exist
|
||||||
logging.FileHandler(config['logging']['file']),
|
logs_dir = os.path.dirname(config['logging']['file'])
|
||||||
logging.StreamHandler()
|
if logs_dir and not os.path.exists(logs_dir):
|
||||||
]
|
os.makedirs(logs_dir, exist_ok=True)
|
||||||
|
|
||||||
|
# Main log file with rotation
|
||||||
|
main_handler = RotatingFileHandler(
|
||||||
|
config['logging']['file'],
|
||||||
|
maxBytes=config['logging'].get('max_bytes', 10 * 1024 * 1024), # 10MB default
|
||||||
|
backupCount=config['logging'].get('backup_count', 5)
|
||||||
)
|
)
|
||||||
|
main_handler.setLevel(getattr(logging, config['logging']['level']))
|
||||||
|
main_handler.setFormatter(logging.Formatter(
|
||||||
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
||||||
|
))
|
||||||
|
|
||||||
|
# Error log file (separate file for errors only)
|
||||||
|
error_handler = RotatingFileHandler(
|
||||||
|
config['logging']['error_file'],
|
||||||
|
maxBytes=config['logging'].get('max_bytes', 10 * 1024 * 1024),
|
||||||
|
backupCount=config['logging'].get('backup_count', 5)
|
||||||
|
)
|
||||||
|
error_handler.setLevel(logging.ERROR)
|
||||||
|
error_handler.setFormatter(logging.Formatter(
|
||||||
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s - [%(pathname)s:%(lineno)d]'
|
||||||
|
))
|
||||||
|
|
||||||
|
# Console handler
|
||||||
|
console_handler = logging.StreamHandler()
|
||||||
|
console_handler.setLevel(getattr(logging, config['logging']['level']))
|
||||||
|
console_handler.setFormatter(logging.Formatter(
|
||||||
|
'%(asctime)s - %(levelname)s - %(message)s'
|
||||||
|
))
|
||||||
|
|
||||||
|
# Configure root logger
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.DEBUG, # Capture everything, handlers filter
|
||||||
|
handlers=[main_handler, error_handler, console_handler]
|
||||||
|
)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Initialize Flask
|
# Initialize Flask
|
||||||
|
|
@ -120,7 +159,7 @@ def health():
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'status': 'healthy',
|
'status': 'healthy',
|
||||||
'timestamp': datetime.now().isoformat(),
|
'timestamp': datetime.now().isoformat(),
|
||||||
'version': '0.1'
|
'version': VERSION
|
||||||
})
|
})
|
||||||
|
|
||||||
# Initialize scheduler
|
# Initialize scheduler
|
||||||
|
|
@ -145,14 +184,14 @@ def start_monitoring():
|
||||||
email_handler.send_startup_notification()
|
email_handler.send_startup_notification()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logger.info("Starting Watchdog Docker v0.1")
|
logger.info(f"Starting Watchdog Docker v{VERSION}")
|
||||||
|
|
||||||
# Initialize database
|
# Initialize database
|
||||||
db.initialize()
|
db.initialize()
|
||||||
|
|
||||||
# Start monitoring
|
# Start monitoring
|
||||||
start_monitoring()
|
start_monitoring()
|
||||||
|
|
||||||
# Run Flask
|
# Run Flask
|
||||||
app.run(
|
app.run(
|
||||||
host=config['web']['host'],
|
host=config['web']['host'],
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="text-center mt-4">
|
<div class="text-center mt-4">
|
||||||
<small class="text-muted">Version 0.1</small>
|
<small class="text-muted">Watchdog Docker</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,16 @@ database:
|
||||||
path: "/app/data/watchdog.db"
|
path: "/app/data/watchdog.db"
|
||||||
retention_days: 90 # Keep events for 90 days
|
retention_days: 90 # Keep events for 90 days
|
||||||
|
|
||||||
# Logging
|
# Logging Configuration
|
||||||
logging:
|
logging:
|
||||||
level: "INFO" # DEBUG, INFO, WARNING, ERROR
|
level: "INFO" # DEBUG, INFO, WARNING, ERROR, CRITICAL
|
||||||
file: "/app/data/watchdog.log"
|
|
||||||
|
# Main log file (all messages)
|
||||||
|
file: "/app/logs/watchdog.log"
|
||||||
|
|
||||||
|
# Error log file (errors only with full traceback)
|
||||||
|
error_file: "/app/logs/error.log"
|
||||||
|
|
||||||
|
# Log rotation settings
|
||||||
|
max_bytes: 10485760 # 10MB per log file
|
||||||
|
backup_count: 5 # Keep 5 backup files (total ~50MB per log type)
|
||||||
|
|
@ -10,6 +10,7 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- ./config/config.yaml:/app/config/config.yaml:ro
|
- ./config/config.yaml:/app/config/config.yaml:ro
|
||||||
- ./data:/app/data
|
- ./data:/app/data
|
||||||
|
- ./logs:/app/logs
|
||||||
environment:
|
environment:
|
||||||
- TZ=Europe/Berlin
|
- TZ=Europe/Berlin
|
||||||
- PYTHONUNBUFFERED=1
|
- PYTHONUNBUFFERED=1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue