mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-01 19:32:34 +02:00
Update server/notification-providers/yzj.js
Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
parent
bd70abce6e
commit
d6c7d8a4f5
1 changed files with 12 additions and 28 deletions
|
@ -12,46 +12,30 @@ class YZJ extends NotificationProvider {
|
||||||
let okMsg = "Sent Successfully.";
|
let okMsg = "Sent Successfully.";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (heartbeatJSON !== null) {
|
||||||
if (heartbeatJSON != null) {
|
|
||||||
msg = `${this.statusToString(heartbeatJSON["status"])} ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`;
|
msg = `${this.statusToString(heartbeatJSON["status"])} ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let params = {
|
const config = {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const params = {
|
||||||
content: msg
|
content: msg
|
||||||
};
|
};
|
||||||
|
const url = `${notification.yzjWebHookUrl}?yzjtype=${notification.yzjType}&yzjtoken=${notification.yzjToken}`;
|
||||||
|
|
||||||
if (await this.sendToYZJ(notification, params)) {
|
const result = await axios.post(url, params, config);
|
||||||
return okMsg;
|
if (!result.data?.success) {
|
||||||
|
throw new Error(result.data?.errmsg ?? "yzj's server did not respond with the expected result");
|
||||||
}
|
}
|
||||||
|
return okMsg;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error);
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Send message to YZJ
|
|
||||||
* @param {object} notification Notification
|
|
||||||
* @param {object} params Parameters of message
|
|
||||||
* @returns {boolean} True if successful else false
|
|
||||||
*/
|
|
||||||
async sendToYZJ(notification, params) {
|
|
||||||
|
|
||||||
let config = {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
url: `${notification.yzjWebHookUrl}?yzjtype=${notification.yzjType}&yzjtoken=${notification.yzjToken}`,
|
|
||||||
data: JSON.stringify(params),
|
|
||||||
};
|
|
||||||
|
|
||||||
let result = await axios(config);
|
|
||||||
if (!result.data?.success) {
|
|
||||||
throw new Error(result.data?.errmsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert status constant to string
|
* Convert status constant to string
|
||||||
* @param {string} status The status constant
|
* @param {string} status The status constant
|
||||||
|
|
Loading…
Add table
Reference in a new issue