feat #88 notification blacklist

pull/97/head
lyc8503 2025-04-07 00:50:16 +08:00
parent 8c818017c1
commit 9bc5deb99d
2 changed files with 12 additions and 2 deletions

View File

@ -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 (

View File

@ -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,