- dev/betrieb/deploy.sh: Deploy nur per Tag, mit --seed (Seeder im Wartungsmodus) und --initial (Vorschau/Live einmalig an Ort und Stelle auf Git umstellen) - dev/betrieb/vorschau-auffrischen.sh: Live-DB und Live-Medien in die Vorschau (Generalprobe) - InteriorReleaseSeeder: alle Inhaltsschritte des Relaunchs in einem Lauf, idempotent; Displays, Playlists und Mediathek bleiben unberührt - DisplayInteriorBrandingSeeder überschreibt keinen inzwischen gepflegten Claim mehr - Monitoring: GlitchTip (Server + Browser), /health mit Token, Scheduler-Herzschlag, Alarme per Mail und ntfy, Version in about und /health - public/build versioniert; .gitignore: macOS-Muster Icon traf resources/views/flux/icon/ - Runbook: dev/betrieb/README.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
3.3 KiB
PHP
96 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Support\Str;
|
|
use Throwable;
|
|
|
|
/**
|
|
* Zentrale Betriebs-Alerts: meldet fehlgeschlagene Scheduler-Tasks und
|
|
* Queue-Jobs (Verdrahtung: siehe 03-betriebsueberwachung.md). Der Log-Eintrag (`critical`) ist die verlässliche Ebene und läuft
|
|
* immer; Mail und ntfy-Push 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::raw(
|
|
$summary."\n\n".json_encode($context, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
|
fn ($message) => $message->to($recipient)->subject('['.config('app.name').'] Betriebs-Alert: '.Str::limit($summary, 80)),
|
|
);
|
|
} 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(),
|
|
]);
|
|
}
|
|
}
|
|
}
|