uptime-kuma/server/notification-providers/sevenio.js
Dj Isaac 019702f8e5
Some checks are pending
Auto Test / auto-test (18, ARM64) (push) Blocked by required conditions
Auto Test / auto-test (18, macos-latest) (push) Blocked by required conditions
Auto Test / auto-test (18, ubuntu-latest) (push) Blocked by required conditions
Auto Test / auto-test (18, windows-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, ARM64) (push) Blocked by required conditions
Auto Test / auto-test (20, macos-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, ubuntu-latest) (push) Blocked by required conditions
Auto Test / auto-test (20, windows-latest) (push) Blocked by required conditions
Auto Test / armv7-simple-test (18, ARMv7) (push) Waiting to run
Auto Test / armv7-simple-test (20, ARMv7) (push) Waiting to run
Auto Test / check-linters (push) Waiting to run
Auto Test / e2e-test (push) Waiting to run
CodeQL / Analyze (go) (push) Waiting to run
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
json-yaml-validate / json-yaml-validate (push) Waiting to run
fix: misspelling of 'address' (#5180)
2024-10-10 01:24:32 +02:00

58 lines
1.9 KiB
JavaScript

const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { DOWN, UP } = require("../../src/util");
class SevenIO extends NotificationProvider {
name = "SevenIO";
/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";
const data = {
to: notification.sevenioTo,
from: notification.sevenioSender || "Uptime Kuma",
text: msg,
};
const config = {
baseURL: "https://gateway.seven.io/api/",
headers: {
"Content-Type": "application/json",
"X-API-Key": notification.sevenioApiKey,
},
};
try {
// testing or certificate expiry notification
if (heartbeatJSON == null) {
await axios.post("sms", data, config);
return okMsg;
}
let address = this.extractAddress(monitorJSON);
if (address !== "") {
address = `(${address}) `;
}
// If heartbeatJSON is not null, we go into the normal alerting loop.
if (heartbeatJSON["status"] === DOWN) {
data.text = `Your service ${monitorJSON["name"]} ${address}went down at ${heartbeatJSON["localDateTime"]} ` +
`(${heartbeatJSON["timezone"]}). Error: ${heartbeatJSON["msg"]}`;
} else if (heartbeatJSON["status"] === UP) {
data.text = `Your service ${monitorJSON["name"]} ${address}went back up at ${heartbeatJSON["localDateTime"]} ` +
`(${heartbeatJSON["timezone"]}).`;
}
await axios.post("sms", data, config);
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = SevenIO;