Remove WireGuard integration from production deployment to simplify infrastructure: - Remove docker-compose-direct-access.yml (VPN-bound services) - Remove VPN-only middlewares from Grafana, Prometheus, Portainer - Remove WireGuard middleware definitions from Traefik - Remove WireGuard IPs (10.8.0.0/24) from Traefik forwarded headers All monitoring services now publicly accessible via subdomains: - grafana.michaelschiemer.de (with Grafana native auth) - prometheus.michaelschiemer.de (with Basic Auth) - portainer.michaelschiemer.de (with Portainer native auth) All services use Let's Encrypt SSL certificates via Traefik.
151 lines
4.9 KiB
PHP
151 lines
4.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Process\Services;
|
|
|
|
use App\Framework\Process\ValueObjects\Alert\Alert;
|
|
use App\Framework\Process\ValueObjects\Alert\AlertReport;
|
|
use App\Framework\Process\ValueObjects\Alert\AlertSeverity;
|
|
use App\Framework\Process\ValueObjects\Alert\AlertThreshold;
|
|
use App\Framework\Process\ValueObjects\Health\HealthReport;
|
|
|
|
/**
|
|
* Alert Service.
|
|
*
|
|
* Verwaltet System-Alerts basierend auf Health Checks und Thresholds.
|
|
*/
|
|
final readonly class AlertService
|
|
{
|
|
/**
|
|
* @param AlertThreshold[] $thresholds
|
|
*/
|
|
public function __construct(
|
|
private SystemHealthCheckService $healthCheck,
|
|
private array $thresholds = []
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Prüft alle Alerts und gibt einen Report zurück.
|
|
*/
|
|
public function checkAlerts(): AlertReport
|
|
{
|
|
$healthReport = ($this->healthCheck)();
|
|
$alerts = [];
|
|
|
|
// Check health checks for alerts
|
|
foreach ($healthReport->checks as $check) {
|
|
$threshold = $this->findThreshold($check->name);
|
|
|
|
if ($threshold === null) {
|
|
// Use default thresholds based on health check status
|
|
if ($check->status->value === 'unhealthy') {
|
|
$alerts[] = Alert::create(
|
|
id: $this->generateAlertId($check->name),
|
|
name: $check->name,
|
|
severity: AlertSeverity::CRITICAL,
|
|
message: $check->message,
|
|
description: "Value: {$check->value} {$check->unit} exceeds critical threshold",
|
|
metadata: [
|
|
'value' => $check->value,
|
|
'unit' => $check->unit,
|
|
'threshold' => $check->threshold,
|
|
]
|
|
);
|
|
} elseif ($check->status->value === 'degraded') {
|
|
$alerts[] = Alert::create(
|
|
id: $this->generateAlertId($check->name),
|
|
name: $check->name,
|
|
severity: AlertSeverity::WARNING,
|
|
message: $check->message,
|
|
description: "Value: {$check->value} {$check->unit} exceeds warning threshold",
|
|
metadata: [
|
|
'value' => $check->value,
|
|
'unit' => $check->unit,
|
|
'threshold' => $check->threshold,
|
|
]
|
|
);
|
|
}
|
|
} else {
|
|
// Use configured threshold
|
|
$severity = $threshold->getSeverity($check->value);
|
|
|
|
if ($severity !== AlertSeverity::INFO) {
|
|
$alerts[] = Alert::create(
|
|
id: $this->generateAlertId($check->name),
|
|
name: $check->name,
|
|
severity: $severity,
|
|
message: $check->message,
|
|
description: "Value: {$check->value} {$check->unit} exceeds {$severity->value} threshold",
|
|
metadata: [
|
|
'value' => $check->value,
|
|
'unit' => $check->unit,
|
|
'threshold' => $threshold->criticalThreshold,
|
|
'warning_threshold' => $threshold->warningThreshold,
|
|
]
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
return AlertReport::fromAlerts($alerts);
|
|
}
|
|
|
|
/**
|
|
* Findet Threshold für einen Check-Namen.
|
|
*/
|
|
private function findThreshold(string $checkName): ?AlertThreshold
|
|
{
|
|
foreach ($this->thresholds as $threshold) {
|
|
if ($threshold->name === $checkName) {
|
|
return $threshold;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Generiert eine eindeutige Alert-ID.
|
|
*/
|
|
private function generateAlertId(string $checkName): string
|
|
{
|
|
return 'alert_' . md5($checkName . time());
|
|
}
|
|
|
|
/**
|
|
* Gibt die Standard-Thresholds zurück.
|
|
*
|
|
* @return AlertThreshold[]
|
|
*/
|
|
public static function getDefaultThresholds(): array
|
|
{
|
|
return [
|
|
new AlertThreshold(
|
|
name: 'Memory Usage',
|
|
warningThreshold: 80.0,
|
|
criticalThreshold: 90.0,
|
|
unit: '%',
|
|
description: 'Memory usage percentage'
|
|
),
|
|
new AlertThreshold(
|
|
name: 'Disk Usage',
|
|
warningThreshold: 80.0,
|
|
criticalThreshold: 90.0,
|
|
unit: '%',
|
|
description: 'Disk usage percentage'
|
|
),
|
|
new AlertThreshold(
|
|
name: 'System Load',
|
|
warningThreshold: 80.0,
|
|
criticalThreshold: 120.0,
|
|
unit: '%',
|
|
description: 'System load percentage'
|
|
),
|
|
];
|
|
}
|
|
}
|
|
|
|
|