uptime-kuma/server/notification-providers/pushbullet.js
Frank Elsinga 0f61d7ee1b
chore: enable formatting over the entire codebase in CI (#6655)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-01-09 02:10:36 +01:00

60 lines
2.1 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) {
const okMsg = "Sent Successfully.";
const url = "https://api.pushbullet.com/v2/pushes";
try {
let config = {
headers: {
"Access-Token": notification.pushbulletAccessToken,
"Content-Type": "application/json",
},
};
config = this.getAxiosConfigWithProxy(config);
if (heartbeatJSON == null) {
let data = {
type: "note",
title: "Uptime Kuma Alert",
body: msg,
};
await axios.post(url, 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(url, 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(url, upData, config);
}
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = Pushbullet;