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
@@ -5,11 +5,13 @@ import { ResponseError } from "@homarr/common/server";
|
||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||
|
||||
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||
import type { SessionStore } from "../base/session-store";
|
||||
import type { SynologyDiskRecord, SynologyVolumeRecord } from "./synology-types";
|
||||
import {
|
||||
AUTH_API_NAME,
|
||||
INFO_API_NAME,
|
||||
parseSynologyNumber,
|
||||
REQUEST_TIMEOUT_MS,
|
||||
SESSION_ERROR_CODES,
|
||||
synologyApiInfoResponseSchema,
|
||||
@@ -64,6 +66,15 @@ export class SynologyClient {
|
||||
this.sessionStore = options.sessionStore;
|
||||
}
|
||||
|
||||
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||
let session = await this.sessionStore.getAsync();
|
||||
if (!session) {
|
||||
session = await this.loginAsync();
|
||||
await this.sessionStore.setAsync(session, { ttlSeconds: 600 });
|
||||
}
|
||||
return { headers: { Cookie: session.cookieHeader }, redactValues: [session.cookieHeader] };
|
||||
}
|
||||
|
||||
public async getSystemInfoAsync() {
|
||||
const response = await this.requestAsync("SYNO.Core.System", { method: "info" });
|
||||
return synologySystemInfoDataSchema.parse(response.data);
|
||||
@@ -174,8 +185,8 @@ export class SynologyClient {
|
||||
status: string | undefined,
|
||||
displayName?: string,
|
||||
): SynologyVolumeRecord | null {
|
||||
const usedBytes = parseNumericValue(usedValue);
|
||||
const totalBytes = parseNumericValue(totalValue);
|
||||
const usedBytes = parseSynologyNumber(usedValue);
|
||||
const totalBytes = parseSynologyNumber(totalValue);
|
||||
if (usedBytes === null || totalBytes === null || totalBytes <= 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -194,7 +205,7 @@ export class SynologyClient {
|
||||
identifier: disk.id ?? disk.name ?? disk.display_name ?? "unknown-disk",
|
||||
name: disk.display_name ?? disk.name ?? disk.id ?? "unknown-disk",
|
||||
status: disk.smart_status ?? disk.status,
|
||||
temperature: parseOptionalNumericValue(disk.temp ?? disk.temperature),
|
||||
temperature: parseSynologyNumber(disk.temp ?? disk.temperature),
|
||||
volumeName: disk.volume_id ?? disk.vol_path,
|
||||
}));
|
||||
}
|
||||
@@ -205,7 +216,7 @@ export class SynologyClient {
|
||||
identifier: disk.disk_id ?? disk.id ?? disk.name ?? "unknown-disk",
|
||||
name: disk.name ?? disk.disk_id ?? disk.id ?? "unknown-disk",
|
||||
status: disk.overall_status ?? disk.status,
|
||||
temperature: parseOptionalNumericValue(disk.temp ?? disk.temperature),
|
||||
temperature: parseSynologyNumber(disk.temp ?? disk.temperature),
|
||||
volumeName: undefined,
|
||||
}));
|
||||
}
|
||||
@@ -394,16 +405,3 @@ function extractCookieHeader(headers: Headers): string | null {
|
||||
|
||||
return cookies.map((cookie) => cookie.split(";")[0]).join("; ");
|
||||
}
|
||||
|
||||
function parseNumericValue(value: number | string | undefined): number | null {
|
||||
if (value === undefined) {
|
||||
return null;
|
||||
}
|
||||
const parsed = typeof value === "number" ? value : Number.parseFloat(value);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
function parseOptionalNumericValue(value: number | string | undefined): number | null {
|
||||
const parsed = parseNumericValue(value);
|
||||
return parsed === null ? null : parsed;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import type { z } from "zod";
|
||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||
|
||||
import { HandleIntegrationErrors } from "../base/errors/decorator";
|
||||
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||
import type { IntegrationTestingInput } from "../base/integration";
|
||||
import { Integration } from "../base/integration";
|
||||
import { createSessionStore } from "../base/session-store";
|
||||
@@ -10,6 +11,7 @@ import type { TestingResult } from "../base/test-connection/test-connection-serv
|
||||
import type { ISystemHealthMonitoringIntegration } from "../interfaces/health-monitoring/health-monitoring-integration";
|
||||
import type { SystemHealthMonitoring } from "../interfaces/health-monitoring/health-monitoring-types";
|
||||
import { SynologyClient } from "./synology-client";
|
||||
import { parseSynologyNumber } from "./synology-types";
|
||||
import type { SynologyDiskRecord, SynologyVolumeRecord } from "./synology-types";
|
||||
import type { synologySystemInfoDataSchema, synologyUtilizationDataSchema } from "./synology-types";
|
||||
|
||||
@@ -24,6 +26,10 @@ export class SynologyIntegration extends Integration implements ISystemHealthMon
|
||||
private readonly sessionStore = createSessionStore<StoredSession>(this.integration);
|
||||
private client?: SynologyClient;
|
||||
|
||||
public override async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||
return await this.getClient().getHttpAuthenticationAsync();
|
||||
}
|
||||
|
||||
protected async testingAsync(_input: IntegrationTestingInput): Promise<TestingResult> {
|
||||
await this.getClient().testConnectionAsync();
|
||||
return { success: true };
|
||||
@@ -125,16 +131,16 @@ function mapVersion(systemInfo: z.infer<typeof synologySystemInfoDataSchema>): s
|
||||
}
|
||||
|
||||
function mapCpuUtilization(utilization: z.infer<typeof synologyUtilizationDataSchema>): number {
|
||||
const userLoad = parseNumericValue(utilization.cpu?.user_load) ?? 0;
|
||||
const systemLoad = parseNumericValue(utilization.cpu?.system_load) ?? 0;
|
||||
const userLoad = parseSynologyNumber(utilization.cpu?.user_load) ?? 0;
|
||||
const systemLoad = parseSynologyNumber(utilization.cpu?.system_load) ?? 0;
|
||||
const totalLoad = userLoad + systemLoad;
|
||||
return Math.min(totalLoad, 100);
|
||||
}
|
||||
|
||||
function mapMemoryBytes(utilization: z.infer<typeof synologyUtilizationDataSchema>) {
|
||||
const memory = utilization.memory;
|
||||
const totalRealKib = parseNumericValue(memory?.total_real);
|
||||
const realUsagePercent = parseNumericValue(memory?.real_usage);
|
||||
const totalRealKib = parseSynologyNumber(memory?.total_real);
|
||||
const realUsagePercent = parseSynologyNumber(memory?.real_usage);
|
||||
|
||||
// DSM utilization API reports memory sizes in KiB, not bytes.
|
||||
if (totalRealKib !== null && realUsagePercent !== null) {
|
||||
@@ -146,8 +152,8 @@ function mapMemoryBytes(utilization: z.infer<typeof synologyUtilizationDataSchem
|
||||
};
|
||||
}
|
||||
|
||||
const availableKib = parseNumericValue(memory?.avail_real) ?? 0;
|
||||
const cachedKib = parseNumericValue(memory?.cached) ?? 0;
|
||||
const availableKib = parseSynologyNumber(memory?.avail_real) ?? 0;
|
||||
const cachedKib = parseSynologyNumber(memory?.cached) ?? 0;
|
||||
const totalKib = totalRealKib ?? availableKib + cachedKib;
|
||||
const usedKib = Math.max(totalKib - availableKib, 0);
|
||||
|
||||
@@ -163,8 +169,8 @@ function mapNetworkTraffic(utilization: z.infer<typeof synologyUtilizationDataSc
|
||||
return null;
|
||||
}
|
||||
|
||||
const received = parseNumericValue(totalNetwork.rx);
|
||||
const transmitted = parseNumericValue(totalNetwork.tx);
|
||||
const received = parseSynologyNumber(totalNetwork.rx);
|
||||
const transmitted = parseSynologyNumber(totalNetwork.tx);
|
||||
if (received === null || transmitted === null) {
|
||||
return null;
|
||||
}
|
||||
@@ -176,9 +182,9 @@ function mapNetworkTraffic(utilization: z.infer<typeof synologyUtilizationDataSc
|
||||
}
|
||||
|
||||
function mapLoadAverage(utilization: z.infer<typeof synologyUtilizationDataSchema>) {
|
||||
const oneMinute = parseNumericValue(utilization.cpu?.["1min_load"]);
|
||||
const fiveMinute = parseNumericValue(utilization.cpu?.["5min_load"]);
|
||||
const fifteenMinute = parseNumericValue(utilization.cpu?.["15min_load"]);
|
||||
const oneMinute = parseSynologyNumber(utilization.cpu?.["1min_load"]);
|
||||
const fiveMinute = parseSynologyNumber(utilization.cpu?.["5min_load"]);
|
||||
const fifteenMinute = parseSynologyNumber(utilization.cpu?.["15min_load"]);
|
||||
|
||||
if (oneMinute === null && fiveMinute === null && fifteenMinute === null) {
|
||||
return null;
|
||||
@@ -210,7 +216,7 @@ function mapUptimeSeconds(systemInfo: z.infer<typeof synologySystemInfoDataSchem
|
||||
}
|
||||
|
||||
function mapCpuTemperature(systemInfo: z.infer<typeof synologySystemInfoDataSchema>): number | undefined {
|
||||
const temperature = parseNumericValue(systemInfo.sys_temp ?? systemInfo.temperature);
|
||||
const temperature = parseSynologyNumber(systemInfo.sys_temp ?? systemInfo.temperature);
|
||||
return temperature === null ? undefined : temperature;
|
||||
}
|
||||
|
||||
@@ -313,11 +319,3 @@ function isHealthyStatus(status: string | undefined): boolean {
|
||||
normalizedStatus.includes(unhealthyToken),
|
||||
);
|
||||
}
|
||||
|
||||
function parseNumericValue(value: number | string | undefined): number | null {
|
||||
if (value === undefined) {
|
||||
return null;
|
||||
}
|
||||
const parsed = typeof value === "number" ? value : Number.parseFloat(value);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
@@ -36,6 +36,14 @@ export const synologyAuthResponseSchema = synologyEnvelopeSchema.extend({
|
||||
|
||||
const numericString = z.union([z.number(), z.string()]);
|
||||
|
||||
export function parseSynologyNumber(value: number | string | undefined): number | null {
|
||||
if (value === undefined) {
|
||||
return null;
|
||||
}
|
||||
const parsed = typeof value === "number" ? value : Number.parseFloat(value);
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
export const synologySystemInfoDataSchema = z
|
||||
.object({
|
||||
up_time: z.string().optional(),
|
||||
|
||||
Reference in new issue
Block a user