Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Fix Thresholds page crash on guest filesystems with omitted usage

rcourtman15bb0c217ee8
diff --git a/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsGuestData.test.ts b/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsGuestData.test.ts
index 013c1dcb8b..096572dba6 100644
--- a/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsGuestData.test.ts
+++ b/frontend-modern/src/features/alerts/thresholds/hooks/__tests__/useThresholdsGuestData.test.ts
@@ -72,6 +72,69 @@ describe('useThresholdsGuestData guest filesystems', () => {
});
});
+ it('projects filesystems whose serialized usage was omitted without crashing', () => {
+ createRoot((dispose) => {
+ const props = {
+ allGuests: () => [
+ {
+ id: 'cluster-a:node-1:101',
+ name: 'files',
+ platformId: 'cluster-a',
+ status: 'online',
+ type: 'ct',
+ lastSeen: 1,
+ proxmox: {
+ instance: 'cluster-a',
+ node: 'node-1',
+ vmid: 101,
+ // The unified resources payload drops zero-valued numerics, so
+ // an untouched filesystem arrives with no usage/used fields.
+ disks: [
+ {
+ device: 'rootfs',
+ mountpoint: '/',
+ total: 107374182400,
+ type: 'ext4',
+ },
+ {
+ device: 'mp0',
+ mountpoint: '/data',
+ total: 214748364800,
+ used: 107374182400,
+ free: 107374182400,
+ type: 'ext4',
+ },
+ ],
+ },
+ },
+ ],
+ backupDefaults: () => ({ enabled: false }),
+ guestDefaults: { disk: 85 },
+ nodes: [],
+ overrides: () => [],
+ snapshotDefaults: () => ({ enabled: false }),
+ } as unknown as ThresholdsTableProps;
+
+ const data = useThresholdsGuestData({
+ props,
+ editingId: () => null,
+ searchTerm: () => '',
+ });
+
+ expect(data.guestDisksWithOverrides()).toEqual([
+ expect.objectContaining({
+ name: '/',
+ subtitle: '0.0 / 100.0 GB · 0.0%',
+ }),
+ expect.objectContaining({
+ name: '/data',
+ subtitle: '100.0 / 200.0 GB · 50.0%',
+ }),
+ ]);
+ dispose();
+ });
+ });
+
it('keeps a persisted filesystem override visible after its guest disappears', () => {
createRoot((dispose) => {
const props = {
diff --git a/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsGuestData.ts b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsGuestData.ts
index 16f814830b..56fee75712 100644
--- a/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsGuestData.ts
+++ b/frontend-modern/src/features/alerts/thresholds/hooks/useThresholdsGuestData.ts
@@ -117,7 +117,16 @@ export function useThresholdsGuestData(inputs: ThresholdsDataInputs) {
const guestIdentity = getGuestOverrideIdentity(guest);
disks.forEach((disk: Disk) => {
- if (!disk || disk.total <= 0 || disk.usage < 0) return;
+ // The unified resources payload omits zero-valued numerics, so
+ // total/used/usage may all be absent; usage < 0 is the poller's
+ // "unknown" sentinel and stays excluded.
+ const total = disk?.total ?? 0;
+ const used = disk?.used ?? 0;
+ if (!disk || total <= 0 || (typeof disk.usage === 'number' && disk.usage < 0)) return;
+ const usagePercent =
+ typeof disk.usage === 'number' && Number.isFinite(disk.usage)
+ ? disk.usage
+ : (used / total) * 100;
const candidates = guestDiskOverrideIdCandidates(guest, disk.mountpoint, disk.device);
const storageId = guestDiskOverrideStorageId(guest, disk.mountpoint, disk.device);
@@ -153,7 +162,7 @@ export function useThresholdsGuestData(inputs: ThresholdsDataInputs) {
disabled: override?.disabled || false,
thresholds: override?.thresholds || {},
defaults: { disk: props.guestDefaults.disk },
- subtitle: `${(disk.used / 1024 / 1024 / 1024).toFixed(1)} / ${(disk.total / 1024 / 1024 / 1024).toFixed(1)} GB · ${disk.usage.toFixed(1)}%`,
+ subtitle: `${(used / 1024 / 1024 / 1024).toFixed(1)} / ${(total / 1024 / 1024 / 1024).toFixed(1)} GB · ${usagePercent.toFixed(1)}%`,
} satisfies TableResource);
});
});