From dd34fbe61aabca325afddc346e0f7eaa6681520e Mon Sep 17 00:00:00 2001 From: mdivecky Date: Sat, 18 Nov 2023 11:36:42 +0100 Subject: [PATCH] Fix resolved priority and add priority label switch --- src/services/GrafanaService.ts | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/services/GrafanaService.ts b/src/services/GrafanaService.ts index de671d3..2efb41f 100644 --- a/src/services/GrafanaService.ts +++ b/src/services/GrafanaService.ts @@ -4,7 +4,7 @@ import { Priority } from '../enum/priority'; export class GrafanaService { public async postAlert(req: Request): Promise { - const messagePriotity = getPriority(req.body.status); + const messagePriotity = getPriority(req.body.status, req.body.commonLabels.priority); const messageTitle = req.body.commonLabels.alertname; const messageDescription = req.body.commonAnnotations.summary; const messageTags = getTags(req.body.commonLabels, req.body.status); @@ -20,15 +20,23 @@ export class GrafanaService { } } -function getPriority(status: string): Priority { - switch (status) { - case 'firing': - return Priority.URGENT; - case 'firing': - return Priority.MIN; - default: - return Priority.DEFAULT; - } +function getPriority(status: string, priority: string): Priority { + if (status == 'resolved') { + return Priority.MIN; + } + + switch (priority) { + case 'low': + return Priority.MIN; + case 'normal': + return Priority.DEFAULT; + case 'high': + return Priority.HIGH; + case 'critical': + return Priority.URGENT; + default: + return Priority.DEFAULT; + } } function getTags(commonLabels: string, status: string): string {