Add Discord webhook notification support

This commit is contained in:
Skorpios committed 2025-01-22 15:41:47 -08:00
1 parent e4f2cfb978
commit 28f5d355a7
2 files changed
+22 -1

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ const NotificationSchema = mongoose.Schema(
},
type: {
type: String,
enum: ["email", "sms"],
enum: ["email", "sms", "discord"],
},
address: {
type: String,
+21
View File
@@ -1,4 +1,5 @@
const SERVICE_NAME = "NotificationService";
import axios from 'axios';
class NotificationService {
static SERVICE_NAME = SERVICE_NAME;
@@ -16,6 +17,26 @@ class NotificationService {
this.logger = logger;
}
async sendDiscordNotification(networkResponse, webhookUrl) {
const { monitor, status } = networkResponse;
const message = {
content: `Monitor ${monitor.name} is ${status ? "up" : "down"}. URL: ${monitor.url}`
};
try {
await axios.post(webhookUrl, message);
return true;
} catch (error) {
this.logger.error({
message: error.message,
service: this.SERVICE_NAME,
method: "sendDiscordNotification",
stack: error.stack,
});
return false;
}
}
/**
* Sends an email notification for hardware infrastructure alerts
*