- GlitchTip über die Sentry-SDKs; Datenschutzfilter (nur User-ID, keine
Request-Bodys, Tokens aus URL/Query/Referer, E-Mails aus Meldungen).
Browser-SDK erst beim ersten Fehler nachgeladen.
- ReportErrorSignals: tote interne Links (404 mit eigenem Referrer), 403/429
für Angemeldete, 419 als gedrosselte Warnung.
- /health (Bearer-Token): DB, Cache, Queue-Rückstau, Scheduler-Herzschlag,
Plattenplatz → 200/503; Scheduler und Plattenplatz auch im Systemstatus.
- OperationalAlert zusätzlich per ntfy (JSON-POST), unabhängig von der Mail.
- Verlauf: login_failed (Grund unbekannt/kein Passwort/falsch),
login_lockout, two_factor_failed; IP nur als gekürzter HMAC.
- Umami: Kundenbereich mit eigenem Schalter und identify('user-<id>'),
nie im Admin/bei Impersonation; Query-Filter auch auf den Webseiten
(signierte Links gingen bisher an Umami).
- queue:prune-failed nach 30 Tagen.
- Versionsnummer: config('app.version') aus APP_VERSION oder Datei RELEASE
(git describe --tags), in GlitchTip, /health, Systemstatus, artisan about.
Plan: dev/betrieb/monitoring-plan.md (Entscheidungen M1–M9).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
94 lines
3.2 KiB
PHP
94 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Mail\OperationalAlertMail;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Str;
|
|
use Throwable;
|
|
|
|
/**
|
|
* Zentrale Betriebs-Alerts (R5.3): meldet fehlgeschlagene Scheduler-Tasks und
|
|
* Queue-Jobs. Der Log-Eintrag (`critical`) ist die verlässliche Ebene und läuft
|
|
* immer; Mail und ntfy-Push (Monitoring-Plan M3) sind Best-Effort, unabhängig
|
|
* voneinander, und dürfen den auslösenden Prozess nie mit in den Abgrund
|
|
* reißen (Mailserver down, ntfy nicht erreichbar o. ä.).
|
|
*/
|
|
class OperationalAlert
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $context
|
|
*/
|
|
public static function send(string $summary, array $context = []): void
|
|
{
|
|
Log::channel('monitoring')->critical('[monitoring] '.$summary, $context);
|
|
|
|
if (! config('monitoring.alerts.enabled')) {
|
|
return;
|
|
}
|
|
|
|
self::mail($summary, $context);
|
|
self::push($summary, $context);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $context
|
|
*/
|
|
private static function mail(string $summary, array $context): void
|
|
{
|
|
$recipient = config('monitoring.alerts.mail_to');
|
|
|
|
if (empty($recipient)) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
Mail::to($recipient)->send(new OperationalAlertMail($summary, $context));
|
|
} catch (Throwable $e) {
|
|
Log::channel('monitoring')->error('[monitoring] Alert-Mail konnte nicht versendet werden.', [
|
|
'summary' => $summary,
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* JSON-Publish an die ntfy-Basis-URL (UTF-8-sicher, anders als Header).
|
|
*
|
|
* @param array<string, mixed> $context
|
|
*/
|
|
private static function push(string $summary, array $context): void
|
|
{
|
|
$url = (string) config('monitoring.alerts.ntfy.url');
|
|
$topic = (string) config('monitoring.alerts.ntfy.topic');
|
|
|
|
if ($url === '' || $topic === '') {
|
|
return;
|
|
}
|
|
|
|
$details = collect($context)
|
|
->map(fn (mixed $value, string $key): string => $key.': '.(is_scalar($value) || $value === null ? (string) $value : json_encode($value)))
|
|
->implode("\n");
|
|
|
|
try {
|
|
Http::timeout(5)
|
|
->connectTimeout(3)
|
|
->when(filled(config('monitoring.alerts.ntfy.token')), fn ($request) => $request->withToken((string) config('monitoring.alerts.ntfy.token')))
|
|
->post(rtrim($url, '/'), [
|
|
'topic' => $topic,
|
|
'title' => config('app.name').' ('.app()->environment().'): Betriebs-Alert',
|
|
'message' => Str::limit(trim($summary."\n\n".$details), 3500),
|
|
'priority' => (int) config('monitoring.alerts.ntfy.priority'),
|
|
'tags' => ['rotating_light'],
|
|
])
|
|
->throw();
|
|
} catch (Throwable $e) {
|
|
Log::channel('monitoring')->error('[monitoring] ntfy-Push konnte nicht versendet werden.', [
|
|
'summary' => $summary,
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
}
|
|
}
|
|
}
|