-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathalertManager.ts
More file actions
52 lines (50 loc) · 1.3 KB
/
alertManager.ts
File metadata and controls
52 lines (50 loc) · 1.3 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
40
41
42
43
44
45
46
47
48
49
50
51
52
import {
removeWarningAlerts,
formatActiveAlerts,
sortAlerts,
} from './alertUtils';
export type PrometheusAlert = {
annotations: Record<string, string>;
receivers: {
name: string;
}[];
fingerprint: string;
startsAt: string;
updatedAt: string;
endsAt: string;
status: {
state: 'unprocessed' | 'active' | 'suppressed';
silencedBy: string[];
inhibitedBy: string[];
};
labels: Record<string, string>;
generatorURL: string;
};
export type AlertLabels = {
// @ts-expect-error - FIXME when you are working on it
parents?: string[];
// @ts-expect-error - FIXME when you are working on it
selectors?: string[];
[labelName: string]: string;
};
export function getAlerts(alertManagerUrl: string, token?: string) {
return fetch(alertManagerUrl + '/api/v2/alerts', {
headers: token ? { Authorization: `Bearer ${token}` } : {},
})
.then((r) => {
if (r.ok) {
return r.json();
}
throw new Error(`Alert manager responded with ${r.status}`);
})
.then((resolve) => {
if (resolve.error) {
throw resolve.error;
}
return resolve;
})
.then((result) => {
// format the alerts then remove the warning and finally sort the alerts.
return sortAlerts(removeWarningAlerts(formatActiveAlerts(result)));
});
}