From e87e350d6d4a9d41df14da50d8e4d09bb5ffd7ad Mon Sep 17 00:00:00 2001 From: lyc8503 Date: Wed, 5 Nov 2025 01:06:21 +0800 Subject: [PATCH] feat: skip error change notification option --- types/config.ts | 1 + uptime.config.ts | 2 ++ worker/src/index.ts | 20 ++++++++++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/types/config.ts b/types/config.ts index 1ef2f4f..e469f4f 100644 --- a/types/config.ts +++ b/types/config.ts @@ -58,6 +58,7 @@ export type Notification = { timeZone?: string gracePeriod?: number skipNotificationIds?: string[] + skipErrorChangeNotification?: boolean } type SingleWebhook = { diff --git a/uptime.config.ts b/uptime.config.ts index 1589a3c..d5d5dee 100644 --- a/uptime.config.ts +++ b/uptime.config.ts @@ -120,6 +120,8 @@ const workerConfig: WorkerConfig = { gracePeriod: 5, // [Optional] disable notification for monitors with specified ids skipNotificationIds: ['foo_monitor', 'bar_monitor'], + // [Optional] suppress extra notifications for error reason changes during an incident, default to false + skipErrorChangeNotification: true, }, callbacks: { onStatusChange: async ( diff --git a/worker/src/index.ts b/worker/src/index.ts index 8cbc79c..ebadc72 100644 --- a/worker/src/index.ts +++ b/worker/src/index.ts @@ -225,17 +225,21 @@ const Worker = { currentTimeSecond - currentIncident.start[0] < workerConfig.notification.gracePeriod * 60 + 30) ) { - await formatAndNotify( - monitor, - false, - currentIncident.start[0], - currentTimeSecond, - status.err - ) + if (currentIncident.start[0] !== currentTimeSecond && workerConfig.notification?.skipErrorChangeNotification) { + console.log('Skipping notification for following error reason change due to user config') + } else { + await formatAndNotify( + monitor, + false, + currentIncident.start[0], + currentTimeSecond, + status.err + ) + } } else { console.log( `Grace period (${workerConfig.notification - ?.gracePeriod}m) not met (currently down for ${ + ?.gracePeriod}m) not met or no change (currently down for ${ currentTimeSecond - currentIncident.start[0] }s, changed ${monitorStatusChanged}), skipping webhook DOWN notification for ${ monitor.name