Skip to content

Commit 4549df7

Browse files
committed
add severity, topic, and ruleId to notification log table
1 parent 351067c commit 4549df7

7 files changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module.exports = class AddNotificationSeverity1773090000000 {
2+
name = 'AddNotificationSeverity1773090000000'
3+
4+
async up(db) {
5+
await db.query(`ALTER TABLE "notification_log" ADD "severity" text`)
6+
await db.query(`ALTER TABLE "notification_log" ADD "topic" text`)
7+
await db.query(`ALTER TABLE "notification_log" ADD "rule_id" text`)
8+
await db.query(`CREATE INDEX "IDX_notification_log_severity" ON "notification_log" ("severity") `)
9+
await db.query(`CREATE INDEX "IDX_notification_log_topic" ON "notification_log" ("topic") `)
10+
await db.query(`CREATE INDEX "IDX_notification_log_rule_id" ON "notification_log" ("rule_id") `)
11+
}
12+
13+
async down(db) {
14+
await db.query(`DROP INDEX "public"."IDX_notification_log_rule_id"`)
15+
await db.query(`DROP INDEX "public"."IDX_notification_log_topic"`)
16+
await db.query(`DROP INDEX "public"."IDX_notification_log_severity"`)
17+
await db.query(`ALTER TABLE "notification_log" DROP COLUMN "rule_id"`)
18+
await db.query(`ALTER TABLE "notification_log" DROP COLUMN "topic"`)
19+
await db.query(`ALTER TABLE "notification_log" DROP COLUMN "severity"`)
20+
}
21+
}

schema.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ type NotificationLog @entity {
3030
recordId: String! @index # EventRecord.id or TraceRecord.id
3131
recordType: String! @index # "event" | "trace"
3232
processor: String @index # Processor name that triggered it
33+
severity: String @index # rule severity at notify time: low|medium|high|critical|broken|highlight
34+
topic: String @index # notification topic/product (OETH, ARM, Governance, …)
35+
ruleId: String @index # alert_rule.id that fired (null for code-driven processors)
3336
notifiedAt: DateTime! @index
3437
chainId: Int! @index
3538
blockNumber: Int! @index

src/model/generated/notificationLog.model.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ export class NotificationLog {
2121
@StringColumn_({nullable: true})
2222
processor!: string | undefined | null
2323

24+
@Index_()
25+
@StringColumn_({nullable: true})
26+
severity!: string | undefined | null
27+
28+
@Index_()
29+
@StringColumn_({nullable: true})
30+
topic!: string | undefined | null
31+
32+
@Index_()
33+
@StringColumn_({nullable: true})
34+
ruleId!: string | undefined | null
35+
2436
@Index_()
2537
@DateTimeColumn_({nullable: false})
2638
notifiedAt!: Date

src/notify/event/event.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const notifyForEvent = async (params: {
7878
ctx: Context
7979
topic: Topic
8080
severity?: Severity
81+
ruleId?: string
8182
name?: string
8283
eventName: string
8384
event: EventDecoder
@@ -94,6 +95,9 @@ export const notifyForEvent = async (params: {
9495
recordId,
9596
recordType: 'event',
9697
processor: params.name,
98+
severity: params.severity,
99+
topic: params.topic,
100+
ruleId: params.ruleId,
97101
chainId: params.ctx.chain.id,
98102
blockNumber: params.log.block.height,
99103
})

src/notify/notification-log.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ export const checkAndLogNotification = async (params: {
1212
recordId: string
1313
recordType: 'event' | 'trace'
1414
processor?: string
15+
severity?: string
16+
topic?: string
17+
ruleId?: string
1518
chainId: number
1619
blockNumber: number
1720
}): Promise<boolean> => {
@@ -29,6 +32,9 @@ export const checkAndLogNotification = async (params: {
2932
recordId: params.recordId,
3033
recordType: params.recordType,
3134
processor: params.processor ?? null,
35+
severity: params.severity ?? null,
36+
topic: params.topic ?? null,
37+
ruleId: params.ruleId ?? null,
3238
notifiedAt: new Date(),
3339
chainId: params.chainId,
3440
blockNumber: params.blockNumber,

src/notify/trace.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface NotifyForTraceInput {
1414
ctx: Context
1515
topic: Topic
1616
severity?: Severity
17+
ruleId?: string
1718
name?: string
1819
functionName?: string
1920
functionData?: unknown
@@ -48,6 +49,9 @@ export const notifyForTrace = async (input: NotifyForTraceInput) => {
4849
recordId,
4950
recordType: 'trace',
5051
processor: name,
52+
severity,
53+
topic,
54+
ruleId: input.ruleId,
5155
chainId: ctx.chain.id,
5256
blockNumber: trace.block.height,
5357
})

src/processors/config-alert.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export const createConfigAlertProcessor = async (chainId: number) => {
120120
block,
121121
log,
122122
event: abiEvent ?? { topic: topic0, decode: () => undefined },
123+
ruleId: rule.id,
123124
topic: rule.topic,
124125
severity: rule.severity === 'low' ? undefined : rule.severity,
125126
notifyTarget: rule.notifyTargets ?? undefined,
@@ -174,6 +175,7 @@ export const createConfigAlertProcessor = async (chainId: number) => {
174175
ctx,
175176
name: rule.displayName ?? rule.topic,
176177
trace,
178+
ruleId: rule.id,
177179
topic: rule.topic,
178180
severity,
179181
notifyTarget: rule.notifyTargets ?? undefined,

0 commit comments

Comments
 (0)