mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-24 23:34:03 +00:00
8a92054c2b
* 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>
57 lines
2 KiB
JavaScript
57 lines
2 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
|
|
const { DOWN, UP } = require("../../src/util");
|
|
|
|
class Pushbullet extends NotificationProvider {
|
|
|
|
name = "pushbullet";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
let okMsg = "Sent Successfully.";
|
|
|
|
try {
|
|
let pushbulletUrl = "https://api.pushbullet.com/v2/pushes";
|
|
let config = {
|
|
headers: {
|
|
"Access-Token": notification.pushbulletAccessToken,
|
|
"Content-Type": "application/json"
|
|
}
|
|
};
|
|
if (heartbeatJSON == null) {
|
|
let data = {
|
|
"type": "note",
|
|
"title": "Uptime Kuma Alert",
|
|
"body": msg,
|
|
};
|
|
await axios.post(pushbulletUrl, data, config);
|
|
} else if (heartbeatJSON["status"] === DOWN) {
|
|
let downData = {
|
|
"type": "note",
|
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
|
"body": "[🔴 Down] " +
|
|
heartbeatJSON["msg"] +
|
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
|
};
|
|
await axios.post(pushbulletUrl, downData, config);
|
|
} else if (heartbeatJSON["status"] === UP) {
|
|
let upData = {
|
|
"type": "note",
|
|
"title": "UptimeKuma Alert: " + monitorJSON["name"],
|
|
"body": "[✅ Up] " +
|
|
heartbeatJSON["msg"] +
|
|
`\nTime (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
|
};
|
|
await axios.post(pushbulletUrl, upData, config);
|
|
}
|
|
return okMsg;
|
|
} catch (error) {
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = Pushbullet;
|