Fixed review from owner

This commit is contained in:
0xsid0703 2026-01-18 03:39:13 +01:00
parent 645aecc3ba
commit 5624d257ce
2 changed files with 36 additions and 35 deletions

View File

@ -1505,43 +1505,43 @@ class Monitor extends BeanModel {
let msg = `[${monitor.name}] [${text}] ${bean.msg}`;
const heartbeatJSON = await bean.toJSONAsync({ decodeResponse: true });
const monitorData = [{ id: monitor.id, active: monitor.active, name: monitor.name }];
const preloadData = await Monitor.preparePreloadData(monitorData);
// Prevent if the msg is undefined, notifications such as Discord cannot send out.
if (!heartbeatJSON["msg"]) {
heartbeatJSON["msg"] = "N/A";
}
// Also provide the time in server timezone
heartbeatJSON["timezone"] = await UptimeKumaServer.getInstance().getTimezone();
heartbeatJSON["timezoneOffset"] = UptimeKumaServer.getInstance().getTimezoneOffset();
heartbeatJSON["localDateTime"] = dayjs
.utc(heartbeatJSON["time"])
.tz(heartbeatJSON["timezone"])
.format(SQL_DATETIME_FORMAT);
// Calculate downtime tracking information when service comes back up
// This makes downtime information available to all notification providers
if (bean.status === UP && monitor.id) {
try {
const lastDownHeartbeat = await R.getRow(
"SELECT time FROM heartbeat WHERE monitor_id = ? AND status = ? ORDER BY time DESC LIMIT 1",
[monitor.id, DOWN]
);
if (lastDownHeartbeat && lastDownHeartbeat.time) {
heartbeatJSON["lastDownTime"] = lastDownHeartbeat.time;
}
} catch (error) {
// If we can't calculate downtime, just continue without it
// Silently fail to avoid disrupting notification sending
log.debug("monitor", `[${monitor.name}] Could not calculate downtime information: ${error.message}`);
}
}
for (let notification of notificationList) {
try {
const heartbeatJSON = await bean.toJSONAsync({ decodeResponse: true });
const monitorData = [{ id: monitor.id, active: monitor.active, name: monitor.name }];
const preloadData = await Monitor.preparePreloadData(monitorData);
// Prevent if the msg is undefined, notifications such as Discord cannot send out.
if (!heartbeatJSON["msg"]) {
heartbeatJSON["msg"] = "N/A";
}
// Also provide the time in server timezone
heartbeatJSON["timezone"] = await UptimeKumaServer.getInstance().getTimezone();
heartbeatJSON["timezoneOffset"] = UptimeKumaServer.getInstance().getTimezoneOffset();
heartbeatJSON["localDateTime"] = dayjs
.utc(heartbeatJSON["time"])
.tz(heartbeatJSON["timezone"])
.format(SQL_DATETIME_FORMAT);
// Calculate downtime tracking information when service comes back up
// This makes downtime information available to all notification providers
if (bean.status === UP && monitor.id) {
try {
const lastDownHeartbeat = await R.getRow(
"SELECT time FROM heartbeat WHERE monitor_id = ? AND status = ? ORDER BY time DESC LIMIT 1",
[monitor.id, DOWN]
);
if (lastDownHeartbeat && lastDownHeartbeat.time) {
heartbeatJSON["lastDownTime"] = lastDownHeartbeat.time;
}
} catch (error) {
// If we can't calculate downtime, just continue without it
// Silently fail to avoid disrupting notification sending
log.debug("monitor", `[${monitor.name}] Could not calculate downtime information: ${error.message}`);
}
}
await Notification.send(
JSON.parse(notification.config),
msg,

View File

@ -127,6 +127,7 @@ class Discord extends NotificationProvider {
const durationSeconds = backOnlineTimestamp - wentOfflineTimestamp;
// Format duration as human-readable string (e.g., "1h 23m", "45m 30s")
// TODO: Update below to Intl.DurationFormat("en", { style: "short" }).format(duration) once we are on a newer node version
const hours = Math.floor(durationSeconds / 3600);
const minutes = Math.floor((durationSeconds % 3600) / 60);
const seconds = durationSeconds % 60;