mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-09-08 02:12:10 +00:00
![Matthew Nickson](/assets/img/avatar_default.png)
* Added JSDoc to eslint rules Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> * Fixed JSDoc eslint errors Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> * Update the check-linters workflow to Node.js 20 --------- Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com> Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
const { DOWN, UP } = require("../../src/util");
|
|
|
|
class LunaSea extends NotificationProvider {
|
|
|
|
name = "lunasea";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
let okMsg = "Sent Successfully.";
|
|
let lunaseaurl = "";
|
|
if (notification.lunaseaTarget === "user") {
|
|
lunaseaurl = "https://notify.lunasea.app/v1/custom/user/" + notification.lunaseaUserID;
|
|
} else {
|
|
lunaseaurl = "https://notify.lunasea.app/v1/custom/device/" + notification.lunaseaDevice;
|
|
}
|
|
|
|
try {
|
|
if (heartbeatJSON == null) {
|
|
let testdata = {
|
|
"title": "Uptime Kuma Alert",
|
|
"body": msg,
|
|
};
|
|
await axios.post(lunaseaurl, testdata);
|
|
return okMsg;
|
|
}
|
|
|
|
if (heartbeatJSON["status"] === DOWN) {
|
|
let downdata = {
|
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
|
"body": "[🔴 Down] " +
|
|
heartbeatJSON["msg"] +
|
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
|
};
|
|
await axios.post(lunaseaurl, downdata);
|
|
return okMsg;
|
|
}
|
|
|
|
if (heartbeatJSON["status"] === UP) {
|
|
let updata = {
|
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
|
"body": "[✅ Up] " +
|
|
heartbeatJSON["msg"] +
|
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
|
};
|
|
await axios.post(lunaseaurl, updata);
|
|
return okMsg;
|
|
}
|
|
|
|
} catch (error) {
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
module.exports = LunaSea;
|