forked from pavel-kazhavets/AlertmanagerRocketChat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlertmanagerIntegration.js
82 lines (72 loc) · 2.27 KB
/
AlertmanagerIntegration.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class Script {
process_incoming_request({
request
}) {
console.log(request.content);
var alertColor = "warning";
if (request.content.status == "resolved") {
alertColor = "green";
} else if (request.content.status == "firing") {
alertColor = "danger";
}
let finFields = [];
for (i = 0; i < request.content.alerts.length; i++) {
var endVal = request.content.alerts[i];
var elem = {
title: "Alertname",
value: endVal.labels.alertname,
short: false
};
finFields.push(elem);
if (!!endVal.annotations.summary) {
finFields.push({
title: "Summary",
value: endVal.annotations.summary
});
}
if (!!endVal.labels.severity) {
finFields.push({
title: "Severity",
value: endVal.labels.severity
});
}
if (!!endVal.annotations.description) {
finFields.push({
title: "Description",
value: endVal.annotations.description
});
}
if (!!endVal.annotations.message) {
finFields.push({
title: "Message",
value: endVal.annotations.message
});
}
finFields.push({
title: "Labels",
value: this.getLabelsField(endVal.labels)
});
}
return {
content: {
username: "Prometheus Alert",
attachments: [{
color: alertColor,
title_link: request.content.externalURL,
title: "Prometheus notification",
fields: finFields
}]
}
};
}
getLabelsField(labelsObj) {
let labelsArr = [];
for (const key of Object.keys(labelsObj)) {
if (key == "alertname" || key == "severity") {
continue;
}
labelsArr.push(key+"="+labelsObj[key]);
}
return labelsArr.join(", ");
}
}