feat!: release v2 (#6545)

Co-authored-by: Artur <145776561+arturict@users.noreply.github.com>
Co-authored-by: arturict <arturict@users.noreply.github.com>
Co-authored-by: Thomas <thomas@ajnart.fr>
Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com>
Co-authored-by: Danura30082 <danura30082+github@gmail.com>
Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com>
Co-authored-by: ajnart <thomas@ajnart.fr>
Co-authored-by: ajnart <thomas@ajnart.dev>
Co-authored-by: chenjun <chenjun@foxmail.com>
Co-authored-by: Wikibear <wikibear@users.noreply.github.com>
Co-authored-by: Bergasha <bergasha@gmail.com>
Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com>
Co-authored-by: Lucas Araujo <lucas.lra@gmail.com>
Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com>
Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social>
Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com>
Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com>
Co-authored-by: thrawnx <tight.bulb9384@fastmail.com>
Co-authored-by: Chris <58918656+nordada@users.noreply.github.com>
Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com>
Co-authored-by: Yanis <naamaneyanis@gmail.com>
Co-authored-by: Wikibear <me@sej.de>
Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386 -139176

No files matched your search

+186 -1
View File
@@ -64,7 +64,14 @@ function makeResponse(body: unknown) {
} as never;
}
function mockGlancesFetch(statsBody: unknown, sensorsBody: unknown) {
// Glances answers 400 "Unknown plugin smart" when the SMART plugin is disabled (the default).
const smartDisabledResponse = {
ok: false,
status: 400,
json: () => Promise.resolve({ detail: "Unknown plugin smart (available plugins: ...)" }),
} as never;
function mockGlancesFetch(statsBody: unknown, sensorsBody: unknown, smartBody?: unknown) {
mockFetch.mockImplementation(((url: string | URL) => {
const urlString = url.toString();
if (urlString.endsWith("/api/4/all")) {
@@ -73,10 +80,85 @@ function mockGlancesFetch(statsBody: unknown, sensorsBody: unknown) {
if (urlString.endsWith("/api/4/sensors")) {
return Promise.resolve(makeResponse(sensorsBody));
}
if (urlString.endsWith("/api/4/smart")) {
return Promise.resolve(smartBody === undefined ? smartDisabledResponse : makeResponse(smartBody));
}
return Promise.reject(new Error(`Unexpected fetch URL: ${urlString}`));
}) as typeof fetchWithTrustedCertificatesAsync);
}
// Trimmed /api/4/smart response from Glances 4.5.7 (pySMART) with one SATA disk and one NVMe drive.
const smartStats = [
{
DeviceName: "nvme0 KINGSTON SA2000M81000G",
key: "DeviceName",
"1": {
name: "Number of critical warnings",
key: "criticalWarning",
value: 0,
flags: null,
raw: 0,
worst: null,
threshold: null,
type: null,
updated: null,
when_failed: null,
},
"2": {
name: "Temperature (°C)",
key: "_temperature",
value: 30,
flags: null,
raw: 30,
worst: null,
threshold: null,
type: null,
updated: null,
when_failed: null,
},
"22": {
name: "Errors",
key: "errors",
value: [],
flags: null,
raw: [],
worst: null,
threshold: null,
type: null,
updated: null,
when_failed: null,
},
},
{
DeviceName: "sda WDC WD30EFRX-68EUZN0",
key: "DeviceName",
"5": {
name: "Reallocated_Sector_Ct",
key: "Reallocated_Sector_Ct",
value: "200",
flags: "0x0033",
raw: "0",
worst: "200",
threshold: "140",
type: "Pre-fail",
updated: "Always",
when_failed: "-",
},
"194": {
name: "Temperature_Celsius",
key: "Temperature_Celsius",
value: "115",
flags: "0x0022",
raw: "35 (Min/Max 20/45)",
worst: "106",
threshold: "000",
type: "Old_age",
updated: "Always",
when_failed: "-",
},
},
];
const integrationInput = {
id: "test-glances",
name: "Glances",
@@ -131,6 +213,109 @@ describe("GlancesIntegration schema", () => {
});
});
describe("GlancesIntegration SMART", () => {
beforeEach(() => {
mockFetch.mockReset();
});
test("maps a SATA disk with temperature from Temperature_Celsius", async () => {
mockGlancesFetch(baseStats, [], smartStats);
const integration = new GlancesIntegration(integrationInput);
const result = await integration.getSystemInfoAsync();
expect(result.smart).toContainEqual({
deviceName: "/dev/sda",
temperature: 35,
overallStatus: "PASSED",
healthy: true,
statusReason: { type: "attributesWithinThresholds" },
});
});
test("maps an NVMe drive by controller name with temperature from _temperature", async () => {
mockGlancesFetch(baseStats, [], smartStats);
const integration = new GlancesIntegration(integrationInput);
const result = await integration.getSystemInfoAsync();
expect(result.smart).toContainEqual({
deviceName: "/dev/nvme0",
temperature: 30,
overallStatus: "PASSED",
healthy: true,
statusReason: { type: "noCriticalWarning" },
});
});
test("reports FAILED when an ATA attribute has failed or NVMe has a critical warning", async () => {
const [nvme, sata] = smartStats;
mockGlancesFetch(
baseStats,
[],
[
{ ...nvme, "1": { ...nvme?.["1"], value: 4, raw: 4 } },
{ ...sata, "5": { ...sata?.["5"], when_failed: "FAILING_NOW" } },
],
);
const integration = new GlancesIntegration(integrationInput);
const result = await integration.getSystemInfoAsync();
expect(result.smart).toEqual([
expect.objectContaining({
deviceName: "/dev/nvme0",
overallStatus: "FAILED",
healthy: false,
statusReason: { type: "criticalWarning" },
}),
expect.objectContaining({
deviceName: "/dev/sda",
overallStatus: "FAILED",
healthy: false,
statusReason: { type: "attributesFailed", attributes: ["Reallocated_Sector_Ct"] },
}),
]);
});
test("returns no SMART data when the plugin is disabled, keeping the other stats", async () => {
mockGlancesFetch(baseStats, []);
const integration = new GlancesIntegration(integrationInput);
const result = await integration.getSystemInfoAsync();
expect(result.smart).toEqual([]);
expect(result.cpuUtilization).toBe(10);
expect(result.memUsedInBytes).toBe(4_000_000_000);
expect(result.fileSystem).toHaveLength(1);
expect(result.gpu).toEqual([]);
});
test("omits devices without SMART health data instead of reporting them healthy", async () => {
const [nvme] = smartStats;
mockGlancesFetch(
baseStats,
[],
[
{ DeviceName: "sdc USB Disk", key: "DeviceName" },
{ ...nvme, "1": { ...nvme?.["1"], value: null, raw: null } },
],
);
const integration = new GlancesIntegration(integrationInput);
const result = await integration.getSystemInfoAsync();
expect(result.smart).toEqual([]);
});
test("returns no SMART data when the payload is malformed", async () => {
mockGlancesFetch(baseStats, [], { unexpected: true });
const integration = new GlancesIntegration(integrationInput);
await expect(integration.getSystemInfoAsync()).resolves.toMatchObject({ smart: [] });
});
});
describe("parseGlancesCpuTempFromSensors", () => {
test("prefers CPU label over core sensors", () => {
const result = parseGlancesCpuTempFromSensors([