mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-06 13:12:33 +02:00
Merge remote-tracking branch 'jacr13/dev'
# Conflicts: # server/notification.js
This commit is contained in:
commit
0e30e68548
2 changed files with 88 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const {R} = require("redbean-node");
|
const { R } = require("redbean-node");
|
||||||
const FormData = require('form-data');
|
const FormData = require('form-data');
|
||||||
const nodemailer = require("nodemailer");
|
const nodemailer = require("nodemailer");
|
||||||
|
|
||||||
|
@ -52,45 +52,61 @@ class Notification {
|
||||||
} else if (notification.type === "smtp") {
|
} else if (notification.type === "smtp") {
|
||||||
return await Notification.smtp(notification, msg)
|
return await Notification.smtp(notification, msg)
|
||||||
|
|
||||||
|
} else if (notification.type === "signal") {
|
||||||
|
try {
|
||||||
|
let data = {
|
||||||
|
"message": msg,
|
||||||
|
"number": notification.signalNumber,
|
||||||
|
"recipients": notification.signalRecipients.replace(/\s/g, '').split(",")
|
||||||
|
};
|
||||||
|
let config = {};
|
||||||
|
|
||||||
|
let res = await axios.post(notification.signalURL, data, config)
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (notification.type === "discord") {
|
} else if (notification.type === "discord") {
|
||||||
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 = {
|
||||||
|
username: 'Uptime-Kuma',
|
||||||
|
content: msg
|
||||||
|
}
|
||||||
|
let res = await axios.post(notification.discordWebhookUrl, data)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// If heartbeatJSON is not null, we go into the normal alerting loop.
|
||||||
|
if (heartbeatJSON['status'] == 0) {
|
||||||
|
var alertColor = "16711680";
|
||||||
|
} else if (heartbeatJSON['status'] == 1) {
|
||||||
|
var alertColor = "65280";
|
||||||
|
}
|
||||||
let data = {
|
let data = {
|
||||||
username: 'Uptime-Kuma',
|
username: 'Uptime-Kuma',
|
||||||
content: msg
|
embeds: [{
|
||||||
|
title: "Uptime-Kuma Alert",
|
||||||
|
color: alertColor,
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: "Time (UTC)",
|
||||||
|
value: heartbeatJSON["time"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Message",
|
||||||
|
value: msg
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
let res = await axios.post(notification.discordWebhookUrl, data)
|
let res = await axios.post(notification.discordWebhookUrl, data)
|
||||||
return true;
|
return true;
|
||||||
}
|
} catch (error) {
|
||||||
// If heartbeatJSON is not null, we go into the normal alerting loop.
|
console.log(error)
|
||||||
if(heartbeatJSON['status'] == 0) {
|
return false;
|
||||||
var alertColor = "16711680";
|
|
||||||
} else if(heartbeatJSON['status'] == 1) {
|
|
||||||
var alertColor = "65280";
|
|
||||||
}
|
|
||||||
let data = {
|
|
||||||
username: 'Uptime-Kuma',
|
|
||||||
embeds: [{
|
|
||||||
title: "Uptime-Kuma Alert",
|
|
||||||
color: alertColor,
|
|
||||||
fields: [
|
|
||||||
{
|
|
||||||
name: "Time (UTC)",
|
|
||||||
value: heartbeatJSON["time"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Message",
|
|
||||||
value: msg
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}]
|
|
||||||
}
|
|
||||||
let res = await axios.post(notification.discordWebhookUrl, data)
|
|
||||||
return true;
|
|
||||||
} catch(error) {
|
|
||||||
console.log(error)
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Notification type is not supported")
|
throw new Error("Notification type is not supported")
|
||||||
|
@ -106,7 +122,7 @@ class Notification {
|
||||||
userID,
|
userID,
|
||||||
])
|
])
|
||||||
|
|
||||||
if (! bean) {
|
if (!bean) {
|
||||||
throw new Error("notification not found")
|
throw new Error("notification not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +142,7 @@ class Notification {
|
||||||
userID,
|
userID,
|
||||||
])
|
])
|
||||||
|
|
||||||
if (! bean) {
|
if (!bean) {
|
||||||
throw new Error("notification not found")
|
throw new Error("notification not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
<option value="webhook">Webhook</option>
|
<option value="webhook">Webhook</option>
|
||||||
<option value="smtp">Email (SMTP)</option>
|
<option value="smtp">Email (SMTP)</option>
|
||||||
<option value="discord">Discord</option>
|
<option value="discord">Discord</option>
|
||||||
|
<option value="signal">Signal</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -133,6 +134,41 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template v-if="notification.type === 'signal'">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="signal-url" class="form-label">Post URL</label>
|
||||||
|
<input type="url" pattern="https?://.+" class="form-control" id="signal-url" required v-model="notification.signalURL">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="signal-number" class="form-label">Number</label>
|
||||||
|
<input type="text" class="form-control" id="signal-number" required v-model="notification.signalNumber">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="signal-recipients" class="form-label">Recipients</label>
|
||||||
|
<input type="text" class="form-control" id="signal-recipients" required v-model="notification.signalRecipients">
|
||||||
|
|
||||||
|
<div class="form-text">
|
||||||
|
You need to have a signal client with REST API.
|
||||||
|
|
||||||
|
<p style="margin-top: 8px;">
|
||||||
|
You can check this url to view how to setup one:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p style="margin-top: 8px;">
|
||||||
|
<a href="https://github.com/bbernhard/signal-cli-rest-api" target="_blank">https://github.com/bbernhard/signal-cli-rest-api</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p style="margin-top: 8px;">
|
||||||
|
IMPORTANT: You cannot mix groups and numbers in recipients!
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-danger" @click="deleteConfirm" :disabled="processing" v-if="id">Delete</button>
|
<button type="button" class="btn btn-danger" @click="deleteConfirm" :disabled="processing" v-if="id">Delete</button>
|
||||||
|
|
Loading…
Add table
Reference in a new issue