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