Add Discord webhook notification support
This commit is contained in:
1 parent
e4f2cfb978
commit
28f5d355a7
2 files changed
+22
-1
No files matched your search
@@ -8,7 +8,7 @@ const NotificationSchema = mongoose.Schema(
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
enum: ["email", "sms"],
|
||||
enum: ["email", "sms", "discord"],
|
||||
},
|
||||
address: {
|
||||
type: String,
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user