This commit is contained in:
Mateusz Gruszczyński
2025-10-17 14:30:40 +02:00
parent 38e5fc6e49
commit b22cfe368e
3 changed files with 73 additions and 37 deletions

View File

@@ -121,19 +121,24 @@ async function fetchNodeDetail(name) {
return await r.json();
}
// ------ Normalizacja stanu usług ------
// ------ Services status ------
function normSvcState(s) {
const raw = String(pick(
const vals = [
s.active, s['active-state'], s.ActiveState, s.activestate,
s.state, s.SubState, s.substate
)).toLowerCase();
const bad = String(pick(s.result, s.Result, s['exit-code'])).toLowerCase();
s.SubState, s.substate,
s.state, s.State,
s.loadstate, s.LoadState,
s.result, s.Result, s['exit-code']
]
.filter(v => v !== undefined && v !== null && v !== '')
.map(v => String(v).toLowerCase());
if (/failed|error|dead/.test(bad)) return 'failed';
if (/^active$|running/.test(raw)) return 'active';
if (/activating|starting/.test(raw)) return 'activating';
if (/deactivating|stopping/.test(raw)) return 'deactivating';
if (/failed|dead/.test(raw)) return 'failed';
const joined = ' ' + vals.join(' ') + ' ';
if (/\b(failed|error|dead|auto-restart\b.*fail)\b/.test(joined)) return 'failed';
if (/\b(active|running|up)\b/.test(joined)) return 'active';
if (/\b(activating|starting|start-pre|reload)\b/.test(joined)) return 'activating';
if (/\b(deactivating|stopping|stop-post)\b/.test(joined)) return 'deactivating';
if (vals.length) return 'inactive';
return 'inactive';
}