Upload via GUI (396 Dateien)

This commit is contained in:
2026-11-04 07:55:19 +00:00
parent c55cc54ba2
commit 27b3e4dbaf
19 changed files with 1559 additions and 9 deletions
+49
View File
@@ -171,6 +171,53 @@ function status_execute_component_check(PDO $pdo, array $check): array
return ['ok' => $ok, 'error' => mb_substr($error, 0, 255), 'ms' => (int) round((microtime(true) - $started) * 1000)];
}
/** Sollen Administratoren bei Ausfall und Wiederkehr eines Dienstes benachrichtigt werden? (Standard: ja) */
function status_notify_admins_enabled(): bool
{
return get_setting('status_notify_admins', '1') === '1';
}
/**
* Benachrichtigt die aktiven Administratoren per E-Mail und Push, wenn ein überwachter Dienst ausfällt oder wieder läuft.
* Höchstens eine Meldung je Dienst und Richtung innerhalb von 10 Minuten (kein Dauerfeuer bei einem flackernden Dienst).
*
* @return int Anzahl der angeschriebenen Administratoren
*/
function status_notify_admins(PDO $pdo, array $component, bool $recovered, string $error = ''): int
{
if (!status_notify_admins_enabled()) return 0;
$key = 'status_notified_' . ($recovered ? 'up_' : 'down_') . (int) $component['id'];
$last = (string) get_setting($key, '');
if ($last !== '' && strtotime($last) > time() - 600) return 0;
set_setting($key, db_now());
$ids = $pdo->query("SELECT id FROM staff WHERE is_active = 1 AND role = 'admin'")->fetchAll(PDO::FETCH_COLUMN);
$name = (string) $component['name'];
$internal = !empty($component['is_internal']);
$title = $recovered ? "Dienst läuft wieder: {$name}" : "Dienst nicht erreichbar: {$name}";
$url = base_url() . '/staff/status_page.php';
$inner = '<p><strong>' . e($title) . '</strong></p>'
. '<p>' . ($recovered ? 'Die automatische Prüfung erreicht den Dienst wieder.' : 'Die automatische Prüfung erreicht den Dienst seit mindestens zwei Prüfungen nicht.') . '</p>'
. ($error !== '' && !$recovered ? '<p>Fehler: ' . e($error) . '</p>' : '')
. ($internal ? '<p style="color:#64748b">Dieser Dienst ist intern und steht nicht auf der öffentlichen Statusseite.</p>' : '')
. '<p><a href="' . e($url) . '">Statusseite im Mitarbeiterbereich öffnen</a></p>';
$sent = 0;
if (function_exists('staff_emails_by_ids')) {
$emails = staff_emails_by_ids($pdo, function_exists('vacation_expand_ids') ? vacation_expand_ids($pdo, $ids) : $ids);
foreach ($emails as $email) {
email_send_and_log($email, '[DeskHub] ' . $title, email_wrap($inner), null, 'Statusmeldung');
$sent++;
}
}
if (function_exists('push_to_staff')) {
foreach ($ids as $id) {
try { push_to_staff((int) $id, $title, $recovered ? 'Der Dienst läuft wieder.' : ($error !== '' ? $error : 'Die Prüfung schlägt fehl.'), '/staff/status_page.php'); } catch (Throwable $e) { /* Push ist optional */ }
}
}
try { audit_log(null, mb_substr('Statusseite: ' . $title . ' (Administratoren benachrichtigt)', 0, 250)); } catch (Throwable $e) { /* Protokoll ist optional */ }
return $sent;
}
function status_run_component_checks(PDO $pdo, bool $force = false): int
{
$components = status_components($pdo);
@@ -189,9 +236,11 @@ function status_run_component_checks(PDO $pdo, bool $force = false): int
$currentStatus = (string) $component['status'];
if ($result['ok'] && $currentStatus !== 'maintenance' && $currentStatus !== 'operational') {
status_set_component($pdo, (int) $component['id'], 'operational');
if ($currentStatus === 'outage') status_notify_admins($pdo, $component, true);
$currentStatus = 'operational';
} elseif (!$result['ok'] && $failures >= 2 && $currentStatus !== 'maintenance' && $currentStatus !== 'outage') {
status_set_component($pdo, (int) $component['id'], 'outage');
status_notify_admins($pdo, $component, false, (string) $result['error']);
$currentStatus = 'outage';
}
$sample->execute([(int) $component['id'], $currentStatus, db_now(), $result['ms']]);