mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-03-05 00:44:46 +00:00
Add discord support for SLOW/NOMINAL notification cards
This commit is contained in:
parent
bdfe95a0f1
commit
7d5297df9d
1 changed files with 84 additions and 2 deletions
|
@ -1,10 +1,11 @@
|
||||||
const NotificationProvider = require("./notification-provider");
|
const NotificationProvider = require("./notification-provider");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const { DOWN, UP } = require("../../src/util");
|
const { DOWN, UP, SLOW, NOMINAL } = require("../../src/util");
|
||||||
|
|
||||||
class Discord extends NotificationProvider {
|
class Discord extends NotificationProvider {
|
||||||
|
|
||||||
name = "discord";
|
name = "discord";
|
||||||
|
supportSlowNotifications = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
|
@ -115,12 +116,93 @@ class Discord extends NotificationProvider {
|
||||||
|
|
||||||
await axios.post(notification.discordWebhookUrl, discordupdata);
|
await axios.post(notification.discordWebhookUrl, discordupdata);
|
||||||
return okMsg;
|
return okMsg;
|
||||||
|
} else if (heartbeatJSON["status"] === SLOW) {
|
||||||
|
let discordslowdata = {
|
||||||
|
username: discordDisplayName,
|
||||||
|
embeds: [{
|
||||||
|
title: "🐌 Your service " + monitorJSON["name"] + " responded slow. 🐌",
|
||||||
|
color: 16761095,
|
||||||
|
timestamp: heartbeatJSON["time"],
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "Service Name",
|
||||||
|
value: monitorJSON["name"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL",
|
||||||
|
value: monitorJSON["type"] === "push" ? "Heartbeat" : address,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `Time (${heartbeatJSON["timezone"]})`,
|
||||||
|
value: heartbeatJSON["localDateTime"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Ping",
|
||||||
|
value: heartbeatJSON["calculatedResponse"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Threshold",
|
||||||
|
value: heartbeatJSON["calculatedThreshold"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (notification.discordPrefixMessage) {
|
||||||
|
discordslowdata.content = notification.discordPrefixMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
await axios.post(notification.discordWebhookUrl, discordslowdata);
|
||||||
|
return okMsg;
|
||||||
|
} else if (heartbeatJSON["status"] === NOMINAL) {
|
||||||
|
let discordnominaldata = {
|
||||||
|
username: discordDisplayName,
|
||||||
|
embeds: [{
|
||||||
|
title: "🚀 Your service " + monitorJSON["name"] + " is responding normally! 🚀",
|
||||||
|
color: 65280,
|
||||||
|
timestamp: heartbeatJSON["time"],
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "Service Name",
|
||||||
|
value: monitorJSON["name"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: monitorJSON["type"] === "push" ? "Service Type" : "Service URL",
|
||||||
|
value: monitorJSON["type"] === "push" ? "Heartbeat" : address,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: `Time (${heartbeatJSON["timezone"]})`,
|
||||||
|
value: heartbeatJSON["localDateTime"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Ping",
|
||||||
|
value: heartbeatJSON["calculatedResponse"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Threshold",
|
||||||
|
value: heartbeatJSON["calculatedThreshold"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Slow For",
|
||||||
|
value: heartbeatJSON["slowFor"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (notification.discordPrefixMessage) {
|
||||||
|
discordnominaldata.content = notification.discordPrefixMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
await axios.post(notification.discordWebhookUrl, discordnominaldata);
|
||||||
|
return okMsg;
|
||||||
|
} else {
|
||||||
|
this.throwGeneralAxiosError("Not sure why we're here");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.throwGeneralAxiosError(error);
|
this.throwGeneralAxiosError(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Discord;
|
module.exports = Discord;
|
||||||
|
|
Loading…
Add table
Reference in a new issue