mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-01 11:22:34 +02:00
48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
|
|
class SpugPush extends NotificationProvider {
|
|
|
|
name = "SpugPush";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
let okMsg = "Sent Successfully.";
|
|
try {
|
|
await axios.post(`https://push.spug.cc/send/${notification.templateKey}`, {
|
|
"status": heartbeatJSON["status"],
|
|
"msg": heartbeatJSON["msg"],
|
|
"duration": heartbeatJSON["duration"],
|
|
"name": monitorJSON["name"],
|
|
"target": this.getTarget(monitorJSON),
|
|
});
|
|
|
|
return okMsg;
|
|
|
|
} catch (error) {
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the formatted target for message
|
|
* @param {object} monitorJSON Monitor details (For Up/Down only)
|
|
* @returns {string} Formatted target
|
|
*/
|
|
getTarget(monitorJSON) {
|
|
let target = "-";
|
|
if (monitorJSON["hostname"]) {
|
|
target = monitorJSON["hostname"];
|
|
if (monitorJSON["port"]) {
|
|
target += ":" + monitorJSON["port"];
|
|
}
|
|
} else if (monitorJSON["url"]) {
|
|
target = monitorJSON["url"];
|
|
}
|
|
return target;
|
|
}
|
|
}
|
|
|
|
module.exports = SpugPush;
|