inject logger
This commit is contained in:
1 parent
7c9410f9d7
commit
bebb5d6942
9 files changed
+125
-18
No files matched your search
@@ -1,9 +1,10 @@
|
||||
import type { Monitor, Notification, MonitorStatusResponse } from "@/types/index.js";
|
||||
import { INotificationProvider } from "@/service/index.js";
|
||||
import { buildHardwareAlerts, buildDiscordBody } from "@/service/infrastructure/notificationProviders/utils.js";
|
||||
import { buildHardwareAlerts, buildDiscordBody, getTestMessage } from "@/service/infrastructure/notificationProviders/utils.js";
|
||||
import got from "got";
|
||||
|
||||
export class DiscordProvider implements INotificationProvider {
|
||||
constructor(private logger: any) {}
|
||||
private getHardwareContent = (monitor: Monitor, monitorStatusResponse: MonitorStatusResponse) => {
|
||||
const { discordPayload } = buildHardwareAlerts("HOST_PLACEHOLDER", monitor, monitorStatusResponse);
|
||||
return discordPayload;
|
||||
@@ -22,6 +23,7 @@ export class DiscordProvider implements INotificationProvider {
|
||||
}
|
||||
|
||||
try {
|
||||
this.logger?.debug?.("Sending Discord alert", { address: notification.address });
|
||||
await got.post(notification.address, {
|
||||
json: body,
|
||||
headers: {
|
||||
@@ -31,10 +33,27 @@ export class DiscordProvider implements INotificationProvider {
|
||||
});
|
||||
return true;
|
||||
} catch (error: any) {
|
||||
this.logger?.error?.("Discord alert failed", { error });
|
||||
return false;
|
||||
}
|
||||
};
|
||||
sendTestAlert = async (notification: Notification) => {
|
||||
return false;
|
||||
if (!notification.address) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
this.logger?.debug?.("Sending Discord test alert", { address: notification.address });
|
||||
await got.post(notification.address, {
|
||||
json: { content: getTestMessage() },
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
responseType: "json",
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
this.logger?.error?.("Discord test alert failed", { error });
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user