Skip to content
Merged
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: 4 additions & 0 deletions notifications.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
customEndpoints:
- name: "Package updates notifications"
description: string
enabled: true
7 changes: 0 additions & 7 deletions packages/daemons/src/autoUpdates/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
export { startAutoUpdatesDaemon } from "./startAutoUpdatesDaemon.js";
export { clearCompletedCoreUpdatesIfAny } from "./clearCompletedCoreUpdatesIfAny.js";
export { clearPendingUpdates } from "./clearPendingUpdates.js";
export { clearRegistry } from "./clearRegistry.js";
export { editCoreSetting } from "./editCoreSetting.js";
export { editDnpSetting } from "./editDnpSetting.js";
export { flagCompletedUpdate } from "./flagCompletedUpdate.js";
export { flagErrorUpdate } from "./flagErrorUpdate.js";
export { formatPackageUpdateNotification } from "./formatNotificationBody.js";
export { isCoreUpdateEnabled } from "./isCoreUpdateEnabled.js";
export { isDnpUpdateEnabled } from "./isDnpUpdateEnabled.js";
export { isUpdateDelayCompleted, updateDelay } from "./isUpdateDelayCompleted.js";
export * from "./params.js";
export { sendUpdatePackageNotificationMaybe } from "./sendUpdateNotification.js";
export { setPending } from "./setPending.js";
export { setSettings } from "./setSettings.js";
export { checkNewPackagesVersion } from "./updateMyPackages.js";
export { checkSystemPackagesVersion, autoUpdateSystemPackages } from "./updateSystemPackages.js";
export { getCoreUpdateData } from "./getCoreUpdateData.js";
7 changes: 7 additions & 0 deletions packages/daemons/src/autoUpdates/sendUpdateNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export async function sendUpdatePackageNotificationMaybe({
currentVersion: string;
newVersion: string;
}): Promise<void> {
// Check if auto-update notifications are enabled
const dappmanagerCustomEndpoint = (await notifications.getEndpoints())[
params.dappmanagerDnpName
].customEndpoints.find((customEndpoint) => customEndpoint.name === "auto-updates");

if (!dappmanagerCustomEndpoint || !dappmanagerCustomEndpoint.enabled) return;

// If version has already been emitted, skip
const lastEmittedVersion = db.notificationLastEmitVersion.get(dnpName);
if (lastEmittedVersion && valid(lastEmittedVersion) && lte(newVersion, lastEmittedVersion)) return; // Already emitted update available for this version
Expand Down
2 changes: 1 addition & 1 deletion packages/daemons/src/diskUsage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async function monitorDiskUsage(): Promise<void> {
await notifications
.sendNotification({
title: `Disk space is running out, ${threshold.id.split(" ")[0]}`,
dnpName: "dappmanager.dnp.dappnode.eth",
dnpName: params.dappmanagerDnpName,
body: [
`Available disk space is less than a ${threshold.id}.`,
`To prevent your DAppNode from becoming unusable ${threshold.containersDescription} where stopped.`,
Expand Down
2 changes: 1 addition & 1 deletion packages/dappmanager/src/calls/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CustomEndpoint, GatusEndpoint, Notification, NotificationsConfig } from
* @returns all the notifications
*/
export async function notificationsGetAll(): Promise<Notification[]> {
return await notifications.getAll();
return await notifications.getAllNotifications();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/dappmanager/src/calls/setStaticIp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { updateDyndnsIp } from "@dappnode/dyndns";
import { eventBus } from "@dappnode/eventbus";
import { logs } from "@dappnode/logger";
import { notifications } from "@dappnode/notifications";
import { params } from "@dappnode/params";
import { NotificationCategory } from "@dappnode/types";

/**
Expand Down Expand Up @@ -31,7 +32,7 @@ export async function setStaticIp({ staticIp }: { staticIp: string }): Promise<v
.sendNotification({
title: "Static IP updated",
body: `Your static IP was changed to ${staticIp}.`,
dnpName: "dappmanager.dnp.dappnode.eth",
dnpName: params.dappmanagerDnpName,
category: NotificationCategory.CORE
})
.catch((e) => logs.error("Error sending static IP updated notification", e));
Expand Down
2 changes: 1 addition & 1 deletion packages/notifications/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Notifications {
/**
* Get all the notifications
*/
async getAll(): Promise<Notification[]> {
async getAllNotifications(): Promise<Notification[]> {
return await this.api.getAllNotifications();
}

Expand Down
12 changes: 2 additions & 10 deletions packages/schemas/src/schemas/notifications.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,11 @@
"type": "array",
"items": {
"type": "object",
"required": ["enabled", "name", "definition", "group"],
"required": ["enabled", "name", "description"],
"properties": {
"enabled": { "type": "boolean" },
"name": { "type": "string" },
"definition": {
"type": "object",
"required": ["title", "description"],
"properties": {
"title": { "type": "string" },
"description": { "type": "string" }
}
},
"group": { "type": "string" },
"description": { "type": "string" },
"metric": {
"type": "object",
"properties": {
Expand Down
8 changes: 2 additions & 6 deletions packages/types/src/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ export enum NotificationCategory {
}

export interface CustomEndpoint {
enabled: boolean;
name: string;
definition: {
title: string;
description: string;
};
group: string;
enabled: boolean;
description: string;
metric?: {
treshold: number;
min: number;
Expand Down
Loading