diff --git a/public/api/snmp_status.php b/public/api/snmp_status.php index ea85338..4d26b23 100644 --- a/public/api/snmp_status.php +++ b/public/api/snmp_status.php @@ -38,6 +38,18 @@ function log_msg(string $msg): void { @file_put_contents($logFile, "[$timestamp] $msg\n", FILE_APPEND); } +function rotate_log_if_needed(): void { + global $logFile; + $maxSize = 500 * 1024; // 500 KB (anpassbar) + + if (file_exists($logFile) && filesize($logFile) > $maxSize) { + $backupFile = $logFile . '.old'; + @rename($logFile, $backupFile); + log_msg('=== Log rotiert (alte Datei: .old) ==='); + } +} + + $configPath = __DIR__ . '/../../config/config.php'; if (!is_readable($configPath)) { log_msg('ERROR: config.php nicht lesbar'); @@ -48,6 +60,8 @@ if (!is_readable($configPath)) { $config = require $configPath; $snmp = $config['snmp'] ?? []; +rotate_log_if_needed(); + log_msg('--- SNMP-Abfrage gestartet ---'); // === Cache-Logik (Datei) ===