mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-03-15 13:54:45 +00:00
Some checks are pending
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
Auto Test / auto-test (18, macos-latest) (push) Blocked by required conditions
Auto Test / auto-test (18, ARM64) (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
CodeQL / Analyze (push) Waiting to run
Merge Conflict Labeler / Labeling (push) Waiting to run
validate / json-yaml-validate (push) Waiting to run
validate / validate (push) Waiting to run
Co-authored-by: Frank Elsinga <frank@elsinga.de>
57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const { DOWN, UP } = require("../../src/util");
|
|
const { default: axios } = require("axios");
|
|
|
|
class YZJ extends NotificationProvider {
|
|
name = "YZJ";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
let okMsg = "Sent Successfully.";
|
|
|
|
try {
|
|
if (heartbeatJSON !== null) {
|
|
msg = `${this.statusToString(heartbeatJSON["status"])} ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`;
|
|
}
|
|
|
|
const config = {
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
};
|
|
const params = {
|
|
content: msg
|
|
};
|
|
// yzjtype=0 => general robot
|
|
const url = `${notification.yzjWebHookUrl}?yzjtype=0&yzjtoken=${notification.yzjToken}`;
|
|
|
|
const result = await axios.post(url, params, config);
|
|
if (!result.data?.success) {
|
|
throw new Error(result.data?.errmsg ?? "yzj's server did not respond with the expected result");
|
|
}
|
|
return okMsg;
|
|
} catch (error) {
|
|
this.throwGeneralAxiosError(error);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Convert status constant to string
|
|
* @param {string} status The status constant
|
|
* @returns {string} status
|
|
*/
|
|
statusToString(status) {
|
|
switch (status) {
|
|
case DOWN:
|
|
return "❌";
|
|
case UP:
|
|
return "✅";
|
|
default:
|
|
return status;
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = YZJ;
|