From c3f44bd12472b56b539c8f0b59bf11bcede95f98 Mon Sep 17 00:00:00 2001 From: Ivan K Date: Wed, 21 May 2025 14:18:23 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20fix(diagnosticTab):=20add=20error?= =?UTF-8?q?=20polling=20and=20notification=20system?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/view/podkop/diagnosticTab.js | 86 +++++++++++++++++-- 1 file changed, 81 insertions(+), 5 deletions(-) diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/diagnosticTab.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/diagnosticTab.js index 524eea0..b649878 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/diagnosticTab.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/diagnosticTab.js @@ -326,14 +326,23 @@ async function checkBypass() { async function getPodkopErrors() { return new Promise(resolve => { safeExec('/usr/bin/podkop', ['check_logs'], 0, result => { - if (!result || !result.stdout) return resolve([]); + if (!result || !result.stdout) { + console.error('No logs received from check_logs command'); + return resolve([]); + } const logs = result.stdout.split('\n'); - const errors = logs.filter(log => - log.includes('[critical]') - ); + console.log('Got logs from check_logs command, total lines:', logs.length); - console.log('Found errors:', errors); + const errors = logs.filter(log => { + const hasCritical = log.includes('[critical]'); + if (hasCritical) { + console.log('Found critical log:', log); + } + return hasCritical; + }); + + console.log('Found errors:', errors.length, errors); resolve(errors); }); }); @@ -711,6 +720,73 @@ function stopDiagnosticsUpdates() { } } +// Error polling functions +function startErrorPolling() { + console.log('Starting error polling'); + if (errorPollTimer) { + console.log('Clearing existing error poll timer'); + clearInterval(errorPollTimer); + } + + // Reset initial check flag to make sure we show errors + isInitialCheck = false; + + // Immediately check for errors on start + console.log('Running immediate check for errors'); + checkForCriticalErrors(); + + // Then set up periodic checks + console.log('Setting up periodic error checks with interval:', constants.ERROR_POLL_INTERVAL); + errorPollTimer = setInterval(checkForCriticalErrors, constants.ERROR_POLL_INTERVAL); +} + +function stopErrorPolling() { + if (errorPollTimer) { + clearInterval(errorPollTimer); + errorPollTimer = null; + } +} + +async function checkForCriticalErrors() { + try { + console.log('Checking for critical errors, isInitialCheck =', isInitialCheck); + const errors = await getPodkopErrors(); + console.log('Got errors from getPodkopErrors:', errors.length); + + if (errors && errors.length > 0) { + // Filter out errors we've already seen + const newErrors = errors.filter(error => !lastErrorsSet.has(error)); + console.log('New errors not seen before:', newErrors.length); + + if (newErrors.length > 0) { + // On initial check, just store errors without showing notifications + if (!isInitialCheck) { + console.log('Showing notifications for errors:', newErrors.length); + // Show each new error as a notification + newErrors.forEach(error => { + console.log('Showing notification for error:', error); + showErrorNotification(error, newErrors.length > 1); + }); + } else { + console.log('Initial check, not showing notifications'); + } + + // Add new errors to our set of seen errors + newErrors.forEach(error => lastErrorsSet.add(error)); + console.log('Updated lastErrorsSet, size =', lastErrorsSet.size); + } + } + + // After first check, mark as no longer initial + if (isInitialCheck) { + console.log('Setting isInitialCheck to false'); + isInitialCheck = false; + } + } catch (error) { + console.error('Error checking for critical messages:', error); + } +} + // Update individual text element with new content function updateTextElement(elementId, content) { const element = document.getElementById(elementId);