From 7e01f6d3db08fb4218dfd8ea6d4a96b2602c1ad5 Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Sat, 30 May 2026 16:26:51 -0400 Subject: [PATCH] Differentiate API key missing vs API unreachable in monitor banner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit unraid_api.php: track key_missing separately from general fallbacks. vv_api_data() sets key_missing=true when HOST*_UNRAID_API_KEY is empty. vv_api_get_status() includes key_missing in the status payload. monitor.php: two distinct banner states instead of one orange warning. key_missing → subtle dark/grey note: "API key not configured — add HOST1_UNRAID_API_KEY in Scheduler → host conf to enable enhanced monitoring" key present but unreachable → existing orange ⚠ with fallback list. No banner at all when API is working correctly. --- Plugin/unraid/include/unraid_api.php | 15 +++++++++++---- Plugin/unraid/pages/monitor.php | 25 ++++++++++++++++--------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Plugin/unraid/include/unraid_api.php b/Plugin/unraid/include/unraid_api.php index 43efa11..0409b7f 100644 --- a/Plugin/unraid/include/unraid_api.php +++ b/Plugin/unraid/include/unraid_api.php @@ -17,17 +17,19 @@ require_once __DIR__ . '/config.php'; // ── Fallback tracking ───────────────────────────────────────────────────────── function &_vv_api_fallbacks(): array { static $f = []; return $f; } +function &_vv_api_key_missing(): bool { static $m = false; return $m; } function vv_api_record_fallback(string $fn): void { - $f = &_vv_api_fallbacks(); + $f = &_vv_api_fallbacks(); $f[] = $fn; } function vv_api_get_status(): array { $fallbacks = array_unique(_vv_api_fallbacks()); return [ - 'available' => empty($fallbacks), - 'fallbacks' => $fallbacks, + 'available' => empty($fallbacks), + 'key_missing' => _vv_api_key_missing(), + 'fallbacks' => $fallbacks, ]; } @@ -43,7 +45,12 @@ function vv_api_data(): ?array { $hostId = vv_detect_host(); $vars = vv_conf_vars(); $key = $vars[strtoupper($hostId) . '_UNRAID_API_KEY'] ?? ''; - if (!$key) { $cache = null; return null; } + if (!$key) { + $m = &_vv_api_key_missing(); + $m = true; + $cache = null; + return null; + } // Fields verified against live schema introspection (2026-05-29). // array.parities / .disks / .caches are SEPARATE lists — .disks is DATA only. diff --git a/Plugin/unraid/pages/monitor.php b/Plugin/unraid/pages/monitor.php index ddd21b2..4fd26b1 100644 --- a/Plugin/unraid/pages/monitor.php +++ b/Plugin/unraid/pages/monitor.php @@ -1,10 +1,6 @@ - +
@@ -467,10 +463,21 @@ function vvPollMonitor() { const apiStatus = d._api_status ?? {}; const banner = document.getElementById('vv-api-banner'); if (banner) { - const hasFallbacks = apiStatus.fallbacks && apiStatus.fallbacks.length > 0; - banner.style.display = hasFallbacks ? '' : 'none'; - const listEl = document.getElementById('vv-api-fallback-list'); - if (listEl && hasFallbacks) listEl.textContent = '(' + apiStatus.fallbacks.join(', ') + ')'; + const fallbacks = apiStatus.fallbacks ?? []; + if (fallbacks.length === 0) { + banner.style.display = 'none'; + } else if (apiStatus.key_missing) { + // Key not configured — informational, not alarming + Object.assign(banner.style, {display:'', background:'#111', border:'1px solid #2a2a2a', color:'#555'}); + banner.textContent = 'API key not configured — add HOST' + + (typeof vvLocalHostConf !== 'undefined' ? vvLocalHostConf.replace(/\D/g,'') : '1') + + '_UNRAID_API_KEY in Scheduler → host conf to enable enhanced monitoring.'; + } else { + // Key present but API unreachable — genuine problem + Object.assign(banner.style, {display:'', background:'#1a1200', border:'1px solid #3a2800', color:'#ff9800'}); + banner.innerHTML = '⚠ Unraid API unreachable — using local reads. Check API key in host conf.' + + (fallbacks.length ? ' (' + fallbacks.join(', ') + ')' : ''); + } } // ── Thresholds (from dynamix.cfg via backend) ────────────────────────────