Merge branch 'develop' into feat/choose-disks-monitor

This commit is contained in:
Antonin committed 2025-11-30 11:35:34 +01:00
commit 913f7a9e42
3 files changed
+37 -4

No files matched your search

+25
View File
@@ -10,6 +10,31 @@ PS: **We work closely with contributors on our [Discord channel](https://discord
--- ---
## 🚀 Quick Setup Checklist
Before you dive in, make sure you have these installed:
```bash
# Check Node.js (v16+ required)
node --version
# Check npm
npm --version
# Check Docker
docker --version
# Check Git
git --version
```
**New to contributing?** Start here:
1. Pick a [`good-first-issue`](https://github.com/bluewave-labs/checkmate/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)
2. Comment that you'd like to work on it
3. Follow the [setup guide](#set-up-checkmate-locally) below
4. Join our [Discord](https://discord.com/invite/NAb6H3UTjK) if you get stuck
## Table of contents ## Table of contents
- [How do I...?](#how-do-i) - [How do I...?](#how-do-i)
+1
View File
@@ -173,6 +173,7 @@ export const initializeServices = async ({ logger, envSettings, settingsService
const notificationUtils = new NotificationUtils({ const notificationUtils = new NotificationUtils({
stringService, stringService,
emailService, emailService,
settingsService,
}); });
const notificationService = new NotificationService({ const notificationService = new NotificationService({
@@ -3,9 +3,10 @@ const SERVICE_NAME = "NotificationUtils";
class NotificationUtils { class NotificationUtils {
static SERVICE_NAME = SERVICE_NAME; static SERVICE_NAME = SERVICE_NAME;
constructor({ stringService, emailService }) { constructor({ stringService, emailService, settingsService }) {
this.stringService = stringService; this.stringService = stringService;
this.emailService = emailService; this.emailService = emailService;
this.settingsService = settingsService;
} }
get serviceName() { get serviceName() {
@@ -101,6 +102,8 @@ class NotificationUtils {
const metrics = networkResponse?.payload?.data; const metrics = networkResponse?.payload?.data;
const { cpu: { usage_percent: cpuUsage = -1 } = {}, memory: { usage_percent: memoryUsage = -1 } = {}, disk = [] } = metrics; const { cpu: { usage_percent: cpuUsage = -1 } = {}, memory: { usage_percent: memoryUsage = -1 } = {}, disk = [] } = metrics;
const { clientHost } = this.settingsService.getSettings();
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,
@@ -113,12 +116,13 @@ class NotificationUtils {
{ name: "Monitor", value: monitor.name, inline: true }, { name: "Monitor", value: monitor.name, inline: true },
{ name: "URL", value: monitor.url, inline: false }, { name: "URL", value: monitor.url, inline: false },
]; ];
const goToIncidentField = { name: `Go to incident`, value: `${clientHost}/infrastructure/${monitor._id}` };
const formatDiscordAlert = { const formatDiscordAlert = {
cpu: () => ({ cpu: () => ({
title: "CPU alert", title: "CPU alert",
description: `Your current CPU usage (${(cpuUsage * 100).toFixed(0)}%) is above your threshold (${(cpuThreshold * 100).toFixed(0)}%)`, description: `Your current CPU usage (${(cpuUsage * 100).toFixed(0)}%) is above your threshold (${(cpuThreshold * 100).toFixed(0)}%)`,
color: 15548997, color: 15548997,
fields: monitorInfoFields, fields: [...monitorInfoFields, goToIncidentField],
footer: { text: "Checkmate" }, footer: { text: "Checkmate" },
}), }),
@@ -126,7 +130,7 @@ class NotificationUtils {
title: "Memory alert", title: "Memory alert",
description: `Your current memory usage (${(memoryUsage * 100).toFixed(0)}%) is above your threshold (${(memoryThreshold * 100).toFixed(0)}%)`, description: `Your current memory usage (${(memoryUsage * 100).toFixed(0)}%) is above your threshold (${(memoryThreshold * 100).toFixed(0)}%)`,
color: 15548997, color: 15548997,
fields: monitorInfoFields, fields: [...monitorInfoFields, goToIncidentField],
footer: { text: "Checkmate" }, footer: { text: "Checkmate" },
}), }),
@@ -142,6 +146,7 @@ class NotificationUtils {
value: `${(d?.usage_percent * 100).toFixed(0)}%`, value: `${(d?.usage_percent * 100).toFixed(0)}%`,
inline: true, inline: true,
})), })),
goToIncidentField,
], ],
}), }),
}; };
@@ -184,8 +189,10 @@ class NotificationUtils {
}; };
buildHardwareNotificationMessage = (alerts, monitor) => { buildHardwareNotificationMessage = (alerts, monitor) => {
const { clientHost } = this.settingsService.getSettings();
const alertsHeader = [`Monitor: ${monitor.name}`, `URL: ${monitor.url}`]; const alertsHeader = [`Monitor: ${monitor.name}`, `URL: ${monitor.url}`];
const alertText = alerts.length > 0 ? [...alertsHeader, ...alerts] : []; const alertFooter = [`Go to incident: ${clientHost}/infrastructure/${monitor._id}`];
const alertText = alerts.length > 0 ? [...alertsHeader, ...alerts, ...alertFooter] : [];
return alertText.map((alert) => alert).join("\n"); return alertText.map((alert) => alert).join("\n");
}; };
buildHardwareWebhookBody = (alerts, monitor) => { buildHardwareWebhookBody = (alerts, monitor) => {