Warn in the navbar when a drive's SMART health is failing. (#471)

A failing SMART self-assessment predicts imminent drive failure, so it
deserves a prominent warning.  useDriveHealth() reads the assessment
already present in smart_stats (pySMART reports PASS / FAIL / null) and
flags any drive whose assessment is FAIL.  Nav.js renders a red warning
icon in its own always-on slot — like the power warning, and unlike the
single-slot priority chain where a transient high temp could hide it.

Frontend-only: the assessment field is already in the cached payload.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
lrnselfreliance 2026-06-03 20:02:59 -06:00 • committed by Roland
parent 1bd102c768
commit e018616daf
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
3 changed files with 92 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import {DarkModeToggle, HotspotStatusIcon, useLocalStorage} from "./Common";
import {ShareButton} from "./Share";
import {
useCPUTemperature,
useDriveHealth,
useDriveTemperature,
useIOStats,
useLoad,
@ -197,6 +198,20 @@ export function NavBar() {
driveTemperatureIcon = <Popup content={`${hotDrive}: ${driveTemperature.toFixed()}°C`} trigger={link}/>;
}
// A drive's SMART self-assessment is failing — imminent drive failure.
// Always displayed (like power); too important to hide behind a transient
// warning in the priority chain.
const {failingDevices, failing: driveFailing} = useDriveHealth();
let driveHealthIcon;
if (driveFailing) {
const icon = <Icon data-testid='driveHealthIcon' name='warning sign' size='large' color={highWarningColor}/>;
const link = <Link to='/admin/status'>{icon}</Link>;
const message = failingDevices.length === 1
? `Drive ${failingDevices[0]} is failing its SMART health check! Back up your data.`
: `Drives failing SMART health check: ${failingDevices.join(', ')}. Back up your data.`;
driveHealthIcon = <Popup content={message} trigger={link}/>;
}
// Power issues, this is always displayed if detected.
const {underVoltage, overCurrent} = usePowerStats();
let powerIcon;
@ -274,6 +289,7 @@ export function NavBar() {
<NavIconWrapper>{apiDownIcon}</NavIconWrapper>
<NavIconWrapper>{processingIcon}</NavIconWrapper>
<NavIconWrapper>{upgradeIcon}</NavIconWrapper>
<NavIconWrapper>{driveHealthIcon}</NavIconWrapper>
<NavIconWrapper>{powerIcon}</NavIconWrapper>
<NavIconWrapper>{warningIcon}</NavIconWrapper>
<NavIconWrapper><ShareButton/></NavIconWrapper>

View file

@ -1357,6 +1357,18 @@ export const useDriveTemperature = () => {
}
}
// Reports drives whose SMART self-assessment is failing, so the navbar can
// warn of an imminent drive failure. pySMART reports 'PASS', 'FAIL', or null
// (unknown); only 'FAIL' is a problem.
export const useDriveHealth = () => {
const {status} = React.useContext(StatusContext);
const drives = Array.isArray(status?.smart_stats?.drives) ? status.smart_stats.drives : [];
const failingDevices = drives
.filter((d) => d.assessment === 'FAIL')
.map((d) => d.device);
return {failingDevices, failing: failingDevices.length > 0};
}
export const useLoad = () => {
const {status} = React.useContext(StatusContext);
let minute_1 = status?.load_stats?.minute_1;

View file

@ -1,7 +1,7 @@
import React from 'react';
import {act, renderHook} from '@testing-library/react';
import {render, screen} from '@testing-library/react';
import {usePages, useDriveTemperature} from './customHooks';
import {usePages, useDriveTemperature, useDriveHealth} from './customHooks';
import {QueryContext, StatusContext} from '../contexts/contexts';
import {Paginator} from '../components/Common';
@ -162,6 +162,69 @@ describe('useDriveTemperature', () => {
});
});
describe('useDriveHealth', () => {
const makeStatusWrapper = (status) => ({children}) => (
<StatusContext.Provider value={{status}}>
{children}
</StatusContext.Provider>
);
test('flags drives whose SMART assessment is FAIL', () => {
const status = {
smart_stats: {
drives: [
{device: 'sda', assessment: 'PASS'},
{device: 'sdb', assessment: 'FAIL'},
],
},
};
const {result} = renderHook(() => useDriveHealth(),
{wrapper: makeStatusWrapper(status)});
expect(result.current.failing).toBe(true);
expect(result.current.failingDevices).toEqual(['sdb']);
});
test('reports every failing drive', () => {
const status = {
smart_stats: {
drives: [
{device: 'sda', assessment: 'FAIL'},
{device: 'sdb', assessment: 'FAIL'},
],
},
};
const {result} = renderHook(() => useDriveHealth(),
{wrapper: makeStatusWrapper(status)});
expect(result.current.failingDevices).toEqual(['sda', 'sdb']);
});
test('does not warn when all drives PASS', () => {
const status = {
smart_stats: {drives: [{device: 'sda', assessment: 'PASS'}]},
};
const {result} = renderHook(() => useDriveHealth(),
{wrapper: makeStatusWrapper(status)});
expect(result.current.failing).toBe(false);
expect(result.current.failingDevices).toEqual([]);
});
test('ignores drives with an unknown (null) assessment', () => {
const status = {
smart_stats: {drives: [{device: 'sda', assessment: null}]},
};
const {result} = renderHook(() => useDriveHealth(),
{wrapper: makeStatusWrapper(status)});
expect(result.current.failing).toBe(false);
});
test('does not warn when smart_stats is absent', () => {
const {result} = renderHook(() => useDriveHealth(),
{wrapper: makeStatusWrapper({})});
expect(result.current.failing).toBe(false);
expect(result.current.failingDevices).toEqual([]);
});
});
describe('Paginator rendering', () => {
test('renders exactly totalPages numbered page links (no phantom trailing link)', () => {
// 48 results at 24 per page -> 2 pages. If totalPages is 3, semantic-ui