Update snmp_status.php

Funktion Hinzugefügt damit log files nicht unendlich wachsen jeweils ein 500kb backup und ein 500kb aktueller file
This commit is contained in:
Tom 2025-12-03 17:54:12 +01:00
parent c03a99d07a
commit b5146cde65

View File

@ -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) ===