Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/admin-ui/src/__mock-backend__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,9 @@ export const otherCalls: Omit<Routes, keyof typeof namedSpacedCalls> = {
dockerLatestVersion: "20.10.8"
}),
getIsConnectedToInternet: async () => false,
getCoreVersion: async () => "0.2.92"
getCoreVersion: async () => "0.2.92",
gatusGetEndpoints: async () => new Map(),
gatusUpdateEndpoint: async () => {}
};

export const calls: Routes = {
Expand Down
3 changes: 2 additions & 1 deletion packages/dappmanager/src/api/routes/packageManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const packageManifest = wrapHandler<Params>(async (req, res) => {
"links",
"repository",
"bugs",
"license"
"license",
"notifications"
]);

res.status(200).send(filteredManifest);
Expand Down
56 changes: 56 additions & 0 deletions packages/dappmanager/src/calls/gatusConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { listPackages } from "@dappnode/dockerapi";
import { GatusConfig, Endpoint, Manifest } from "@dappnode/types";
import { getManifestPath } from "@dappnode/utils";
import fs from "fs";

/**
* Get gatus endpoints indexed by dnpName
*/
export async function gatusGetEndpoints(): Promise<Map<string, GatusConfig>> {
const packages = await listPackages();

// Read all manifests files and retrieve the gatus config
const endpoints = new Map<string, GatusConfig>();
for (const pkg of packages) {
const manifestPath = getManifestPath(pkg.dnpName, pkg.isCore);
const manifest: Manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
if (manifest.notifications) endpoints.set(pkg.dnpName, manifest.notifications);
}

return endpoints;
}

/**
* Update endpoint properties
* @param dnpName
* @param updatedEndpoint
*/
export async function gatusUpdateEndpoint({
dnpName,
updatedEndpoint
}: {
dnpName: string;
updatedEndpoint: Endpoint;
}): Promise<void> {
// Get current endpoint status
const manifest: Manifest = JSON.parse(fs.readFileSync(getManifestPath(dnpName, false), "utf8"));
if (!manifest.notifications) throw new Error("No notifications found in manifest");

const endpoint = manifest.notifications.endpoints.find((e) => e.name === updatedEndpoint.name);
if (!endpoint) throw new Error(`Endpoint ${updatedEndpoint.name} not found in manifest`);

// Update endpoint
Object.assign(endpoint, updatedEndpoint);

// Save manifest
fs.writeFileSync(getManifestPath(dnpName, false), JSON.stringify(manifest, null, 2));

// Update endpoint in gatus
// await fetch(`http://notifier.notifications.dappnode:8082/gatus/endpoints`, {
// method: "POST",
// headers: {
// "Content-Type": "application/json"
// },
// body: JSON.stringify(endpoint)
// });
}
1 change: 1 addition & 0 deletions packages/dappmanager/src/calls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { getCoreVersion } from "./getCoreVersion.js";
export { getUserActionLogs } from "./getUserActionLogs.js";
export { getHostUptime } from "./getHostUptime.js";
export { getIsConnectedToInternet } from "./getIsConnectedToInternet.js";
export { gatusGetEndpoints, gatusUpdateEndpoint } from "./gatusConfig.js";
export * from "./httpsPortal.js";
export { ipfsTest } from "./ipfsTest.js";
export { ipfsClientTargetSet } from "./ipfsClientTargetSet.js";
Expand Down
14 changes: 10 additions & 4 deletions packages/installer/src/dappnodeInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
PackageRequest,
SetupWizard,
GrafanaDashboard,
PrometheusTarget
PrometheusTarget,
GatusConfig
} from "@dappnode/types";
import { DappGetState, DappgetOptions, dappGet } from "./dappGet/index.js";
import { validateDappnodeCompose, validateManifestSchema } from "@dappnode/schemas";
Expand Down Expand Up @@ -72,7 +73,8 @@ export class DappnodeInstaller extends DappnodeRepository {
disclaimer: pkgRelease.disclaimer,
gettingStarted: pkgRelease.gettingStarted,
grafanaDashboards: pkgRelease.grafanaDashboards,
prometheusTargets: pkgRelease.prometheusTargets
prometheusTargets: pkgRelease.prometheusTargets,
notifications: pkgRelease.notifications
});

// set compose to custom dappnode compose in release
Expand Down Expand Up @@ -107,7 +109,8 @@ export class DappnodeInstaller extends DappnodeRepository {
disclaimer: pkgRelease.disclaimer,
gettingStarted: pkgRelease.gettingStarted,
grafanaDashboards: pkgRelease.grafanaDashboards,
prometheusTargets: pkgRelease.prometheusTargets
prometheusTargets: pkgRelease.prometheusTargets,
notifications: pkgRelease.notifications
});
});

Expand Down Expand Up @@ -151,20 +154,23 @@ export class DappnodeInstaller extends DappnodeRepository {
disclaimer,
gettingStarted,
prometheusTargets,
grafanaDashboards
grafanaDashboards,
notifications
}: {
manifest: Manifest;
SetupWizard?: SetupWizard;
disclaimer?: string;
gettingStarted?: string;
prometheusTargets?: PrometheusTarget[];
grafanaDashboards?: GrafanaDashboard[];
notifications?: GatusConfig;
}): Manifest {
if (SetupWizard) manifest.setupWizard = SetupWizard;
if (disclaimer) manifest.disclaimer = { message: disclaimer };
if (gettingStarted) manifest.gettingStarted = gettingStarted;
if (prometheusTargets) manifest.prometheusTargets = prometheusTargets;
if (grafanaDashboards && grafanaDashboards.length > 0) manifest.grafanaDashboards = grafanaDashboards;
if (notifications) manifest.notifications = notifications;

return manifest;
}
Expand Down
13 changes: 11 additions & 2 deletions packages/installer/src/installer/writeAndValidateFiles.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from "fs";
import { Log } from "@dappnode/logger";
import { validatePath } from "@dappnode/utils";
import { InstallPackageData } from "@dappnode/types";
import { InstallPackageData, Manifest } from "@dappnode/types";
import { dockerComposeConfig } from "@dappnode/dockerapi";
import { ComposeEditor } from "@dappnode/dockercompose";
import { isNotFoundError, writeManifest } from "@dappnode/utils";
import { isNotFoundError } from "@dappnode/utils";

/**
* Write the new compose and test it with config
Expand Down Expand Up @@ -47,3 +47,12 @@ function copyIfExists(src: string, dest: string): void {
if (!isNotFoundError(e)) throw e;
}
}

/**
* Util: Write manifest to file
* @param manfiestPath
* @param manifest
*/
function writeManifest(manfiestPath: string, manifest: Manifest): void {
fs.writeFileSync(manfiestPath, JSON.stringify(manifest, null, 2));
}
4 changes: 3 additions & 1 deletion packages/installer/test/unit/release/findEntries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ describe("validateTarImage", () => {
"host-grafana-dashboard.json",
"prometheus-targets.json",
"setup-wizard.json",
"signature.json"
"signature.json",
"notifications.yaml"
].map((name) => ({
name,
path: `Qm-root/${name}`,
Expand All @@ -70,6 +71,7 @@ describe("validateTarImage", () => {
disclaimer: "disclaimer.md",
gettingStarted: "getting-started.md",
prometheusTargets: "prometheus-targets.json",
notifications: "notifications.yaml",
grafanaDashboards: ["docker-grafana-dashboard.json", "host-grafana-dashboard.json"]
};

Expand Down
3 changes: 2 additions & 1 deletion packages/toolkit/src/repository/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ export class DappnodeRepository extends ApmRepository {
disclaimer: await this.getPkgAsset(releaseFilesToDownload.disclaimer, ipfsEntries),
gettingStarted: await this.getPkgAsset(releaseFilesToDownload.gettingStarted, ipfsEntries),
prometheusTargets: await this.getPkgAsset(releaseFilesToDownload.prometheusTargets, ipfsEntries),
grafanaDashboards: await this.getPkgAsset(releaseFilesToDownload.grafanaDashboards, ipfsEntries)
grafanaDashboards: await this.getPkgAsset(releaseFilesToDownload.grafanaDashboards, ipfsEntries),
notifications: await this.getPkgAsset(releaseFilesToDownload.notifications, ipfsEntries)
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "./releaseFiles.js";
export * from "./errors.js";
export * from "./routes.js";
export * from "./subscriptions.js";
export * from "./notifications.js";

// utils
export * from "./utils/index.js";
4 changes: 4 additions & 0 deletions packages/types/src/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { GatusConfig } from "./notifications.js";
import { SetupSchema, SetupTarget, SetupUiJson, SetupWizard } from "./setupWizard.js";

export interface Manifest {
Expand Down Expand Up @@ -98,6 +99,9 @@ export interface Manifest {

// setupWizard for compacted manifests in core packages
setupWizard?: SetupWizard;

// notifications
notifications?: GatusConfig;
}

export interface UpstreamItem {
Expand Down
29 changes: 29 additions & 0 deletions packages/types/src/notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export interface GatusConfig {
endpoints: Endpoint[];
}

export interface Endpoint {
name: string;
enabled: boolean;
url: string;
method: string;
conditions: string[];
interval: string; // e.g., "1m"
group: string;
alerts: Alert[];
description: string; // dappnode specific
metric?: {
// dappnode specific
min: number;
max: number;
unit: string; // e.g ºC
};
}

interface Alert {
type: string;
"failure-threshold": number;
"success-threshold": number;
"send-on-resolved": boolean;
description: string;
}
2 changes: 2 additions & 0 deletions packages/types/src/pkg.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Compose } from "./compose.js";
import { Manifest, PrometheusTarget, GrafanaDashboard } from "./manifest.js";
import { GatusConfig } from "./notifications.js";
import { SetupWizard } from "./setupWizard.js";

/**
Expand Down Expand Up @@ -97,6 +98,7 @@ export type DirectoryFiles = {
gettingStarted?: string;
prometheusTargets?: PrometheusTarget[];
grafanaDashboards?: GrafanaDashboard[];
notifications?: GatusConfig;
};

export interface FileConfig {
Expand Down
10 changes: 9 additions & 1 deletion packages/types/src/releaseFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ export const releaseFiles = Object.freeze({
maxSize: 10e6, // ~ 10MB
required: false as const,
multiple: true as const
}),
notifications: Object.freeze({
regex: /^.*notifications\.yaml$/,
format: FileFormat.YAML,
maxSize: 10e3,
required: false as const,
multiple: false as const
})
} as const);

Expand All @@ -95,5 +102,6 @@ export const releaseFilesToDownload = {
disclaimer: releaseFiles.disclaimer,
gettingStarted: releaseFiles.gettingStarted,
prometheusTargets: releaseFiles.prometheusTargets,
grafanaDashboards: releaseFiles.grafanaDashboards
grafanaDashboards: releaseFiles.grafanaDashboards,
notifications: releaseFiles.notifications
};
13 changes: 13 additions & 0 deletions packages/types/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
} from "./calls.js";
import { PackageEnvs } from "./compose.js";
import { PackageBackup } from "./manifest.js";
import { Endpoint, GatusConfig } from "./notifications.js";
import { TrustedReleaseKey } from "./pkg.js";
import { OptimismConfigSet, OptimismConfigGet } from "./rollups.js";
import { Network, StakerConfigGet, StakerConfigSet } from "./stakers.js";
Expand Down Expand Up @@ -261,6 +262,16 @@ export interface Routes {
*/
fetchDnpRequest: (kwargs: { id: string; version?: string }) => Promise<RequestedDnp>;

/**
* Gatus get endpoints
*/
gatusGetEndpoints(): Promise<Map<string, GatusConfig>>;

/**
* Gatus update endpoint
*/
gatusUpdateEndpoint: (kwargs: { dnpName: string; updatedEndpoint: Endpoint }) => Promise<void>;

/**
* Returns the user action logs. This logs are stored in a different
* file and format, and are meant to ease user support
Expand Down Expand Up @@ -690,6 +701,8 @@ export const routesData: { [P in keyof Routes]: RouteData } = {
fetchDirectory: {},
fetchRegistry: {},
fetchDnpRequest: {},
gatusGetEndpoints: { log: true },
gatusUpdateEndpoint: { log: true },
getUserActionLogs: {},
getHostUptime: {},
httpsPortalMappingAdd: { log: true },
Expand Down
1 change: 0 additions & 1 deletion packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ export { shouldUpdate } from "./shouldUpdate.js";
export { getPublicIpFromUrls } from "./getPublicIpFromUrls.js";
export { computeSemverUpdateType } from "./computeSemverUpdateType.js";
export * from "./coreVersionId.js";
export { writeManifest } from "./writeManifest.js";
export { readManifestIfExists } from "./readManifestIfExists.js";
export { removeCidrSuffix } from "./removeCidrSuffix.js";
6 changes: 0 additions & 6 deletions packages/utils/src/writeManifest.ts

This file was deleted.

Loading