update providers
This commit is contained in:
1 parent
8020bfde21
commit
be8580ee99
9 files changed
+140
-35
No files matched your search
@@ -41,6 +41,7 @@ export class NotificationsService implements INotificationsService {
|
||||
createdAt: number;
|
||||
}
|
||||
>;
|
||||
private currentDecision?: MonitorActionDecision;
|
||||
|
||||
constructor(
|
||||
notificationsRepository: INotificationsRepository,
|
||||
@@ -83,17 +84,17 @@ export class NotificationsService implements INotificationsService {
|
||||
private send = async (notification: Notification, monitor: Monitor, monitorStatusResponse: MonitorStatusResponse): Promise<boolean> => {
|
||||
switch (notification.type) {
|
||||
case "email":
|
||||
return await this.emailProvider.sendAlert(notification, monitor, monitorStatusResponse);
|
||||
return await this.emailProvider.sendAlert(notification, monitor, monitorStatusResponse, this.currentDecision!);
|
||||
case "slack":
|
||||
return await this.slackProvider.sendAlert(notification, monitor, monitorStatusResponse);
|
||||
return await this.slackProvider.sendAlert(notification, monitor, monitorStatusResponse, this.currentDecision!);
|
||||
case "discord":
|
||||
return await this.discordProvider.sendAlert(notification, monitor, monitorStatusResponse);
|
||||
return await this.discordProvider.sendAlert(notification, monitor, monitorStatusResponse, this.currentDecision!);
|
||||
case "pager_duty":
|
||||
return await this.pagerDutyProvider.sendAlert(notification, monitor, monitorStatusResponse);
|
||||
return await this.pagerDutyProvider.sendAlert(notification, monitor, monitorStatusResponse, this.currentDecision!);
|
||||
case "matrix":
|
||||
return await this.matrixProvider.sendAlert(notification, monitor, monitorStatusResponse);
|
||||
return await this.matrixProvider.sendAlert(notification, monitor, monitorStatusResponse, this.currentDecision!);
|
||||
case "webhook":
|
||||
return await this.webhookProvider.sendAlert(notification, monitor, monitorStatusResponse);
|
||||
return await this.webhookProvider.sendAlert(notification, monitor, monitorStatusResponse, this.currentDecision!);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -157,7 +158,15 @@ export class NotificationsService implements INotificationsService {
|
||||
this.pendingEmailGroups.delete(key);
|
||||
|
||||
try {
|
||||
await this.flushEmailGroup(notification, group.monitors, group.statusResponses);
|
||||
// For grouped notifications (always DOWN), create a decision
|
||||
const groupedDecision: MonitorActionDecision = {
|
||||
shouldCreateIncident: false,
|
||||
shouldResolveIncident: false,
|
||||
shouldSendNotification: true,
|
||||
incidentReason: "status_down",
|
||||
notificationReason: "status_change",
|
||||
};
|
||||
await this.flushEmailGroup(notification, group.monitors, group.statusResponses, groupedDecision);
|
||||
} catch (error: any) {
|
||||
this.logger.error({
|
||||
message: error?.message,
|
||||
@@ -196,7 +205,12 @@ export class NotificationsService implements INotificationsService {
|
||||
* @param statusResponses Array of status responses (parallel to monitors)
|
||||
* @returns true if email was sent successfully, false otherwise
|
||||
*/
|
||||
private flushEmailGroup = async (notification: Notification, monitors: Monitor[], statusResponses: MonitorStatusResponse[]): Promise<boolean> => {
|
||||
private flushEmailGroup = async (
|
||||
notification: Notification,
|
||||
monitors: Monitor[],
|
||||
statusResponses: MonitorStatusResponse[],
|
||||
decision: MonitorActionDecision
|
||||
): Promise<boolean> => {
|
||||
if (!monitors.length || !statusResponses.length) {
|
||||
return false;
|
||||
}
|
||||
@@ -221,7 +235,7 @@ export class NotificationsService implements INotificationsService {
|
||||
};
|
||||
|
||||
// Reuse existing email provider to send grouped notification.
|
||||
return await this.emailProvider.sendAlert(notification, syntheticMonitor, baseStatus);
|
||||
return await this.emailProvider.sendAlert(notification, syntheticMonitor, baseStatus, decision);
|
||||
};
|
||||
|
||||
handleNotifications = async (monitor: Monitor, monitorStatusResponse: MonitorStatusResponse, decision: MonitorActionDecision) => {
|
||||
@@ -230,6 +244,9 @@ export class NotificationsService implements INotificationsService {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Store decision for use in send method
|
||||
this.currentDecision = decision;
|
||||
|
||||
// Send notifications based on decision
|
||||
return await this.sendNotifications(monitor, monitorStatusResponse);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user