OperationalAlert loggt critical + Best-Effort-Mail an MONITORING_ALERT_EMAIL (Fallback LEGAL_CONTACT_EMAIL, feature-flagged). Alle 6 Scheduler-Tasks mit onFailure, Queue::failing-Listener; .env.example: LOG_STACK=daily als Prod-Soll. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Mail\OperationalAlertMail;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Mail;
|
|
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; die Mail ist Best-Effort und darf den auslösenden Prozess nie mit in
|
|
* den Abgrund reißen (Mailserver down o. ä.).
|
|
*/
|
|
class OperationalAlert
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $context
|
|
*/
|
|
public static function send(string $summary, array $context = []): void
|
|
{
|
|
Log::critical('[monitoring] '.$summary, $context);
|
|
|
|
if (! config('monitoring.alerts.enabled')) {
|
|
return;
|
|
}
|
|
|
|
$recipient = config('monitoring.alerts.mail_to');
|
|
|
|
if (empty($recipient)) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
Mail::to($recipient)->send(new OperationalAlertMail($summary, $context));
|
|
} catch (Throwable $e) {
|
|
Log::error('[monitoring] Alert-Mail konnte nicht versendet werden.', [
|
|
'summary' => $summary,
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
}
|
|
}
|
|
}
|