From a42f7416b525a9f067b9a5fb187429560782ab3c Mon Sep 17 00:00:00 2001 From: Mikkel-T Date: Sun, 2 Oct 2022 19:29:33 +0200 Subject: [PATCH 01/12] Improve the URL field in Discord embeds Instead of having two different ways of showing the URL field in Discord embeds, always show the raw address. --- server/notification-providers/discord.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/notification-providers/discord.js b/server/notification-providers/discord.js index 28ead7b7a..3f1fc3345 100644 --- a/server/notification-providers/discord.js +++ b/server/notification-providers/discord.js @@ -91,7 +91,7 @@ class Discord extends NotificationProvider { }, { name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL", - value: monitorJSON["type"] === "push" ? "Heartbeat" : address.startsWith("http") ? "[Visit Service](" + address + ")" : address, + value: monitorJSON["type"] === "push" ? "Heartbeat" : address, }, { name: "Time (UTC)", From 73bfdb9ef9d3d970338086c8f339c84389e09a99 Mon Sep 17 00:00:00 2001 From: panos Date: Thu, 8 Dec 2022 13:32:10 +0200 Subject: [PATCH 02/12] zoho cliq notification provider --- server/notification-providers/zoho-cliq.js | 119 +++++++++++++++++++++ server/notification.js | 2 + src/components/notifications/ZohoCliq.vue | 18 ++++ src/components/notifications/index.js | 2 + src/languages/el-GR.js | 2 + src/languages/en.js | 2 + src/languages/eu.js | 2 + 7 files changed, 147 insertions(+) create mode 100644 server/notification-providers/zoho-cliq.js create mode 100644 src/components/notifications/ZohoCliq.vue diff --git a/server/notification-providers/zoho-cliq.js b/server/notification-providers/zoho-cliq.js new file mode 100644 index 000000000..d944089d4 --- /dev/null +++ b/server/notification-providers/zoho-cliq.js @@ -0,0 +1,119 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const {DOWN, UP} = require("../../src/util"); + +class ZohoCliq extends NotificationProvider { + + name = "ZohoCliq"; + + /** + * Generate the message to send + * @param {const} status The status constant + * @param {string} monitorName Name of monitor + * @returns {string} + */ + _statusMessageFactory = (status, monitorName) => { + if (status === DOWN) { + return `🔴 Application [${monitorName}] went down\n`; + } else if (status === UP) { + return `✅ Application [${monitorName}] is back online\n`; + } + return "Notification\n"; + }; + + /** + * Send the notification + * @param {string} webhookUrl URL to send the request to + * @param {Array} payload Payload generated by _notificationPayloadFactory + */ + _sendNotification = async(webhookUrl, payload) => { + await axios.post(webhookUrl, {text: payload.join("\n")}); + }; + + /** + * Generate payload for notification + * @param {const} status The status of the monitor + * @param {string} monitorMessage Message to send + * @param {string} monitorName Name of monitor affected + * @param {string} monitorUrl URL of monitor affected + * @returns {Array} + */ + _notificationPayloadFactory = ({ + status, + monitorMessage, + monitorName, + monitorUrl, + }) => { + + const payload = ["### Uptime Kuma\n"]; + payload.push(this._statusMessageFactory(status, monitorName)); + payload.push(`*Description:* ${monitorMessage}`); + + if (monitorName) { + payload.push(`*Monitor:* ${monitorName}`); + } + + if (monitorUrl && monitorUrl !== "https://") { + payload.push(`*URL:* [${monitorUrl}](${monitorUrl})`); + } + + return payload; + }; + + /** + * Send a general notification + * @param {string} webhookUrl URL to send request to + * @param {string} msg Message to send + * @returns {Promise} + */ + _handleGeneralNotification = (webhookUrl, msg) => { + const payload = this._notificationPayloadFactory({ + monitorMessage: msg + }); + + return this._sendNotification(webhookUrl, payload); + }; + + _monitorUrlFactory = (monitorJSON) => { + let url; + switch(monitorJSON["type"]) { + case "http": + case "keywork": + url = monitorJSON["url"]; + break; + case "docker": + url = monitorJSON["docker_host"]; + break; + default: + url = monitorJSON["hostname"]; + break; + } + return url; + }; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + + try { + if (heartbeatJSON == null) { + await this._handleGeneralNotification(notification.webhookUrl, msg); + return okMsg; + } + + const payload = this._notificationPayloadFactory({ + monitorMessage: heartbeatJSON.msg, + monitorName: monitorJSON.name, + monitorUrl: this._monitorUrlFactory(monitorJSON), + status: heartbeatJSON.status, + }); + + await this._sendNotification(notification.webhookUrl, payload); + return okMsg; + + } catch(error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = ZohoCliq; diff --git a/server/notification.js b/server/notification.js index 9069601b4..275f07b93 100644 --- a/server/notification.js +++ b/server/notification.js @@ -44,6 +44,7 @@ const WeCom = require("./notification-providers/wecom"); const GoAlert = require("./notification-providers/goalert"); const SMSManager = require("./notification-providers/smsmanager"); const ServerChan = require("./notification-providers/serverchan"); +const ZohoCliq = require("./notification-providers/zoho-cliq"); class Notification { @@ -100,6 +101,7 @@ class Notification { new Webhook(), new WeCom(), new GoAlert(), + new ZohoCliq() ]; for (let item of list) { diff --git a/src/components/notifications/ZohoCliq.vue b/src/components/notifications/ZohoCliq.vue new file mode 100644 index 000000000..9a9cd7360 --- /dev/null +++ b/src/components/notifications/ZohoCliq.vue @@ -0,0 +1,18 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 0c220b717..86dad13e7 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -42,6 +42,7 @@ import Telegram from "./Telegram.vue"; import Webhook from "./Webhook.vue"; import WeCom from "./WeCom.vue"; import GoAlert from "./GoAlert.vue"; +import ZohoCliq from "./ZohoCliq.vue"; /** * Manage all notification form. @@ -93,6 +94,7 @@ const NotificationFormList = { "WeCom": WeCom, "GoAlert": GoAlert, "ServerChan": ServerChan, + "ZohoCliq": ZohoCliq }; export default NotificationFormList; diff --git a/src/languages/el-GR.js b/src/languages/el-GR.js index c520a6079..9b7c4cfb3 100644 --- a/src/languages/el-GR.js +++ b/src/languages/el-GR.js @@ -194,6 +194,7 @@ export default { here: "εδώ", Required: "Απαιτείται", telegram: "Telegram", + "ZohoCliq": "ZohoCliq", "Bot Token": "Διακριτικό Bot", wayToGetTelegramToken: "Μπορείτε να πάρετε ένα διακριτικό από {0}.", "Chat ID": "Chat ID", @@ -224,6 +225,7 @@ export default { teams: "Microsoft Teams", "Webhook URL": "Webhook URL", wayToGetTeamsURL: "Μπορείτε να μάθετε πώς να δημιουργείτε μια διεύθυνση URL webhook {0}.", + wayToGetZohoCliqURL: "Μπορείτε να μάθετε πώς να δημιουργείτε μια διεύθυνση URL webhook {0}.", signal: "Signal", Number: "Αριθμός", Recipients: "Αποδέκτες", diff --git a/src/languages/en.js b/src/languages/en.js index e7de9648b..106edf0e8 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -209,6 +209,7 @@ export default { here: "here", Required: "Required", telegram: "Telegram", + "ZohoCliq": "ZohoCliq", "Bot Token": "Bot Token", wayToGetTelegramToken: "You can get a token from {0}.", "Chat ID": "Chat ID", @@ -241,6 +242,7 @@ export default { teams: "Microsoft Teams", "Webhook URL": "Webhook URL", wayToGetTeamsURL: "You can learn how to create a webhook URL {0}.", + wayToGetZohoCliqURL: "You can learn how to create a webhook URL {0}.", signal: "Signal", Number: "Number", Recipients: "Recipients", diff --git a/src/languages/eu.js b/src/languages/eu.js index c99f1eb70..a491c8728 100644 --- a/src/languages/eu.js +++ b/src/languages/eu.js @@ -191,6 +191,7 @@ export default { here: "Hemen", Required: "Beharrezkoa", telegram: "Telegram", + "ZohoCliq": "ZohoCliq", "Bot Token": "Bot Tokena", wayToGetTelegramToken: "You can get a token from {0}.", "Chat ID": "Txat IDa", @@ -221,6 +222,7 @@ export default { teams: "Microsoft Teams", "Webhook URL": "Webhook URL", wayToGetTeamsURL: "You can learn how to create a webhook URL {0}.", + wayToGetZohoCliqURL: "You can learn how to create a webhook URL {0}.", signal: "Signal", Number: "Zenbakia", Recipients: "Recipients", From 68bc7ac421baf0234ccf51059108dfb3d88cd943 Mon Sep 17 00:00:00 2001 From: panos Date: Thu, 8 Dec 2022 13:41:05 +0200 Subject: [PATCH 03/12] zoho cliq code style --- server/notification-providers/zoho-cliq.js | 36 ++++++++++------------ 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/server/notification-providers/zoho-cliq.js b/server/notification-providers/zoho-cliq.js index d944089d4..61fc68bec 100644 --- a/server/notification-providers/zoho-cliq.js +++ b/server/notification-providers/zoho-cliq.js @@ -43,8 +43,7 @@ class ZohoCliq extends NotificationProvider { monitorMessage, monitorName, monitorUrl, - }) => { - + }) => { const payload = ["### Uptime Kuma\n"]; payload.push(this._statusMessageFactory(status, monitorName)); payload.push(`*Description:* ${monitorMessage}`); @@ -74,23 +73,6 @@ class ZohoCliq extends NotificationProvider { return this._sendNotification(webhookUrl, payload); }; - _monitorUrlFactory = (monitorJSON) => { - let url; - switch(monitorJSON["type"]) { - case "http": - case "keywork": - url = monitorJSON["url"]; - break; - case "docker": - url = monitorJSON["docker_host"]; - break; - default: - url = monitorJSON["hostname"]; - break; - } - return url; - }; - async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { let okMsg = "Sent Successfully."; @@ -100,10 +82,24 @@ class ZohoCliq extends NotificationProvider { return okMsg; } + let url; + switch(monitorJSON["type"]) { + case "http": + case "keywork": + url = monitorJSON["url"]; + break; + case "docker": + url = monitorJSON["docker_host"]; + break; + default: + url = monitorJSON["hostname"]; + break; + } + const payload = this._notificationPayloadFactory({ monitorMessage: heartbeatJSON.msg, monitorName: monitorJSON.name, - monitorUrl: this._monitorUrlFactory(monitorJSON), + monitorUrl: url, status: heartbeatJSON.status, }); From 851a04b08215020c1c2d21418189f17c80b5ce44 Mon Sep 17 00:00:00 2001 From: panos Date: Thu, 8 Dec 2022 13:53:02 +0200 Subject: [PATCH 04/12] zoho cliq code style --- server/notification-providers/zoho-cliq.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/notification-providers/zoho-cliq.js b/server/notification-providers/zoho-cliq.js index 61fc68bec..b7885be42 100644 --- a/server/notification-providers/zoho-cliq.js +++ b/server/notification-providers/zoho-cliq.js @@ -1,6 +1,6 @@ const NotificationProvider = require("./notification-provider"); const axios = require("axios"); -const {DOWN, UP} = require("../../src/util"); +const { DOWN, UP } = require("../../src/util"); class ZohoCliq extends NotificationProvider { @@ -44,7 +44,8 @@ class ZohoCliq extends NotificationProvider { monitorName, monitorUrl, }) => { - const payload = ["### Uptime Kuma\n"]; + const payload = []; + payload.push("### Uptime Kuma\n"); payload.push(this._statusMessageFactory(status, monitorName)); payload.push(`*Description:* ${monitorMessage}`); @@ -83,7 +84,7 @@ class ZohoCliq extends NotificationProvider { } let url; - switch(monitorJSON["type"]) { + switch (monitorJSON["type"]) { case "http": case "keywork": url = monitorJSON["url"]; @@ -100,7 +101,7 @@ class ZohoCliq extends NotificationProvider { monitorMessage: heartbeatJSON.msg, monitorName: monitorJSON.name, monitorUrl: url, - status: heartbeatJSON.status, + status: heartbeatJSON.status }); await this._sendNotification(notification.webhookUrl, payload); From 9da28fbbc75b16b0d90dd013057666b20be641c9 Mon Sep 17 00:00:00 2001 From: panos Date: Thu, 8 Dec 2022 13:56:02 +0200 Subject: [PATCH 05/12] zoho cliq code style --- server/notification-providers/zoho-cliq.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/notification-providers/zoho-cliq.js b/server/notification-providers/zoho-cliq.js index b7885be42..749647d06 100644 --- a/server/notification-providers/zoho-cliq.js +++ b/server/notification-providers/zoho-cliq.js @@ -26,8 +26,8 @@ class ZohoCliq extends NotificationProvider { * @param {string} webhookUrl URL to send the request to * @param {Array} payload Payload generated by _notificationPayloadFactory */ - _sendNotification = async(webhookUrl, payload) => { - await axios.post(webhookUrl, {text: payload.join("\n")}); + _sendNotification = async (webhookUrl, payload) => { + await axios.post(webhookUrl, { text: payload.join("\n") }); }; /** @@ -39,10 +39,10 @@ class ZohoCliq extends NotificationProvider { * @returns {Array} */ _notificationPayloadFactory = ({ - status, - monitorMessage, - monitorName, - monitorUrl, + status, + monitorMessage, + monitorName, + monitorUrl, }) => { const payload = []; payload.push("### Uptime Kuma\n"); @@ -107,7 +107,7 @@ class ZohoCliq extends NotificationProvider { await this._sendNotification(notification.webhookUrl, payload); return okMsg; - } catch(error) { + } catch (error) { this.throwGeneralAxiosError(error); } } From c79b2913a2a36f24c9069294661b5bc4f31b6c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Haugsb=C3=B8?= Date: Sun, 18 Dec 2022 17:16:19 +0100 Subject: [PATCH 06/12] Auth: Case insensitive login check on username Allows users to add users with capital letters and then login with just lowercase letters. We accidentally capitalized the first letter of our username so the other people using it frequently thinks they wrote the wrong password. --- server/auth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/auth.js b/server/auth.js index 3ce1a6041..9bb9dd01d 100644 --- a/server/auth.js +++ b/server/auth.js @@ -15,7 +15,7 @@ exports.login = async function (username, password) { return null; } - let user = await R.findOne("user", " username = ? AND active = 1 ", [ + let user = await R.findOne("user", " username LIKE ? AND active = 1 ", [ username, ]); From b3ac7c3d433568cd9737e1cb563efd9d19a073d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Haugsb=C3=B8?= Date: Mon, 19 Dec 2022 12:18:33 +0100 Subject: [PATCH 07/12] Username case insensitive, patch db instead of using LIKE --- db/patch-user-username-case-insensitive.sql | 47 +++++++++++++++++++++ server/auth.js | 2 +- server/database.js | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 db/patch-user-username-case-insensitive.sql diff --git a/db/patch-user-username-case-insensitive.sql b/db/patch-user-username-case-insensitive.sql new file mode 100644 index 000000000..90b7f1cb2 --- /dev/null +++ b/db/patch-user-username-case-insensitive.sql @@ -0,0 +1,47 @@ +CREATE TABLE [temp_user]( + [id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + [username] VARCHAR(255) NOT NULL UNIQUE COLLATE NOCASE, + [password] VARCHAR(255), + [active] BOOLEAN NOT NULL DEFAULT 1, + [timezone] VARCHAR(150), + twofa_secret VARCHAR(64), + twofa_status BOOLEAN default 0 NOT NULL, + twofa_last_token VARCHAR(6) +); + +INSERT INTO [temp_user] SELECT +[id], +[username], +[password], +[active], +[timezone], +twofa_secret, +twofa_status, +twofa_last_token + FROM user; + +DROP TABLE user; + +CREATE TABLE [user]( + [id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + [username] VARCHAR(255) NOT NULL UNIQUE COLLATE NOCASE, + [password] VARCHAR(255), + [active] BOOLEAN NOT NULL DEFAULT 1, + [timezone] VARCHAR(150), + twofa_secret VARCHAR(64), + twofa_status BOOLEAN default 0 NOT NULL, + twofa_last_token VARCHAR(6) +); + +INSERT INTO [user] SELECT +[id], +[username], +[password], +[active], +[timezone], +twofa_secret, +twofa_status, +twofa_last_token + FROM [temp_user]; + +DROP TABLE [temp_user]; diff --git a/server/auth.js b/server/auth.js index 9bb9dd01d..b4eeee41f 100644 --- a/server/auth.js +++ b/server/auth.js @@ -15,7 +15,7 @@ exports.login = async function (username, password) { return null; } - let user = await R.findOne("user", " username LIKE ? AND active = 1 ", [ + let user = await R.findOne("user", " username = ? AND active = 1", [ username, ]); diff --git a/server/database.js b/server/database.js index 2544f1972..7764df3f6 100644 --- a/server/database.js +++ b/server/database.js @@ -66,6 +66,7 @@ class Database { "patch-add-radius-monitor.sql": true, "patch-monitor-add-resend-interval.sql": true, "patch-maintenance-table2.sql": true, + "patch-user-username-case-insensitive.sql": { parents: [ "patch-2fa-invalidate-used-token.sql", "patch-2fa.sql" ] } }; /** From c60b741406d45c7678e16a53500f1359678bd95c Mon Sep 17 00:00:00 2001 From: 401Unauthorized Date: Tue, 27 Dec 2022 14:05:45 +0800 Subject: [PATCH 08/12] Add kook notification provider --- server/notification-providers/kook.js | 31 +++++++++++++++++++++++ server/notification.js | 2 ++ src/components/notifications/Kook.vue | 36 +++++++++++++++++++++++++++ src/components/notifications/index.js | 2 ++ src/languages/en.js | 4 +++ src/languages/zh-CN.js | 4 +++ 6 files changed, 79 insertions(+) create mode 100644 server/notification-providers/kook.js create mode 100644 src/components/notifications/Kook.vue diff --git a/server/notification-providers/kook.js b/server/notification-providers/kook.js new file mode 100644 index 000000000..b37b75ab1 --- /dev/null +++ b/server/notification-providers/kook.js @@ -0,0 +1,31 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +class Kook extends NotificationProvider { + + name = "Kook"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + let url = "https://www.kookapp.cn/api/v3/message/create"; + let data = { + target_id: notification.kookGuildID, + content: msg, + }; + let config = { + headers: { + "Authorization": "Bot " + notification.kookBotToken, + "Content-Type": "application/json", + }, + }; + try { + await axios.post(url, data, config); + return okMsg; + + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = Kook; diff --git a/server/notification.js b/server/notification.js index 9069601b4..6ff42e013 100644 --- a/server/notification.js +++ b/server/notification.js @@ -14,6 +14,7 @@ const GoogleChat = require("./notification-providers/google-chat"); const Gorush = require("./notification-providers/gorush"); const Gotify = require("./notification-providers/gotify"); const HomeAssistant = require("./notification-providers/home-assistant"); +const Kook = require("./notification-providers/kook"); const Line = require("./notification-providers/line"); const LineNotify = require("./notification-providers/linenotify"); const LunaSea = require("./notification-providers/lunasea"); @@ -70,6 +71,7 @@ class Notification { new Gorush(), new Gotify(), new HomeAssistant(), + new Kook(), new Line(), new LineNotify(), new LunaSea(), diff --git a/src/components/notifications/Kook.vue b/src/components/notifications/Kook.vue new file mode 100644 index 000000000..d618750b7 --- /dev/null +++ b/src/components/notifications/Kook.vue @@ -0,0 +1,36 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 0c220b717..a2ba485ff 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -12,6 +12,7 @@ import GoogleChat from "./GoogleChat.vue"; import Gorush from "./Gorush.vue"; import Gotify from "./Gotify.vue"; import HomeAssistant from "./HomeAssistant.vue"; +import Kook from "./Kook.vue"; import Line from "./Line.vue"; import LineNotify from "./LineNotify.vue"; import LunaSea from "./LunaSea.vue"; @@ -63,6 +64,7 @@ const NotificationFormList = { "gorush": Gorush, "gotify": Gotify, "HomeAssistant": HomeAssistant, + "Kook": Kook, "line": Line, "LineNotify": LineNotify, "lunasea": LunaSea, diff --git a/src/languages/en.js b/src/languages/en.js index e760f92ea..786185f35 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -270,6 +270,10 @@ export default { apprise: "Apprise (Support 50+ Notification services)", GoogleChat: "Google Chat (Google Workspace only)", pushbullet: "Pushbullet", + Kook: "Kook", + wayToGetKookBotToken: "Create application and get your bot token at {0}", + wayToGetKookGuildID: "Switch on 'Developer Mode' in Kook setting, and right click the guild to get its ID", + "Guild ID": "Guild ID", line: "Line Messenger", mattermost: "Mattermost", "User Key": "User Key", diff --git a/src/languages/zh-CN.js b/src/languages/zh-CN.js index ff11c7e9b..5878758c9 100644 --- a/src/languages/zh-CN.js +++ b/src/languages/zh-CN.js @@ -250,6 +250,10 @@ export default { apprise: "Apprise (支持 50+ 种通知服务)", GoogleChat: "Google Chat(仅 Google Workspace)", pushbullet: "Pushbullet", + Kook: "Kook", + wayToGetKookBotToken: "在 {0} 创建应用并获取机器人 Token", + wayToGetKookGuildID: "在Kook设置中打开 ‘开发者模式’,然后右键频道可获取其 ID", + "Guild ID": "频道 ID", line: "Line Messenger", mattermost: "Mattermost", "User Key": "User Key", From 50b84f5f453d92052aac37a5060b4429a0ae5c57 Mon Sep 17 00:00:00 2001 From: 401Unauthorized Date: Tue, 27 Dec 2022 14:10:19 +0800 Subject: [PATCH 09/12] fix code style: add missing semicolon --- src/components/notifications/Kook.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/notifications/Kook.vue b/src/components/notifications/Kook.vue index d618750b7..7027b5e13 100644 --- a/src/components/notifications/Kook.vue +++ b/src/components/notifications/Kook.vue @@ -32,5 +32,5 @@ export default { components: { HiddenInput, } -} +}; From 4147a4c4040512670be065f9ad29b94d511b7248 Mon Sep 17 00:00:00 2001 From: minhhoang Date: Wed, 28 Dec 2022 22:31:33 +0700 Subject: [PATCH 10/12] fix: #2480 --- server/model/monitor.js | 2 +- server/server.js | 1 + server/util-server.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 186962b08..b6e950322 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -548,7 +548,7 @@ class Monitor extends BeanModel { log.debug("monitor:", `gRPC response: ${JSON.stringify(response)}`); let responseData = response.data; if (responseData.length > 50) { - responseData = response.substring(0, 47) + "..."; + responseData = responseData.toString().substring(0, 47) + "..."; } if (response.code !== 1) { bean.status = DOWN; diff --git a/server/server.js b/server/server.js index 594c29b31..5473cecd4 100644 --- a/server/server.js +++ b/server/server.js @@ -714,6 +714,7 @@ let needSetup = false; bean.authDomain = monitor.authDomain; bean.grpcUrl = monitor.grpcUrl; bean.grpcProtobuf = monitor.grpcProtobuf; + bean.grpcServiceName = monitor.grpcServiceName; bean.grpcMethod = monitor.grpcMethod; bean.grpcBody = monitor.grpcBody; bean.grpcMetadata = monitor.grpcMetadata; diff --git a/server/util-server.js b/server/util-server.js index 0bf69133b..ffc3b3d95 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -787,7 +787,7 @@ module.exports.grpcQuery = async (options) => { data: "" }); } else { - log.debug("monitor:", `gRPC response: ${response}`); + log.debug("monitor:", `gRPC response: ${JSON.stringify(response)}`); return resolve({ code: 1, errorMessage: "", From d111db0321fdd19886d107052c85b46ae77a1b9e Mon Sep 17 00:00:00 2001 From: minhhoang Date: Thu, 29 Dec 2022 08:10:58 +0700 Subject: [PATCH 11/12] fix: add accurate error message when user input invalid service name or method name --- server/util-server.js | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/server/util-server.js b/server/util-server.js index ffc3b3d95..2ce6de3ee 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -778,22 +778,31 @@ module.exports.grpcQuery = async (options) => { cb); }, false, false); return new Promise((resolve, _) => { - return grpcService[`${grpcMethod}`](JSON.parse(grpcBody), function (err, response) { - const responseData = JSON.stringify(response); - if (err) { - return resolve({ - code: err.code, - errorMessage: err.details, - data: "" - }); - } else { - log.debug("monitor:", `gRPC response: ${JSON.stringify(response)}`); - return resolve({ - code: 1, - errorMessage: "", - data: responseData - }); - } - }); + try { + return grpcService[`${grpcMethod}`](JSON.parse(grpcBody), function (err, response) { + const responseData = JSON.stringify(response); + if (err) { + return resolve({ + code: err.code, + errorMessage: err.details, + data: "" + }); + } else { + log.debug("monitor:", `gRPC response: ${JSON.stringify(response)}`); + return resolve({ + code: 1, + errorMessage: "", + data: responseData + }); + } + }); + } catch (err) { + return resolve({ + code: -1, + errorMessage: `Error ${err}. Please review your gRPC configuration option. The service name must not include package name value, and the method name must follow camelCase format`, + data: "" + }); + } + }); }; From 1006fbd873002e862d44ea801419031390a8ffed Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Fri, 30 Dec 2022 13:46:34 +0800 Subject: [PATCH 12/12] A possible fix for #2447 --- server/model/monitor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 186962b08..54899a0a7 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -1090,7 +1090,7 @@ class Monitor extends BeanModel { // Prevent if the msg is undefined, notifications such as Discord cannot send out. const heartbeatJSON = bean.toJSON(); if (!heartbeatJSON["msg"]) { - heartbeatJSON["msg"] = ""; + heartbeatJSON["msg"] = "N/A"; } await Notification.send(JSON.parse(notification.config), msg, await monitor.toJSON(false), heartbeatJSON);