summaryrefslogtreecommitdiffstats
path: root/server/notification-providers/goalert.js
blob: 847c6a003f89d8293867e196da51860d6fc85466 (plain)
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
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { UP } = require("../../src/util");

class GoAlert extends NotificationProvider {
    name = "GoAlert";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        try {
            let data = {
                summary: msg,
            };
            if (heartbeatJSON != null && heartbeatJSON["status"] === UP) {
                data["action"] = "close";
            }
            let headers = {
                "Content-Type": "multipart/form-data",
            };
            let config = {
                headers: headers
            };
            await axios.post(`${notification.goAlertBaseURL}/api/v2/generic/incoming?token=${notification.goAlertToken}`, data, config);
            return okMsg;
        } catch (error) {
            let msg = (error.response.data) ? error.response.data : "Error without response";
            throw new Error(msg);
        }
    }
}

module.exports = GoAlert;