2 files changed
+37
-18
No files matched your search
@@ -25,6 +25,7 @@ const Maintenance = () => {
|
|||||||
const [sort, setSort] = useState({});
|
const [sort, setSort] = useState({});
|
||||||
const [updateTrigger, setUpdateTrigger] = useState(false);
|
const [updateTrigger, setUpdateTrigger] = useState(false);
|
||||||
const [networkError, setNetworkError] = useState(false);
|
const [networkError, setNetworkError] = useState(false);
|
||||||
|
const [isDataFetched, setIsDataFetched] = useState(false);
|
||||||
|
|
||||||
const handleActionMenuDelete = () => {
|
const handleActionMenuDelete = () => {
|
||||||
setUpdateTrigger((prev) => !prev);
|
setUpdateTrigger((prev) => !prev);
|
||||||
@@ -42,6 +43,8 @@ const Maintenance = () => {
|
|||||||
setMaintenanceWindowCount(maintenanceWindowCount);
|
setMaintenanceWindowCount(maintenanceWindowCount);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setNetworkError(true);
|
setNetworkError(true);
|
||||||
|
} finally {
|
||||||
|
setIsDataFetched(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchMaintenanceWindows();
|
fetchMaintenanceWindows();
|
||||||
@@ -61,7 +64,8 @@ const Maintenance = () => {
|
|||||||
</GenericFallback>
|
</GenericFallback>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (maintenanceWindows.length === 0) {
|
// Only show the fallback if we've fetched data and there are no maintenance windows
|
||||||
|
if (isDataFetched && maintenanceWindows.length === 0) {
|
||||||
return (
|
return (
|
||||||
<Fallback
|
<Fallback
|
||||||
title="maintenance window"
|
title="maintenance window"
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
const SERVICE_NAME = "NotificationService";
|
const SERVICE_NAME = "NotificationService";
|
||||||
const TELEGRAM_API_BASE_URL = "https://api.telegram.org/bot";
|
const TELEGRAM_API_BASE_URL = "https://api.telegram.org/bot";
|
||||||
const PLATFORM_TYPES = ["telegram", "slack", "discord"];
|
const PLATFORM_TYPES = ["telegram", "slack", "discord", "webhook"];
|
||||||
|
|
||||||
const MESSAGE_FORMATTERS = {
|
const MESSAGE_FORMATTERS = {
|
||||||
telegram: (messageText, chatId) => ({ chat_id: chatId, text: messageText }),
|
telegram: (messageText, chatId) => ({ chat_id: chatId, text: messageText }),
|
||||||
slack: (messageText) => ({ text: messageText }),
|
slack: (messageText) => ({ text: messageText }),
|
||||||
discord: (messageText) => ({ content: messageText }),
|
discord: (messageText) => ({ content: messageText }),
|
||||||
|
webhook: (messageText) => ({ text: messageText }),
|
||||||
};
|
};
|
||||||
|
|
||||||
class NotificationService {
|
class NotificationService {
|
||||||
@@ -45,19 +46,27 @@ class NotificationService {
|
|||||||
const date = new Date(timestamp);
|
const date = new Date(timestamp);
|
||||||
|
|
||||||
// Get timezone abbreviation and format the date
|
// Get timezone abbreviation and format the date
|
||||||
const timeZoneAbbr = date.toLocaleTimeString('en-US', { timeZoneName: 'short' })
|
const timeZoneAbbr = date
|
||||||
.split(' ').pop();
|
.toLocaleTimeString("en-US", { timeZoneName: "short" })
|
||||||
|
.split(" ")
|
||||||
|
.pop();
|
||||||
|
|
||||||
// Format the date with readable format
|
// Format the date with readable format
|
||||||
return date.toLocaleString('en-US', {
|
return (
|
||||||
year: 'numeric',
|
date
|
||||||
month: '2-digit',
|
.toLocaleString("en-US", {
|
||||||
day: '2-digit',
|
year: "numeric",
|
||||||
hour: '2-digit',
|
month: "2-digit",
|
||||||
minute: '2-digit',
|
day: "2-digit",
|
||||||
second: '2-digit',
|
hour: "2-digit",
|
||||||
hour12: false
|
minute: "2-digit",
|
||||||
}).replace(/(\d+)\/(\d+)\/(\d+),\s/, '$3-$1-$2 ') + ' ' + timeZoneAbbr;
|
second: "2-digit",
|
||||||
|
hour12: false,
|
||||||
|
})
|
||||||
|
.replace(/(\d+)\/(\d+)\/(\d+),\s/, "$3-$1-$2 ") +
|
||||||
|
" " +
|
||||||
|
timeZoneAbbr
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get formatted time
|
// Get formatted time
|
||||||
@@ -71,12 +80,12 @@ class NotificationService {
|
|||||||
messageText = this.stringService.monitorUpAlert
|
messageText = this.stringService.monitorUpAlert
|
||||||
.replace("{monitorName}", monitor.name)
|
.replace("{monitorName}", monitor.name)
|
||||||
.replace("{time}", formattedTime)
|
.replace("{time}", formattedTime)
|
||||||
.replace("{code}", code || 'Unknown');
|
.replace("{code}", code || "Unknown");
|
||||||
} else {
|
} else {
|
||||||
messageText = this.stringService.monitorDownAlert
|
messageText = this.stringService.monitorDownAlert
|
||||||
.replace("{monitorName}", monitor.name)
|
.replace("{monitorName}", monitor.name)
|
||||||
.replace("{time}", formattedTime)
|
.replace("{time}", formattedTime)
|
||||||
.replace("{code}", code || 'Unknown');
|
.replace("{code}", code || "Unknown");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PLATFORM_TYPES.includes(platform)) {
|
if (!PLATFORM_TYPES.includes(platform)) {
|
||||||
@@ -112,7 +121,7 @@ class NotificationService {
|
|||||||
message: this.stringService.getWebhookUnsupportedPlatform(platform),
|
message: this.stringService.getWebhookUnsupportedPlatform(platform),
|
||||||
service: this.SERVICE_NAME,
|
service: this.SERVICE_NAME,
|
||||||
method: "sendWebhookNotification",
|
method: "sendWebhookNotification",
|
||||||
details: { platform }
|
details: { platform },
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -123,7 +132,7 @@ class NotificationService {
|
|||||||
message: "Missing required fields for Telegram notification",
|
message: "Missing required fields for Telegram notification",
|
||||||
service: this.SERVICE_NAME,
|
service: this.SERVICE_NAME,
|
||||||
method: "sendWebhookNotification",
|
method: "sendWebhookNotification",
|
||||||
details: { platform }
|
details: { platform },
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -257,7 +266,13 @@ class NotificationService {
|
|||||||
const alerts = {
|
const alerts = {
|
||||||
cpu: cpuThreshold !== -1 && cpuUsage > cpuThreshold ? true : false,
|
cpu: cpuThreshold !== -1 && cpuUsage > cpuThreshold ? true : false,
|
||||||
memory: memoryThreshold !== -1 && memoryUsage > memoryThreshold ? true : false,
|
memory: memoryThreshold !== -1 && memoryUsage > memoryThreshold ? true : false,
|
||||||
disk: disk?.some(d => diskThreshold !== -1 && typeof d?.usage_percent === "number" && d?.usage_percent > diskThreshold) ?? false,
|
disk:
|
||||||
|
disk?.some(
|
||||||
|
(d) =>
|
||||||
|
diskThreshold !== -1 &&
|
||||||
|
typeof d?.usage_percent === "number" &&
|
||||||
|
d?.usage_percent > diskThreshold
|
||||||
|
) ?? false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const notifications = await this.db.getNotificationsByMonitorId(
|
const notifications = await this.db.getNotificationsByMonitorId(
|
||||||
|
|||||||
Reference in new issue
Block a user