feat: skip error change notification option

pull/161/head
lyc8503 2025-11-05 01:06:21 +08:00
parent a1fa753450
commit e87e350d6d
3 changed files with 15 additions and 8 deletions

View File

@ -58,6 +58,7 @@ export type Notification = {
timeZone?: string
gracePeriod?: number
skipNotificationIds?: string[]
skipErrorChangeNotification?: boolean
}
type SingleWebhook = {

View File

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

View File

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