diff --git a/db/knex_migrations/2025-05-09-0000-add-custom-url.js b/db/knex_migrations/2025-05-09-0000-add-custom-url.js new file mode 100644 index 000000000..b3465c87f --- /dev/null +++ b/db/knex_migrations/2025-05-09-0000-add-custom-url.js @@ -0,0 +1,13 @@ +// Add column custom_url to monitor_group table +exports.up = function (knex) { + return knex.schema + .alterTable("monitor_group", function (table) { + table.text("custom_url", "text"); + }); +}; + +exports.down = function (knex) { + return knex.schema.alterTable("monitor_group", function (table) { + table.dropColumn("custom_url"); + }); +}; diff --git a/server/database.js b/server/database.js index 0e6a7405d..582f19c29 100644 --- a/server/database.js +++ b/server/database.js @@ -736,7 +736,7 @@ class Database { if (Database.dbConfig.type === "sqlite") { return "DATETIME('now', ? || ' hours')"; } else { - return "DATE_ADD(NOW(), INTERVAL ? HOUR)"; + return "DATE_ADD(UTC_TIMESTAMP(), INTERVAL ? HOUR)"; } } diff --git a/server/model/group.js b/server/model/group.js index bd2c30189..16c482759 100644 --- a/server/model/group.js +++ b/server/model/group.js @@ -33,7 +33,7 @@ class Group extends BeanModel { */ async getMonitorList() { return R.convertToBeans("monitor", await R.getAll(` - SELECT monitor.*, monitor_group.send_url FROM monitor, monitor_group + SELECT monitor.*, monitor_group.send_url, monitor_group.custom_url FROM monitor, monitor_group WHERE monitor.id = monitor_group.monitor_id AND group_id = ? ORDER BY monitor_group.weight diff --git a/server/model/monitor.js b/server/model/monitor.js index 626849b91..08d666b78 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -53,7 +53,7 @@ class Monitor extends BeanModel { }; if (this.sendUrl) { - obj.url = this.url; + obj.url = this.customUrl ?? this.url; } if (showTags) { diff --git a/server/notification-providers/discord.js b/server/notification-providers/discord.js index 6a52f8f3e..9ea260410 100644 --- a/server/notification-providers/discord.js +++ b/server/notification-providers/discord.js @@ -46,10 +46,10 @@ class Discord extends NotificationProvider { name: "Service Name", value: monitorJSON["name"], }, - { + ...(!notification.disableUrl ? [{ name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL", value: this.extractAddress(monitorJSON), - }, + }] : []), { name: `Time (${heartbeatJSON["timezone"]})`, value: heartbeatJSON["localDateTime"], @@ -83,10 +83,10 @@ class Discord extends NotificationProvider { name: "Service Name", value: monitorJSON["name"], }, - { + ...(!notification.disableUrl ? [{ name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL", value: this.extractAddress(monitorJSON), - }, + }] : []), { name: `Time (${heartbeatJSON["timezone"]})`, value: heartbeatJSON["localDateTime"], diff --git a/server/notification-providers/notifery.js b/server/notification-providers/notifery.js new file mode 100644 index 000000000..772556497 --- /dev/null +++ b/server/notification-providers/notifery.js @@ -0,0 +1,53 @@ +const { getMonitorRelativeURL, UP } = require("../../src/util"); +const { setting } = require("../util-server"); +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class Notifery extends NotificationProvider { + name = "notifery"; + + /** + * @inheritdoc + */ + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + const okMsg = "Sent Successfully."; + const url = "https://api.notifery.com/event"; + + let data = { + title: notification.notiferyTitle || "Uptime Kuma Alert", + message: msg, + }; + + if (notification.notiferyGroup) { + data.group = notification.notiferyGroup; + } + + // Link to the monitor + const baseURL = await setting("primaryBaseURL"); + if (baseURL && monitorJSON) { + data.message += `\n\nMonitor: ${baseURL}${getMonitorRelativeURL(monitorJSON.id)}`; + } + + if (heartbeatJSON) { + data.code = heartbeatJSON.status === UP ? 0 : 1; + + if (heartbeatJSON.ping) { + data.duration = heartbeatJSON.ping; + } + } + + try { + const headers = { + "Content-Type": "application/json", + "x-api-key": notification.notiferyApiKey, + }; + + await axios.post(url, data, { headers }); + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = Notifery; diff --git a/server/notification-providers/slack.js b/server/notification-providers/slack.js index 5e25a1fbc..455d787c7 100644 --- a/server/notification-providers/slack.js +++ b/server/notification-providers/slack.js @@ -145,6 +145,7 @@ class Slack extends NotificationProvider { const title = "Uptime Kuma Alert"; let data = { + "text": msg, "channel": notification.slackchannel, "username": notification.slackusername, "icon_emoji": notification.slackiconemo, diff --git a/server/notification.js b/server/notification.js index 468d026c0..fd8c23d67 100644 --- a/server/notification.js +++ b/server/notification.js @@ -13,6 +13,7 @@ const DingDing = require("./notification-providers/dingding"); const Discord = require("./notification-providers/discord"); const Elks = require("./notification-providers/46elks"); const Feishu = require("./notification-providers/feishu"); +const Notifery = require("./notification-providers/notifery"); const FreeMobile = require("./notification-providers/freemobile"); const GoogleChat = require("./notification-providers/google-chat"); const Gorush = require("./notification-providers/gorush"); @@ -169,6 +170,7 @@ class Notification { new YZJ(), new SMSPlanet(), new SpugPush(), + new Notifery(), ]; for (let item of list) { if (! item.name) { diff --git a/server/routers/api-router.js b/server/routers/api-router.js index ed6db2cd1..3568f2abf 100644 --- a/server/routers/api-router.js +++ b/server/routers/api-router.js @@ -98,15 +98,15 @@ router.all("/api/push/:pushToken", async (request, response) => { // Reset down count bean.downCount = 0; - log.debug("monitor", `[${this.name}] sendNotification`); + log.debug("monitor", `[${monitor.name}] sendNotification`); await Monitor.sendNotification(isFirstBeat, monitor, bean); } else { - if (bean.status === DOWN && this.resendInterval > 0) { + if (bean.status === DOWN && monitor.resendInterval > 0) { ++bean.downCount; - if (bean.downCount >= this.resendInterval) { + if (bean.downCount >= monitor.resendInterval) { // Send notification again, because we are still DOWN - log.debug("monitor", `[${this.name}] sendNotification again: Down Count: ${bean.downCount} | Resend Interval: ${this.resendInterval}`); - await Monitor.sendNotification(isFirstBeat, this, bean); + log.debug("monitor", `[${monitor.name}] sendNotification again: Down Count: ${bean.downCount} | Resend Interval: ${monitor.resendInterval}`); + await Monitor.sendNotification(isFirstBeat, monitor, bean); // Reset down count bean.downCount = 0; diff --git a/server/socket-handlers/status-page-socket-handler.js b/server/socket-handlers/status-page-socket-handler.js index 1114d81fd..952ec2fa7 100644 --- a/server/socket-handlers/status-page-socket-handler.js +++ b/server/socket-handlers/status-page-socket-handler.js @@ -211,6 +211,10 @@ module.exports.statusPageSocketHandler = (socket) => { relationBean.send_url = monitor.sendUrl; } + if (monitor.url !== undefined) { + relationBean.custom_url = monitor.url; + } + await R.store(relationBean); } diff --git a/src/components/MonitorSettingDialog.vue b/src/components/MonitorSettingDialog.vue index e6b2cd1ef..8723c4862 100644 --- a/src/components/MonitorSettingDialog.vue +++ b/src/components/MonitorSettingDialog.vue @@ -10,7 +10,7 @@ + + + @@ -78,6 +88,7 @@ export default { monitor_index: monitor.index, group_index: group.index, isClickAble: this.showLink(monitor), + url: monitor.element.url, }; this.MonitorSettingDialog.show(); @@ -110,6 +121,17 @@ export default { } return monitor.element.sendUrl && monitor.element.url && monitor.element.url !== "https://" && !this.editMode; }, + + /** + * Toggle the value of sendUrl + * @param {number} groupIndex Index of group monitor is member of + * @param {number} index Index of monitor within group + * @param {string} value The new value of the url + * @returns {void} + */ + changeUrl(groupIndex, index, value) { + this.$root.publicGroupList[groupIndex].monitorList[index].url = value; + }, }, }; diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 2e66de8e9..acfcde6a2 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -168,7 +168,8 @@ export default { "waha": "WhatsApp (WAHA)", "gtxmessaging": "GtxMessaging", "Cellsynt": "Cellsynt", - "SendGrid": "SendGrid" + "SendGrid": "SendGrid", + "notifery": "Notifery" }; // Put notifications here if it's not supported in most regions or its documentation is not in English diff --git a/src/components/PublicGroupList.vue b/src/components/PublicGroupList.vue index 38aca2957..cb97ecdcd 100644 --- a/src/components/PublicGroupList.vue +++ b/src/components/PublicGroupList.vue @@ -58,6 +58,7 @@ v-if="editMode" :class="{'link-active': true, 'btn-link': true}" icon="cog" class="action me-3" + data-testid="monitor-settings" @click="$refs.monitorSettingDialog.show(group, monitor)" /> diff --git a/src/components/notifications/Discord.vue b/src/components/notifications/Discord.vue index 5d8334f5f..40d2f204e 100644 --- a/src/components/notifications/Discord.vue +++ b/src/components/notifications/Discord.vue @@ -53,6 +53,13 @@ + +
+
+ + +
+
diff --git a/src/components/notifications/Notifery.vue b/src/components/notifications/Notifery.vue new file mode 100644 index 000000000..ce204dc6a --- /dev/null +++ b/src/components/notifications/Notifery.vue @@ -0,0 +1,49 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index be7feb820..933139a4a 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -4,6 +4,7 @@ import AliyunSMS from "./AliyunSms.vue"; import Apprise from "./Apprise.vue"; import Bark from "./Bark.vue"; import Bitrix24 from "./Bitrix24.vue"; +import Notifery from "./Notifery.vue"; import ClickSendSMS from "./ClickSendSMS.vue"; import CallMeBot from "./CallMeBot.vue"; import SMSC from "./SMSC.vue"; @@ -149,6 +150,7 @@ const NotificationFormList = { "ZohoCliq": ZohoCliq, "SevenIO": SevenIO, "whapi": Whapi, + "notifery": Notifery, "waha": WAHA, "gtxmessaging": GtxMessaging, "Cellsynt": Cellsynt, diff --git a/src/lang/en.json b/src/lang/en.json index ce52e2fa2..c8555bf12 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -64,6 +64,7 @@ "Expected Value": "Expected Value", "Json Query Expression": "Json Query Expression", "Friendly Name": "Friendly Name", + "defaultFriendlyName": "New Monitor", "URL": "URL", "Hostname": "Hostname", "Host URL": "Host URL", @@ -1074,6 +1075,8 @@ "SendGrid API Key": "SendGrid API Key", "Separate multiple email addresses with commas": "Separate multiple email addresses with commas", "smtpHelpText": "“SMTPS” tests that SMTP/TLS is working; “Ignore TLS” connects over plaintext; “STARTTLS” connects, issues a STARTTLS command and verifies the server certificate. None of these send an email.", + "Custom URL": "Custom URL", + "customUrlDescription": "Will be used as the clickable URL instead of the monitor's one.", "OneChatAccessToken": "OneChat Access Token", "OneChatUserIdOrGroupId": "OneChat User ID or Group ID", "OneChatBotId": "OneChat Bot ID", @@ -1094,5 +1097,6 @@ "the smsplanet documentation": "the smsplanet documentation", "Phone numbers": "Phone numbers", "Sender name": "Sender name", - "smsplanetNeedToApproveName": "Needs to be approved in the client panel" + "smsplanetNeedToApproveName": "Needs to be approved in the client panel", + "Disable URL in Notification": "Disable URL in Notification" } diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index e25dd8e4a..bf4e6889d 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -112,7 +112,7 @@
- +
@@ -1172,6 +1172,25 @@ export default { }, computed: { + defaultFriendlyName() { + if (this.monitor.hostname) { + return this.monitor.hostname; + } + if (this.monitor.url) { + if (this.monitor.url !== "http://" && this.monitor.url !== "https://") { + // Ensure monitor without a URL is not affected by invisible URL. + try { + const url = new URL(this.monitor.url); + return url.hostname; + } catch (e) { + return this.monitor.url.replace(/https?:\/\//, ""); + } + } + } + // Default placeholder if neither hostname nor URL is available + return this.$t("defaultFriendlyName"); + }, + ipRegex() { // Allow to test with simple dns server with port (127.0.0.1:5300) @@ -1715,6 +1734,10 @@ message HealthCheckResponse { this.processing = true; + if (!this.monitor.name) { + this.monitor.name = this.defaultFriendlyName; + } + if (!this.isInputValid()) { this.processing = false; return; diff --git a/test/e2e/specs/fridendly-name.spec.js b/test/e2e/specs/fridendly-name.spec.js new file mode 100644 index 000000000..7dbe9dd06 --- /dev/null +++ b/test/e2e/specs/fridendly-name.spec.js @@ -0,0 +1,83 @@ +import { expect, test } from "@playwright/test"; +import { login, restoreSqliteSnapshot, screenshot } from "../util-test"; + +test.describe("Friendly Name Tests", () => { + test.beforeEach(async ({ page }) => { + await restoreSqliteSnapshot(page); + }); + + test("hostname", async ({ page }, testInfo) => { + // Test DNS monitor with hostname + await page.goto("./add"); + await login(page); + await screenshot(testInfo, page); + + await page.getByTestId("monitor-type-select").selectOption("dns"); + await page.getByTestId("hostname-input").fill("example.com"); + await screenshot(testInfo, page); + + await page.getByTestId("save-button").click(); + await page.waitForURL("/dashboard/*"); + + expect(page.getByTestId("monitor-list")).toContainText("example.com"); + await screenshot(testInfo, page); + }); + + test("URL hostname", async ({ page }, testInfo) => { + // Test HTTP monitor with URL + await page.goto("./add"); + await login(page); + await screenshot(testInfo, page); + + await page.getByTestId("monitor-type-select").selectOption("http"); + await page.getByTestId("url-input").fill("https://www.example.com/"); + await screenshot(testInfo, page); + + await page.getByTestId("save-button").click(); + await page.waitForURL("/dashboard/*"); + + expect(page.getByTestId("monitor-list")).toContainText("www.example.com"); + await screenshot(testInfo, page); + }); + + test("custom friendly name", async ({ page }, testInfo) => { + // Test custom friendly name for HTTP monitor + await page.goto("./add"); + await login(page); + await screenshot(testInfo, page); + + await page.getByTestId("monitor-type-select").selectOption("http"); + await page.getByTestId("url-input").fill("https://www.example.com/"); + + // Check if the friendly name placeholder is set to the hostname + const friendlyNameInput = page.getByTestId("friendly-name-input"); + expect(friendlyNameInput).toHaveAttribute("placeholder", "www.example.com"); + await screenshot(testInfo, page); + + const customName = "Example Monitor"; + await friendlyNameInput.fill(customName); + await screenshot(testInfo, page); + + await page.getByTestId("save-button").click(); + await page.waitForURL("/dashboard/*"); + + expect(page.getByTestId("monitor-list")).toContainText(customName); + await screenshot(testInfo, page); + }); + + test("default friendly name", async ({ page }, testInfo) => { + // Test default friendly name when no custom name is provided + await page.goto("./add"); + await login(page); + await screenshot(testInfo, page); + + await page.getByTestId("monitor-type-select").selectOption("group"); + await screenshot(testInfo, page); + + await page.getByTestId("save-button").click(); + await page.waitForURL("/dashboard/*"); + + expect(page.getByTestId("monitor-list")).toContainText("New Monitor"); + await screenshot(testInfo, page); + }); +}); diff --git a/test/e2e/specs/status-page.spec.js b/test/e2e/specs/status-page.spec.js index f525dfc6f..0231aa225 100644 --- a/test/e2e/specs/status-page.spec.js +++ b/test/e2e/specs/status-page.spec.js @@ -12,6 +12,8 @@ test.describe("Status Page", () => { const monitorName = "Monitor for Status Page"; const tagName = "Client"; const tagValue = "Acme Inc"; + const monitorUrl = "https://www.example.com/status"; + const monitorCustomUrl = "https://www.example.com"; // Status Page const footerText = "This is footer text."; @@ -30,7 +32,7 @@ test.describe("Status Page", () => { await expect(page.getByTestId("monitor-type-select")).toBeVisible(); await page.getByTestId("monitor-type-select").selectOption("http"); await page.getByTestId("friendly-name-input").fill(monitorName); - await page.getByTestId("url-input").fill("https://www.example.com/"); + await page.getByTestId("url-input").fill(monitorUrl); await page.getByTestId("add-tag-button").click(); await page.getByTestId("tag-name-input").fill(tagName); await page.getByTestId("tag-value-input").fill(tagValue); @@ -79,6 +81,13 @@ test.describe("Status Page", () => { await page.getByTestId("monitor-select").getByRole("option", { name: monitorName }).click(); await expect(page.getByTestId("monitor")).toHaveCount(1); await expect(page.getByTestId("monitor-name")).toContainText(monitorName); + await expect(page.getByTestId("monitor-name")).not.toHaveAttribute("href"); + + // Set public url on + await page.getByTestId("monitor-settings").click(); + await page.getByTestId("show-clickable-link").check(); + await page.getByTestId("custom-url-input").fill(monitorCustomUrl); + await page.getByTestId("monitor-settings-close").click(); // Save the changes await screenshot(testInfo, page); @@ -94,6 +103,8 @@ test.describe("Status Page", () => { await expect(page.getByTestId("footer-text")).toContainText(footerText); await expect(page.getByTestId("powered-by")).toHaveCount(0); + await expect(page.getByTestId("monitor-name")).toHaveAttribute("href", monitorCustomUrl); + await expect(page.getByTestId("update-countdown-text")).toContainText("00:"); const updateCountdown = Number((await page.getByTestId("update-countdown-text").textContent()).match(/(\d+):(\d+)/)[2]); expect(updateCountdown).toBeGreaterThanOrEqual(refreshInterval); // cant be certain when the timer will start, so ensure it's within expected range