Discord enhancements

pull/175/head
Niyas 3 years ago committed by GitHub
parent 8350bff629
commit 9ade9af1e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -83,41 +83,91 @@ class Notification {
return await Notification.smtp(notification, msg) return await Notification.smtp(notification, msg)
} else if (notification.type === "discord") { } else if (notification.type === "discord") {
let kumaURL = notification.discorduptimekumaUrl || "https://github.com/louislam/uptime-kuma";
let dashboardURL = notification.discorduptimekumaUrl + '/dashboard/' + monitorJSON["id"];
try { try {
// If heartbeatJSON is null, assume we're testing. // If heartbeatJSON is null, assume we're testing.
if (heartbeatJSON == null) { if (heartbeatJSON == null) {
let data = { let discordtestdata = {
username: "Uptime-Kuma", username: "Uptime Kuma",
content: msg, content: msg,
} }
await axios.post(notification.discordWebhookUrl, data) await axios.post(notification.discordWebhookUrl, discordtestdata)
return okMsg; return okMsg;
} }
// If heartbeatJSON is not null, we go into the normal alerting loop. // If heartbeatJSON is not null, we go into the normal alerting loop.
if (heartbeatJSON["status"] == 0) { if (heartbeatJSON["status"] == 0) {
var alertColor = "16711680"; let discorddowndata = {
} else if (heartbeatJSON["status"] == 1) { username: "Uptime Kuma",
var alertColor = "65280"; embeds: [{
title: "❌ One of your services went down. ❌",
color: 16711680,
timestamp: heartbeatJSON["time"],
fields: [
{
name: "Service Name",
value: monitorJSON["name"],
},
{
name: "Service URL",
value: monitorJSON["url"],
},
{
name: "Time (UTC)",
value: heartbeatJSON["time"],
},
{
name: "Error",
value: heartbeatJSON["msg"],
},
{
name: "Visit Service Dashboard",
value: "[Visit Dashboard]("+ dashboardURL + ")",
},
{
name: "Visit Uptime Kuma",
value: "[Visit]("+ kumaURL +")",
},
],
}],
} }
let data = { await axios.post(notification.discordWebhookUrl, discorddowndata)
username: "Uptime-Kuma", return okMsg;
} else if (heartbeatJSON["status"] == 1) {
let discordupdata = {
username: "Uptime Kuma",
embeds: [{ embeds: [{
title: "Uptime-Kuma Alert", title: "✅ Your service " + monitorJSON["name"] + " is up! ✅",
color: alertColor, color: 65280,
timestamp: heartbeatJSON["time"],
fields: [ fields: [
{
name: "Service Name",
value: monitorJSON["name"],
},
{
name: "Service URL",
value: "[Visit Service]("+ monitorJSON["url"] +")",
},
{ {
name: "Time (UTC)", name: "Time (UTC)",
value: heartbeatJSON["time"], value: heartbeatJSON["time"],
}, },
{ {
name: "Message", name: "Ping",
value: msg, value: heartbeatJSON["ping"] + "ms",
},
{
name: "Visit Uptime Kuma",
value: "[Visit]("+ kumaURL +")",
}, },
], ],
}], }],
} }
await axios.post(notification.discordWebhookUrl, data) await axios.post(notification.discordWebhookUrl, discordupdata)
return okMsg; return okMsg;
}
} catch (error) { } catch (error) {
throwGeneralAxiosError(error) throwGeneralAxiosError(error)
} }

Loading…
Cancel
Save