Differentiate API key missing vs API unreachable in monitor banner
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.
This commit is contained in:
@@ -17,6 +17,7 @@ require_once __DIR__ . '/config.php';
|
|||||||
// ── Fallback tracking ─────────────────────────────────────────────────────────
|
// ── Fallback tracking ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function &_vv_api_fallbacks(): array { static $f = []; return $f; }
|
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 {
|
function vv_api_record_fallback(string $fn): void {
|
||||||
$f = &_vv_api_fallbacks();
|
$f = &_vv_api_fallbacks();
|
||||||
@@ -27,6 +28,7 @@ function vv_api_get_status(): array {
|
|||||||
$fallbacks = array_unique(_vv_api_fallbacks());
|
$fallbacks = array_unique(_vv_api_fallbacks());
|
||||||
return [
|
return [
|
||||||
'available' => empty($fallbacks),
|
'available' => empty($fallbacks),
|
||||||
|
'key_missing' => _vv_api_key_missing(),
|
||||||
'fallbacks' => $fallbacks,
|
'fallbacks' => $fallbacks,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -43,7 +45,12 @@ function vv_api_data(): ?array {
|
|||||||
$hostId = vv_detect_host();
|
$hostId = vv_detect_host();
|
||||||
$vars = vv_conf_vars();
|
$vars = vv_conf_vars();
|
||||||
$key = $vars[strtoupper($hostId) . '_UNRAID_API_KEY'] ?? '';
|
$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).
|
// Fields verified against live schema introspection (2026-05-29).
|
||||||
// array.parities / .disks / .caches are SEPARATE lists — .disks is DATA only.
|
// array.parities / .disks / .caches are SEPARATE lists — .disks is DATA only.
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
<?php require_once dirname(__DIR__) . '/include/monitor.php'; ?>
|
<?php require_once dirname(__DIR__) . '/include/monitor.php'; ?>
|
||||||
|
|
||||||
<div id="vv-api-banner" style="display:none;background:#1a1200;border:1px solid #3a2800;border-radius:4px;
|
<div id="vv-api-banner" style="display:none;border-radius:4px;padding:5px 10px;margin-bottom:8px;font-size:11px;"></div>
|
||||||
padding:5px 10px;margin-bottom:8px;font-size:11px;color:#ff9800;">
|
|
||||||
⚠ Unraid API unavailable — using local reads. Check API key in host conf.
|
|
||||||
<span id="vv-api-fallback-list" style="color:#666;margin-left:6px;"></span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="vv-monitor" style="display:grid;grid-template-columns:repeat(8,1fr);gap:12px;width:100%;box-sizing:border-box;">
|
<div id="vv-monitor" style="display:grid;grid-template-columns:repeat(8,1fr);gap:12px;width:100%;box-sizing:border-box;">
|
||||||
|
|
||||||
@@ -467,10 +463,21 @@ function vvPollMonitor() {
|
|||||||
const apiStatus = d._api_status ?? {};
|
const apiStatus = d._api_status ?? {};
|
||||||
const banner = document.getElementById('vv-api-banner');
|
const banner = document.getElementById('vv-api-banner');
|
||||||
if (banner) {
|
if (banner) {
|
||||||
const hasFallbacks = apiStatus.fallbacks && apiStatus.fallbacks.length > 0;
|
const fallbacks = apiStatus.fallbacks ?? [];
|
||||||
banner.style.display = hasFallbacks ? '' : 'none';
|
if (fallbacks.length === 0) {
|
||||||
const listEl = document.getElementById('vv-api-fallback-list');
|
banner.style.display = 'none';
|
||||||
if (listEl && hasFallbacks) listEl.textContent = '(' + apiStatus.fallbacks.join(', ') + ')';
|
} 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 ? ' <span style="color:#666">(' + fallbacks.join(', ') + ')</span>' : '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Thresholds (from dynamix.cfg via backend) ────────────────────────────
|
// ── Thresholds (from dynamix.cfg via backend) ────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user