Fix resolved priority and add priority label switch

This commit is contained in:
Matěj Divecký 2023-11-18 11:36:42 +01:00
parent a8de2b624b
commit dd34fbe61a

View file

@ -4,7 +4,7 @@ import { Priority } from '../enum/priority';
export class GrafanaService { export class GrafanaService {
public async postAlert(req: Request): Promise<void> { public async postAlert(req: Request): Promise<void> {
const messagePriotity = getPriority(req.body.status); const messagePriotity = getPriority(req.body.status, req.body.commonLabels.priority);
const messageTitle = req.body.commonLabels.alertname; const messageTitle = req.body.commonLabels.alertname;
const messageDescription = req.body.commonAnnotations.summary; const messageDescription = req.body.commonAnnotations.summary;
const messageTags = getTags(req.body.commonLabels, req.body.status); const messageTags = getTags(req.body.commonLabels, req.body.status);
@ -20,15 +20,23 @@ export class GrafanaService {
} }
} }
function getPriority(status: string): Priority { function getPriority(status: string, priority: string): Priority {
switch (status) { if (status == 'resolved') {
case 'firing': return Priority.MIN;
return Priority.URGENT; }
case 'firing':
return Priority.MIN; switch (priority) {
default: case 'low':
return Priority.DEFAULT; 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 { function getTags(commonLabels: string, status: string): string {