Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 66 additions & 49 deletions server/notification-providers/discord.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Discord extends NotificationProvider {

try {
const discordDisplayName = notification.discordUsername || "Uptime Kuma";
const discordMinimalistNotification = notification.discordMinimalistNotification || false;

// If heartbeatJSON is null, assume we're testing.
if (heartbeatJSON == null) {
Expand Down Expand Up @@ -42,71 +43,87 @@ class Discord extends NotificationProvider {
break;
}

// If heartbeatJSON is not null, we go into the normal alerting loop.
if (heartbeatJSON["status"] === DOWN) {
// Build embed dynamically based on minimalist setting
let embed = {
color: 16711680,
};

if (discordMinimalistNotification) {
embed.title = `❌ ${monitorJSON["name"]}`;
} else {
embed.title = `❌ Your service ${monitorJSON["name"]} went down. ❌`;
embed.timestamp = heartbeatJSON["time"];
embed.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: "Error",
value: heartbeatJSON["msg"] == null ? "N/A" : heartbeatJSON["msg"],
},
];
}

let discorddowndata = {
username: discordDisplayName,
embeds: [{
title: "❌ Your service " + monitorJSON["name"] + " went down. ❌",
color: 16711680,
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: "Error",
value: heartbeatJSON["msg"] == null ? "N/A" : heartbeatJSON["msg"],
},
],
}],
embeds: [ embed ],
};

if (notification.discordPrefixMessage) {
// Only add prefix message if NOT minimalist
if (!discordMinimalistNotification && notification.discordPrefixMessage) {
discorddowndata.content = notification.discordPrefixMessage;
}

await axios.post(notification.discordWebhookUrl, discorddowndata);
return okMsg;

} else if (heartbeatJSON["status"] === UP) {
let embed = {
color: 65280,
};

if (discordMinimalistNotification) {
embed.title = `βœ… ${monitorJSON["name"]}`;
} else {
embed.title = `βœ… Your service ${monitorJSON["name"]} is up! βœ…`;
embed.timestamp = heartbeatJSON["time"];
embed.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["ping"] == null ? "N/A" : heartbeatJSON["ping"] + " ms",
},
];
}

let discordupdata = {
username: discordDisplayName,
embeds: [{
title: "βœ… Your service " + monitorJSON["name"] + " is up! βœ…",
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["ping"] == null ? "N/A" : heartbeatJSON["ping"] + " ms",
},
],
}],
embeds: [ embed ],
};

if (notification.discordPrefixMessage) {
// Only add prefix message if NOT minimalist
if (!discordMinimalistNotification && notification.discordPrefixMessage) {
discordupdata.content = notification.discordPrefixMessage;
}

Expand Down
13 changes: 13 additions & 0 deletions src/components/notifications/Discord.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
</div>

<div class="mb-3">
<div class="form-check form-switch">
<input v-model="$parent.notification.discordMinimalistNotification" class="form-check-input" type="checkbox">
<label class="form-check-label">{{ $t("discordMinimalistNotification") }}</label>
</div>
<div class="form-text">
{{ $t("discordMinimalistNotificationDescription") }}
</div>
</div>

<div
v-if="!$parent.notification.discordMinimalistNotification"
class="mb-3"
>
<label for="discord-prefix-message" class="form-label">{{ $t("Prefix Custom Message") }}</label>
<input id="discord-prefix-message" v-model="$parent.notification.discordPrefixMessage" type="text" class="form-control" autocomplete="false" :placeholder="$t('Hello @everyone is...')">
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -821,5 +821,7 @@
"noOrBadCertificate": "No/Bad Certificate",
"gamedigGuessPort": "Gamedig: Guess Port",
"gamedigGuessPortDescription": "The port used by Valve Server Query Protocol may be different from the client port. Try this if the monitor cannot connect to your server.",
"apiKeysDisabledMsg": "API keys are disabled because authentication is disabled."
"apiKeysDisabledMsg": "API keys are disabled because authentication is disabled.",
"discordMinimalistNotification": "Minimalist Notification",
"discordMinimalistNotificationDescription": "Send only name of service and up/down icon"
}