-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (33 loc) · 1.06 KB
/
index.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
const express = require('express');
const axios = require('axios');
const app = express();
app.use(express.json({ limit: '70mb' }));
app.use(express.urlencoded({ limit: '70mb', extended: true}));
app.use(async (req, res) => {
for (const alertId in req.body.alerts) {
const alert = req.body.alerts[alertId];
if (alert.status !== "firing")
continue;
const annotations = Object.assign({}, req.body.commonAnnotations, alert.annotations);
const body = {
title: annotations.title,
message: annotations.description,
priority: parseInt(annotations.priority || process.env.GOTIFY_DEFAULT_PRIORITY)
};
try {
await axios.post(process.env.GOTIFY_URL, body, {
headers: {
"Content-Type": "application/json",
"X-Gotify-Key": process.env.GOTIFY_TOKEN
}
});
} catch (error) {
console.error("Error dispatching message:", error);
}
}
res.end("SUCCESS\n");
});
const port = process.env.PORT | 8435;
app.listen(port, () => {
console.log(`Server Listen On http://localhost:${port}`);
});