-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.notifier.ts
More file actions
39 lines (34 loc) · 1.74 KB
/
console.notifier.ts
File metadata and controls
39 lines (34 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) 2026 Azimutt, Inc.
// Licensed under the MIT License. See LICENSES/MIT.txt in the repository root.
import * as z from 'zod'
import {
AlertResolved,
AlertStarted,
durationToMillis,
NotifierCtx,
NotifierPlugin,
NotifierPluginId,
NotifierResult,
router,
Router,
} from '@azimutt/inspector-core'
const ConsoleNotifierConfig = z.strictObject({}).meta({ id: 'ConsoleNotifierConfig' })
type ConsoleNotifierConfig = z.infer<typeof ConsoleNotifierConfig>
const ConsoleNotifier: NotifierPlugin<ConsoleNotifierConfig> = {
module: NotifierPluginId.parse('ext.console'),
description: 'Log alerts and suggestions to the backend console.',
doc: `Fetch created and closed alerts since the last execution (or the configured delay if first execution) and log them to the console.
This notifier has no specific configuration.`,
config: ConsoleNotifierConfig,
notify: async (ctx: NotifierCtx<ConsoleNotifierConfig>): Promise<NotifierResult> => {
const prev = await ctx.getPreviousResult()
const since = prev ? prev.startedAt || prev.finishedAt : new Date(ctx.execution.startedAt.getTime() - durationToMillis(ctx.notifier.delay))
const newAlerts: AlertStarted[] = await ctx.getAlertsStartedAfter(since)
const resolvedAlerts: AlertResolved[] = prev ? await ctx.getAlertsResolvedAfter(since) : []
const routerAbs: Router = router.setBase(await ctx.getServerUrl())
newAlerts.slice(0, 20).forEach(a => console.log(`New alert: ${a.title} [details](${routerAbs.alert(a.id)})`))
resolvedAlerts.slice(0, 10).forEach(a => console.log(`Closed alert: ${a.title} [details](${routerAbs.alert(a.id)})`))
return { newAlerts: newAlerts.map(a => a.id), resolvedAlerts: resolvedAlerts.map(a => a.id) }
},
}
export default ConsoleNotifier