diff --git a/db/knex_migrations/2024-10-17-0000-notifications-path-as-name.js b/db/knex_migrations/2024-10-17-0000-notifications-path-as-name.js new file mode 100644 index 000000000..3a4e6be91 --- /dev/null +++ b/db/knex_migrations/2024-10-17-0000-notifications-path-as-name.js @@ -0,0 +1,12 @@ +exports.up = function (knex) { + return knex.schema + .alterTable("notification", function (table) { + table.boolean("use_path_as_name").notNullable().defaultTo(true); + }); +}; + +exports.down = function (knex) { + return knex.schema.alterTable("notification", function (table) { + table.dropColumn("use_path_as_name"); + }); +}; diff --git a/server/client.js b/server/client.js index 72f0a4e8e..f37a84330 100644 --- a/server/client.js +++ b/server/client.js @@ -26,7 +26,15 @@ async function sendNotificationList(socket) { for (let bean of list) { let notificationObject = bean.export(); notificationObject.isDefault = (notificationObject.isDefault === 1); + notificationObject.usePathAsName = (notificationObject.usePathAsName === 1); notificationObject.active = (notificationObject.active === 1); + + const configObject = JSON.parse(notificationObject.config); + if ( !("usePathAsName" in configObject)) { + configObject.usePathAsName = notificationObject.usePathAsName; + notificationObject.config = JSON.stringify(configObject); + } + result.push(notificationObject); } diff --git a/server/model/monitor.js b/server/model/monitor.js index 241dc10d2..2f50119ea 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -1336,8 +1336,10 @@ class Monitor extends BeanModel { for (let notification of notificationList) { try { const heartbeatJSON = bean.toJSON(); - const monitorData = [{ id: monitor.id, - active: monitor.active + const monitorData = [{ + id: monitor.id, + name: monitor.name, + active: monitor.active, }]; const preloadData = await Monitor.preparePreloadData(monitorData); // Prevent if the msg is undefined, notifications such as Discord cannot send out. diff --git a/server/notification.js b/server/notification.js index 26daeb042..bf00af46a 100644 --- a/server/notification.js +++ b/server/notification.js @@ -176,6 +176,9 @@ class Notification { * @throws Error with fail msg */ static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + if (notification.usePathAsName && monitorJSON) { + monitorJSON["name"] = monitorJSON["pathName"]; + } if (this.providerList[notification.type]) { return this.providerList[notification.type].send(notification, msg, monitorJSON, heartbeatJSON); } else { @@ -211,6 +214,8 @@ class Notification { bean.user_id = userID; bean.config = JSON.stringify(notification); bean.is_default = notification.isDefault || false; + bean.use_path_as_name = notification.usePathAsName; + await R.store(bean); if (notification.applyExisting) { diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index ec86d15f8..483280080 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -41,6 +41,16 @@
+
+ + +
+
+ If your monitor is inside a group, the name will show the full path of the monitor. For example "Group A / Monitor 1". +
+ +
+
@@ -95,6 +105,7 @@ export default { /** @type { null | keyof NotificationFormList } */ type: null, isDefault: false, + usePathAsName: false, // Do not set default value here, please scroll to show() } }; @@ -263,6 +274,7 @@ export default { name: "", type: "telegram", isDefault: false, + usePathAsName: true, }; }