[]>}
*/
async getTags() {
- return await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [ this.id ]);
+ return await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ? ORDER BY tag.name", [ this.id ]);
}
/**
@@ -203,7 +204,7 @@ class Monitor extends BeanModel {
let previousBeat = null;
let retries = 0;
- let prometheus = new Prometheus(this);
+ this.prometheus = new Prometheus(this);
const beat = async () => {
@@ -272,17 +273,29 @@ class Monitor extends BeanModel {
log.debug("monitor", `[${this.name}] Prepare Options for axios`);
+ let contentType = null;
+ let bodyValue = null;
+
+ if (this.body && !this.httpBodyEncoding || this.httpBodyEncoding === "json") {
+ bodyValue = JSON.parse(this.body);
+ contentType = "application/json";
+ } else if (this.body && (this.httpBodyEncoding === "xml")) {
+ bodyValue = this.body;
+ contentType = "text/xml; charset=utf-8";
+ }
+
// Axios Options
const options = {
url: this.url,
method: (this.method || "get").toLowerCase(),
- ...(this.body ? { data: JSON.parse(this.body) } : {}),
+ ...(bodyValue ? { data: bodyValue } : {}),
timeout: this.interval * 1000 * 0.8,
headers: {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"User-Agent": "Uptime-Kuma/" + version,
- ...(this.headers ? JSON.parse(this.headers) : {}),
+ ...(contentType ? { "Content-Type": contentType } : {}),
...(basicAuthHeader),
+ ...(this.headers ? JSON.parse(this.headers) : {})
},
maxRedirects: this.maxredirects,
validateStatus: (status) => {
@@ -755,7 +768,7 @@ class Monitor extends BeanModel {
await R.store(bean);
log.debug("monitor", `[${this.name}] prometheus.update`);
- prometheus.update(bean, tlsInfo);
+ this.prometheus?.update(bean, tlsInfo);
previousBeat = bean;
@@ -840,15 +853,15 @@ class Monitor extends BeanModel {
clearTimeout(this.heartbeatInterval);
this.isStop = true;
- this.prometheus().remove();
+ this.prometheus?.remove();
}
/**
- * Get a new prometheus instance
- * @returns {Prometheus}
+ * Get prometheus instance
+ * @returns {Prometheus|undefined}
*/
- prometheus() {
- return new Prometheus(this);
+ getPrometheus() {
+ return this.prometheus;
}
/**
diff --git a/server/notification-providers/slack.js b/server/notification-providers/slack.js
index 5a5d40cb3..da89f0f7a 100644
--- a/server/notification-providers/slack.js
+++ b/server/notification-providers/slack.js
@@ -42,7 +42,7 @@ class Slack extends NotificationProvider {
const time = heartbeatJSON["time"];
const textMsg = "Uptime Kuma Alert";
let data = {
- "text": monitorJSON ? textMsg + `: ${monitorJSON.name}` : textMsg,
+ "text": `${textMsg}\n${msg}`,
"channel": notification.slackchannel,
"username": notification.slackusername,
"icon_emoji": notification.slackiconemo,
diff --git a/server/notification-providers/telegram.js b/server/notification-providers/telegram.js
index 2b0576224..3c490655d 100644
--- a/server/notification-providers/telegram.js
+++ b/server/notification-providers/telegram.js
@@ -9,11 +9,18 @@ class Telegram extends NotificationProvider {
let okMsg = "Sent Successfully.";
try {
+ let params = {
+ chat_id: notification.telegramChatID,
+ text: msg,
+ disable_notification: notification.telegramSendSilently ?? false,
+ protect_content: notification.telegramProtectContent ?? false,
+ };
+ if (notification.telegramMessageThreadID) {
+ params.message_thread_id = notification.telegramMessageThreadID;
+ }
+
await axios.get(`https://api.telegram.org/bot${notification.telegramBotToken}/sendMessage`, {
- params: {
- chat_id: notification.telegramChatID,
- text: msg,
- },
+ params: params,
});
return okMsg;
diff --git a/server/routers/api-router.js b/server/routers/api-router.js
index 665163aee..2d5f96617 100644
--- a/server/routers/api-router.js
+++ b/server/routers/api-router.js
@@ -1,5 +1,5 @@
let express = require("express");
-const { allowDevAllOrigin, allowAllOrigin, percentageToColor, filterAndJoin, send403 } = require("../util-server");
+const { allowDevAllOrigin, allowAllOrigin, percentageToColor, filterAndJoin, sendHttpError } = require("../util-server");
const { R } = require("redbean-node");
const apicache = require("../modules/apicache");
const Monitor = require("../model/monitor");
@@ -175,7 +175,7 @@ router.get("/api/badge/:id/status", cache("5 minutes"), async (request, response
response.type("image/svg+xml");
response.send(svg);
} catch (error) {
- send403(response, error.message);
+ sendHttpError(response, error.message);
}
});
@@ -242,7 +242,7 @@ router.get("/api/badge/:id/uptime/:duration?", cache("5 minutes"), async (reques
response.type("image/svg+xml");
response.send(svg);
} catch (error) {
- send403(response, error.message);
+ sendHttpError(response, error.message);
}
});
@@ -303,7 +303,7 @@ router.get("/api/badge/:id/ping/:duration?", cache("5 minutes"), async (request,
response.type("image/svg+xml");
response.send(svg);
} catch (error) {
- send403(response, error.message);
+ sendHttpError(response, error.message);
}
});
@@ -373,7 +373,7 @@ router.get("/api/badge/:id/avg-response/:duration?", cache("5 minutes"), async (
response.type("image/svg+xml");
response.send(svg);
} catch (error) {
- send403(response, error.message);
+ sendHttpError(response, error.message);
}
});
@@ -464,7 +464,7 @@ router.get("/api/badge/:id/cert-exp", cache("5 minutes"), async (request, respon
response.type("image/svg+xml");
response.send(svg);
} catch (error) {
- send403(response, error.message);
+ sendHttpError(response, error.message);
}
});
@@ -536,7 +536,7 @@ router.get("/api/badge/:id/response", cache("5 minutes"), async (request, respon
response.type("image/svg+xml");
response.send(svg);
} catch (error) {
- send403(response, error.message);
+ sendHttpError(response, error.message);
}
});
diff --git a/server/routers/status-page-router.js b/server/routers/status-page-router.js
index de075db8d..28cf5f4c9 100644
--- a/server/routers/status-page-router.js
+++ b/server/routers/status-page-router.js
@@ -2,7 +2,7 @@ let express = require("express");
const apicache = require("../modules/apicache");
const { UptimeKumaServer } = require("../uptime-kuma-server");
const StatusPage = require("../model/status_page");
-const { allowDevAllOrigin, send403 } = require("../util-server");
+const { allowDevAllOrigin, sendHttpError } = require("../util-server");
const { R } = require("redbean-node");
const Monitor = require("../model/monitor");
@@ -44,10 +44,7 @@ router.get("/api/status-page/:slug", cache("5 minutes"), async (request, respons
let statusPageData = await StatusPage.getStatusPageData(statusPage);
if (!statusPageData) {
- response.statusCode = 404;
- response.json({
- msg: "Not Found"
- });
+ sendHttpError(response, "Not Found");
return;
}
@@ -55,7 +52,7 @@ router.get("/api/status-page/:slug", cache("5 minutes"), async (request, respons
response.json(statusPageData);
} catch (error) {
- send403(response, error.message);
+ sendHttpError(response, error.message);
}
});
@@ -103,7 +100,7 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques
});
} catch (error) {
- send403(response, error.message);
+ sendHttpError(response, error.message);
}
});
@@ -119,10 +116,7 @@ router.get("/api/status-page/:slug/manifest.json", cache("1440 minutes"), async
]);
if (!statusPage) {
- response.statusCode = 404;
- response.json({
- msg: "Not Found"
- });
+ sendHttpError(response, "Not Found");
return;
}
@@ -141,7 +135,7 @@ router.get("/api/status-page/:slug/manifest.json", cache("1440 minutes"), async
});
} catch (error) {
- send403(response, error.message);
+ sendHttpError(response, error.message);
}
});
diff --git a/server/server.js b/server/server.js
index 8696aa709..1367662b1 100644
--- a/server/server.js
+++ b/server/server.js
@@ -678,9 +678,6 @@ let needSetup = false;
throw new Error("Permission denied.");
}
- // Reset Prometheus labels
- server.monitorList[monitor.id]?.prometheus()?.remove();
-
bean.name = monitor.name;
bean.type = monitor.type;
bean.url = monitor.url;
@@ -730,6 +727,7 @@ let needSetup = false;
bean.radiusCalledStationId = monitor.radiusCalledStationId;
bean.radiusCallingStationId = monitor.radiusCallingStationId;
bean.radiusSecret = monitor.radiusSecret;
+ bean.httpBodyEncoding = monitor.httpBodyEncoding;
bean.validate();
diff --git a/server/socket-handlers/general-socket-handler.js b/server/socket-handlers/general-socket-handler.js
index 11b47a5bf..bb4a38086 100644
--- a/server/socket-handlers/general-socket-handler.js
+++ b/server/socket-handlers/general-socket-handler.js
@@ -9,10 +9,10 @@ let gameList = null;
/**
* Get a game list via GameDig
- * @returns {any[]}
+ * @returns {Object[]} list of games supported by GameDig
*/
function getGameList() {
- if (!gameList) {
+ if (gameList == null) {
gameList = gameResolver._readGames().games.sort((a, b) => {
if ( a.pretty < b.pretty ) {
return -1;
@@ -22,9 +22,8 @@ function getGameList() {
}
return 0;
});
- } else {
- return gameList;
}
+ return gameList;
}
module.exports.generalSocketHandler = (socket, server) => {
diff --git a/server/util-server.js b/server/util-server.js
index e099f673b..129e15265 100644
--- a/server/util-server.js
+++ b/server/util-server.js
@@ -739,15 +739,27 @@ exports.filterAndJoin = (parts, connector = "") => {
};
/**
- * Send a 403 response
+ * Send an Error response
* @param {Object} res Express response object
* @param {string} [msg=""] Message to send
*/
-module.exports.send403 = (res, msg = "") => {
- res.status(403).json({
- "status": "fail",
- "msg": msg,
- });
+module.exports.sendHttpError = (res, msg = "") => {
+ if (msg.includes("SQLITE_BUSY") || msg.includes("SQLITE_LOCKED")) {
+ res.status(503).json({
+ "status": "fail",
+ "msg": msg,
+ });
+ } else if (msg.toLowerCase().includes("not found")) {
+ res.status(404).json({
+ "status": "fail",
+ "msg": msg,
+ });
+ } else {
+ res.status(403).json({
+ "status": "fail",
+ "msg": msg,
+ });
+ }
};
function timeObjectConvertTimezone(obj, timezone, timeObjectToUTC = true) {
diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue
index 0ca95c222..c3851b568 100644
--- a/src/components/NotificationDialog.vue
+++ b/src/components/NotificationDialog.vue
@@ -13,7 +13,10 @@
@@ -67,7 +70,7 @@
-