From 9bc5deb99d9baf0f14adcc522938dc97b8c6b505 Mon Sep 17 00:00:00 2001 From: lyc8503 Date: Mon, 7 Apr 2025 00:50:16 +0800 Subject: [PATCH] feat #88 notification blacklist --- uptime.config.ts | 2 ++ worker/src/index.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/uptime.config.ts b/uptime.config.ts index d58b158..321dcf3 100644 --- a/uptime.config.ts +++ b/uptime.config.ts @@ -84,6 +84,8 @@ const workerConfig = { // notification will be sent only if the monitor is down for N continuous checks after the initial failure // if not specified, notification will be sent immediately gracePeriod: 5, + // [Optional] disable notification for monitors with specified ids + skipNotificationIds: ['foo_monitor', 'bar_monitor'], }, callbacks: { onStatusChange: async ( diff --git a/worker/src/index.ts b/worker/src/index.ts index 0f30aad..76ff581 100644 --- a/worker/src/index.ts +++ b/worker/src/index.ts @@ -1,6 +1,6 @@ import { workerConfig } from '../../uptime.config' import { formatStatusChangeNotification, getWorkerLocation, notifyWithApprise } from './util' -import { MonitorState } from '../../uptime.types' +import { MonitorState, MonitorTarget } from '../../uptime.types' import { getStatus } from './monitor' export interface Env { @@ -44,12 +44,20 @@ export default { // Auxiliary function to format notification and send it via apprise let formatAndNotify = async ( - monitor: any, + monitor: MonitorTarget, isUp: boolean, timeIncidentStart: number, timeNow: number, reason: string ) => { + // Skip notification if monitor is in the skip list + // @ts-ignore + const skipList: string[] = workerConfig.notification?.skipNotificationIds + if (skipList && skipList.includes(monitor.id)) { + console.log(`Skipping notification for ${monitor.name} (${monitor.id} in skipNotificationIds)`) + return + } + if (workerConfig.notification?.appriseApiServer && workerConfig.notification?.recipientUrl) { const notification = formatStatusChangeNotification( monitor,