mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-25 21:15:55 +00:00
Compare commits
9 commits
3410012862
...
4820e57820
Author | SHA1 | Date | |
---|---|---|---|
|
4820e57820 | ||
|
cc00cc916a | ||
|
e9935d7b3b | ||
|
7a8ab0271e | ||
|
8c3589d40c | ||
|
ddb98ac1d4 | ||
|
12b9d55ef5 | ||
|
6c8b159174 | ||
|
89751b5f33 |
8 changed files with 281 additions and 113 deletions
34
server/notification-providers/bale.js
Normal file
34
server/notification-providers/bale.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
|
||||
class Bale extends NotificationProvider {
|
||||
name = "bale";
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
const okMsg = "Sent Successfully.";
|
||||
const url = "https://tapi.bale.ai";
|
||||
|
||||
try {
|
||||
await axios.post(
|
||||
`${url}/bot${notification.baleBotToken}/sendMessage`,
|
||||
{
|
||||
chat_id: notification.baleChatID,
|
||||
text: msg
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
},
|
||||
}
|
||||
);
|
||||
return okMsg;
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Bale;
|
|
@ -1,5 +1,6 @@
|
|||
const { getMonitorRelativeURL } = require("../../src/util");
|
||||
const { setting } = require("../util-server");
|
||||
const { UP } = require("../../src/util");
|
||||
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
|
@ -43,15 +44,20 @@ class Pushover extends NotificationProvider {
|
|||
if (heartbeatJSON == null) {
|
||||
await axios.post(url, data);
|
||||
return okMsg;
|
||||
} else {
|
||||
data.message += `\n<b>Time (${heartbeatJSON["timezone"]})</b>:${heartbeatJSON["localDateTime"]}`;
|
||||
await axios.post(url, data);
|
||||
return okMsg;
|
||||
}
|
||||
|
||||
if (heartbeatJSON.status === UP && notification.pushoversounds_up) {
|
||||
// default = DOWN => DOWN-sound is also played for non-UP/DOWN notiifcations
|
||||
data.sound = notification.pushoversounds_up;
|
||||
}
|
||||
|
||||
data.message += `\n<b>Time (${heartbeatJSON["timezone"]})</b>: ${heartbeatJSON["localDateTime"]}`;
|
||||
await axios.post(url, data);
|
||||
return okMsg;
|
||||
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ const Alerta = require("./notification-providers/alerta");
|
|||
const AlertNow = require("./notification-providers/alertnow");
|
||||
const AliyunSms = require("./notification-providers/aliyun-sms");
|
||||
const Apprise = require("./notification-providers/apprise");
|
||||
const Bale = require("./notification-providers/bale");
|
||||
const Bark = require("./notification-providers/bark");
|
||||
const Bitrix24 = require("./notification-providers/bitrix24");
|
||||
const ClickSendSMS = require("./notification-providers/clicksendsms");
|
||||
|
@ -71,7 +72,6 @@ const Wpush = require("./notification-providers/wpush");
|
|||
const SendGrid = require("./notification-providers/send-grid");
|
||||
|
||||
class Notification {
|
||||
|
||||
providerList = {};
|
||||
|
||||
/**
|
||||
|
@ -90,6 +90,7 @@ class Notification {
|
|||
new AlertNow(),
|
||||
new AliyunSms(),
|
||||
new Apprise(),
|
||||
new Bale(),
|
||||
new Bark(),
|
||||
new Bitrix24(),
|
||||
new ClickSendSMS(),
|
||||
|
@ -154,10 +155,10 @@ class Notification {
|
|||
new GtxMessaging(),
|
||||
new Cellsynt(),
|
||||
new Wpush(),
|
||||
new SendGrid()
|
||||
new SendGrid(),
|
||||
];
|
||||
for (let item of list) {
|
||||
if (! item.name) {
|
||||
if (!item.name) {
|
||||
throw new Error("Notification provider without name");
|
||||
}
|
||||
|
||||
|
@ -177,9 +178,19 @@ class Notification {
|
|||
* @returns {Promise<string>} Successful msg
|
||||
* @throws Error with fail msg
|
||||
*/
|
||||
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
static async send(
|
||||
notification,
|
||||
msg,
|
||||
monitorJSON = null,
|
||||
heartbeatJSON = null
|
||||
) {
|
||||
if (this.providerList[notification.type]) {
|
||||
return this.providerList[notification.type].send(notification, msg, monitorJSON, heartbeatJSON);
|
||||
return this.providerList[notification.type].send(
|
||||
notification,
|
||||
msg,
|
||||
monitorJSON,
|
||||
heartbeatJSON
|
||||
);
|
||||
} else {
|
||||
throw new Error("Notification type is not supported");
|
||||
}
|
||||
|
@ -201,10 +212,9 @@ class Notification {
|
|||
userID,
|
||||
]);
|
||||
|
||||
if (! bean) {
|
||||
if (!bean) {
|
||||
throw new Error("notification not found");
|
||||
}
|
||||
|
||||
} else {
|
||||
bean = R.dispense("notification");
|
||||
}
|
||||
|
@ -234,7 +244,7 @@ class Notification {
|
|||
userID,
|
||||
]);
|
||||
|
||||
if (! bean) {
|
||||
if (!bean) {
|
||||
throw new Error("notification not found");
|
||||
}
|
||||
|
||||
|
@ -250,7 +260,6 @@ class Notification {
|
|||
let exists = commandExistsSync("apprise");
|
||||
return exists;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -261,16 +270,17 @@ class Notification {
|
|||
*/
|
||||
async function applyNotificationEveryMonitor(notificationID, userID) {
|
||||
let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [
|
||||
userID
|
||||
userID,
|
||||
]);
|
||||
|
||||
for (let i = 0; i < monitors.length; i++) {
|
||||
let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [
|
||||
monitors[i].id,
|
||||
notificationID,
|
||||
]);
|
||||
let checkNotification = await R.findOne(
|
||||
"monitor_notification",
|
||||
" monitor_id = ? AND notification_id = ? ",
|
||||
[ monitors[i].id, notificationID ]
|
||||
);
|
||||
|
||||
if (! checkNotification) {
|
||||
if (!checkNotification) {
|
||||
let relation = R.dispense("monitor_notification");
|
||||
relation.monitor_id = monitors[i].id;
|
||||
relation.notification_id = notificationID;
|
||||
|
|
|
@ -113,6 +113,7 @@ export default {
|
|||
"alerta": "Alerta",
|
||||
"AlertNow": "AlertNow",
|
||||
"apprise": this.$t("apprise"),
|
||||
"bale": "Bale",
|
||||
"Bark": "Bark",
|
||||
"Bitrix24": "Bitrix24",
|
||||
"clicksendsms": "ClickSend SMS",
|
||||
|
|
93
src/components/notifications/Bale.vue
Normal file
93
src/components/notifications/Bale.vue
Normal file
|
@ -0,0 +1,93 @@
|
|||
<template>
|
||||
<div class="mb-3">
|
||||
<label for="bale-bot-token" class="form-label">{{ $t("Bot Token") }}</label>
|
||||
<HiddenInput id="bale-bot-token" v-model="$parent.notification.baleBotToken" :required="true" autocomplete="new-password"></HiddenInput>
|
||||
<i18n-t tag="div" keypath="wayToGetBaleToken" class="form-text">
|
||||
<a href="https://ble.ir/BotFather" target="_blank">https://ble.ir/BotFather</a>
|
||||
</i18n-t>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="bale-chat-id" class="form-label">{{ $t("Chat ID") }}</label>
|
||||
|
||||
<div class="input-group mb-3">
|
||||
<input id="bale-chat-id" v-model="$parent.notification.baleChatID" type="text" class="form-control" required>
|
||||
<button v-if="$parent.notification.baleBotToken" class="btn btn-outline-secondary" type="button" @click="autoGetBaleChatID">
|
||||
{{ $t("Auto Get") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="form-text">
|
||||
{{ $t("supportBaleChatID") }}
|
||||
|
||||
<p style="margin-top: 8px;">
|
||||
{{ $t("wayToGetBaleChatID") }}
|
||||
</p>
|
||||
|
||||
<p style="margin-top: 8px;">
|
||||
<a :href="baleGetUpdatesURL('withToken')" target="_blank" style="word-break: break-word;">{{ baleGetUpdatesURL("masked") }}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import HiddenInput from "../HiddenInput.vue";
|
||||
import axios from "axios";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
HiddenInput,
|
||||
},
|
||||
methods: {
|
||||
/**
|
||||
* Get the URL for bale updates
|
||||
* @param {string} mode Should the token be masked?
|
||||
* @returns {string} formatted URL
|
||||
*/
|
||||
baleGetUpdatesURL(mode = "masked") {
|
||||
let token = `<${this.$t("YOUR BOT TOKEN HERE")}>`;
|
||||
|
||||
if (this.$parent.notification.baleBotToken) {
|
||||
if (mode === "withToken") {
|
||||
token = this.$parent.notification.baleBotToken;
|
||||
} else if (mode === "masked") {
|
||||
token = "*".repeat(this.$parent.notification.baleBotToken.length);
|
||||
}
|
||||
}
|
||||
|
||||
return `https://tapi.bale.ai/bot${token}/getUpdates`;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the bale chat ID
|
||||
* @returns {Promise<void>}
|
||||
* @throws The chat ID could not be found
|
||||
*/
|
||||
async autoGetBaleChatID() {
|
||||
try {
|
||||
let res = await axios.get(this.baleGetUpdatesURL("withToken"));
|
||||
|
||||
if (res.data.result.length >= 1) {
|
||||
let update = res.data.result[res.data.result.length - 1];
|
||||
|
||||
if (update.channel_post) {
|
||||
this.$parent.notification.baleChatID = update.channel_post.chat.id;
|
||||
} else if (update.message) {
|
||||
this.$parent.notification.baleChatID = update.message.chat.id;
|
||||
} else {
|
||||
throw new Error(this.$t("chatIDNotFound"));
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new Error(this.$t("chatIDNotFound"));
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
this.$root.toastError(error.message);
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
|
@ -16,34 +16,24 @@
|
|||
<option>1</option>
|
||||
<option>2</option>
|
||||
</select>
|
||||
<label for="pushover-sound" class="form-label">{{ $t("Notification Sound") }}</label>
|
||||
<select id="pushover-sound" v-model="$parent.notification.pushoversounds" class="form-select">
|
||||
<option value="pushover">{{ $t("pushoversounds pushover") }}</option>
|
||||
<option value="bike">{{ $t("pushoversounds bike") }}</option>
|
||||
<option value="bugle">{{ $t("pushoversounds bugle") }}</option>
|
||||
<option value="cashregister">{{ $t("pushoversounds cashregister") }}</option>
|
||||
<option value="classical">{{ $t("pushoversounds classical") }}</option>
|
||||
<option value="cosmic">{{ $t("pushoversounds cosmic") }}</option>
|
||||
<option value="falling">{{ $t("pushoversounds falling") }}</option>
|
||||
<option value="gamelan">{{ $t("pushoversounds gamelan") }}</option>
|
||||
<option value="incoming">{{ $t("pushoversounds incoming") }}</option>
|
||||
<option value="intermission">{{ $t("pushoversounds intermission") }}</option>
|
||||
<option value="magic">{{ $t("pushoversounds magic") }}</option>
|
||||
<option value="mechanical">{{ $t("pushoversounds mechanical") }}</option>
|
||||
<option value="pianobar">{{ $t("pushoversounds pianobar") }}</option>
|
||||
<option value="siren">{{ $t("pushoversounds siren") }}</option>
|
||||
<option value="spacealarm">{{ $t("pushoversounds spacealarm") }}</option>
|
||||
<option value="tugboat">{{ $t("pushoversounds tugboat") }}</option>
|
||||
<option value="alien">{{ $t("pushoversounds alien") }}</option>
|
||||
<option value="climb">{{ $t("pushoversounds climb") }}</option>
|
||||
<option value="persistent">{{ $t("pushoversounds persistent") }}</option>
|
||||
<option value="echo">{{ $t("pushoversounds echo") }}</option>
|
||||
<option value="updown">{{ $t("pushoversounds updown") }}</option>
|
||||
<option value="vibrate">{{ $t("pushoversounds vibrate") }}</option>
|
||||
<option value="none">{{ $t("pushoversounds none") }}</option>
|
||||
|
||||
<label for="pushover-sound-down" class="form-label">{{ $t("Notification Sound") }} - Up</label>
|
||||
<select id="pushover-sound-down" v-model="$parent.notification.pushoversounds" class="form-select">
|
||||
<option v-for="sound in soundOptions" :key="sound" :value="sound">
|
||||
{{ $t(`pushoversounds ${sound}`) }}
|
||||
</option>
|
||||
</select>
|
||||
|
||||
<label for="pushover-sound-up" class="form-label">{{ $t("Notification Sound") }} - Down</label>
|
||||
<select id="pushover-sound-up" v-model="$parent.notification.pushoversounds_up" class="form-select">
|
||||
<option v-for="sound in soundOptions" :key="sound" :value="sound">
|
||||
{{ $t(`pushoversounds ${sound}`) }}
|
||||
</option>
|
||||
</select>
|
||||
|
||||
<label for="pushover-ttl" class="form-label">{{ $t("pushoverMessageTtl") }}</label>
|
||||
<input id="pushover-ttl" v-model="$parent.notification.pushoverttl" type="number" min="0" step="1" class="form-control">
|
||||
|
||||
<div class="form-text">
|
||||
<span style="color: red;"><sup>*</sup></span>{{ $t("Required") }}
|
||||
<i18n-t tag="p" keypath="More info on:" style="margin-top: 8px;">
|
||||
|
@ -66,5 +56,34 @@ export default {
|
|||
components: {
|
||||
HiddenInput,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
soundOptions: [
|
||||
"pushover",
|
||||
"bike",
|
||||
"bugle",
|
||||
"cashregister",
|
||||
"classical",
|
||||
"cosmic",
|
||||
"falling",
|
||||
"gamelan",
|
||||
"incoming",
|
||||
"intermission",
|
||||
"magic",
|
||||
"mechanical",
|
||||
"pianobar",
|
||||
"siren",
|
||||
"spacealarm",
|
||||
"tugboat",
|
||||
"alien",
|
||||
"climb",
|
||||
"persistent",
|
||||
"echo",
|
||||
"updown",
|
||||
"vibrate",
|
||||
"none",
|
||||
],
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -2,6 +2,7 @@ import Alerta from "./Alerta.vue";
|
|||
import AlertNow from "./AlertNow.vue";
|
||||
import AliyunSMS from "./AliyunSms.vue";
|
||||
import Apprise from "./Apprise.vue";
|
||||
import Bale from "./Bale.vue";
|
||||
import Bark from "./Bark.vue";
|
||||
import Bitrix24 from "./Bitrix24.vue";
|
||||
import ClickSendSMS from "./ClickSendSMS.vue";
|
||||
|
@ -73,75 +74,76 @@ import SendGrid from "./SendGrid.vue";
|
|||
* @type { Record<string, any> }
|
||||
*/
|
||||
const NotificationFormList = {
|
||||
"alerta": Alerta,
|
||||
"AlertNow": AlertNow,
|
||||
"AliyunSMS": AliyunSMS,
|
||||
"apprise": Apprise,
|
||||
"Bark": Bark,
|
||||
"Bitrix24": Bitrix24,
|
||||
"clicksendsms": ClickSendSMS,
|
||||
"CallMeBot": CallMeBot,
|
||||
"smsc": SMSC,
|
||||
"DingDing": DingDing,
|
||||
"discord": Discord,
|
||||
"Elks": Elks,
|
||||
"Feishu": Feishu,
|
||||
"FreeMobile": FreeMobile,
|
||||
"GoogleChat": GoogleChat,
|
||||
"gorush": Gorush,
|
||||
"gotify": Gotify,
|
||||
"GrafanaOncall": GrafanaOncall,
|
||||
"HomeAssistant": HomeAssistant,
|
||||
"HeiiOnCall": HeiiOnCall,
|
||||
"Keep": Keep,
|
||||
"Kook": Kook,
|
||||
"line": Line,
|
||||
"LineNotify": LineNotify,
|
||||
"lunasea": LunaSea,
|
||||
"matrix": Matrix,
|
||||
"mattermost": Mattermost,
|
||||
"nostr": Nostr,
|
||||
"ntfy": Ntfy,
|
||||
"octopush": Octopush,
|
||||
"OneBot": OneBot,
|
||||
"Onesender": Onesender,
|
||||
"Opsgenie": Opsgenie,
|
||||
"PagerDuty": PagerDuty,
|
||||
"FlashDuty": FlashDuty,
|
||||
"PagerTree": PagerTree,
|
||||
"promosms": PromoSMS,
|
||||
"pushbullet": Pushbullet,
|
||||
"PushByTechulus": TechulusPush,
|
||||
"PushDeer": PushDeer,
|
||||
"pushover": Pushover,
|
||||
"pushy": Pushy,
|
||||
alerta: Alerta,
|
||||
AlertNow: AlertNow,
|
||||
AliyunSMS: AliyunSMS,
|
||||
apprise: Apprise,
|
||||
bale: Bale,
|
||||
Bark: Bark,
|
||||
Bitrix24: Bitrix24,
|
||||
clicksendsms: ClickSendSMS,
|
||||
CallMeBot: CallMeBot,
|
||||
smsc: SMSC,
|
||||
DingDing: DingDing,
|
||||
discord: Discord,
|
||||
Elks: Elks,
|
||||
Feishu: Feishu,
|
||||
FreeMobile: FreeMobile,
|
||||
GoogleChat: GoogleChat,
|
||||
gorush: Gorush,
|
||||
gotify: Gotify,
|
||||
GrafanaOncall: GrafanaOncall,
|
||||
HomeAssistant: HomeAssistant,
|
||||
HeiiOnCall: HeiiOnCall,
|
||||
Keep: Keep,
|
||||
Kook: Kook,
|
||||
line: Line,
|
||||
LineNotify: LineNotify,
|
||||
lunasea: LunaSea,
|
||||
matrix: Matrix,
|
||||
mattermost: Mattermost,
|
||||
nostr: Nostr,
|
||||
ntfy: Ntfy,
|
||||
octopush: Octopush,
|
||||
OneBot: OneBot,
|
||||
Onesender: Onesender,
|
||||
Opsgenie: Opsgenie,
|
||||
PagerDuty: PagerDuty,
|
||||
FlashDuty: FlashDuty,
|
||||
PagerTree: PagerTree,
|
||||
promosms: PromoSMS,
|
||||
pushbullet: Pushbullet,
|
||||
PushByTechulus: TechulusPush,
|
||||
PushDeer: PushDeer,
|
||||
pushover: Pushover,
|
||||
pushy: Pushy,
|
||||
"rocket.chat": RocketChat,
|
||||
"serwersms": SerwerSMS,
|
||||
"signal": Signal,
|
||||
"SIGNL4": SIGNL4,
|
||||
"SMSManager": SMSManager,
|
||||
"SMSPartner": SMSPartner,
|
||||
"slack": Slack,
|
||||
"squadcast": Squadcast,
|
||||
"SMSEagle": SMSEagle,
|
||||
"smtp": STMP,
|
||||
"stackfield": Stackfield,
|
||||
"teams": Teams,
|
||||
"telegram": Telegram,
|
||||
"threema": Threema,
|
||||
"twilio": Twilio,
|
||||
"Splunk": Splunk,
|
||||
"webhook": Webhook,
|
||||
"WeCom": WeCom,
|
||||
"GoAlert": GoAlert,
|
||||
"ServerChan": ServerChan,
|
||||
"ZohoCliq": ZohoCliq,
|
||||
"SevenIO": SevenIO,
|
||||
"whapi": Whapi,
|
||||
"gtxmessaging": GtxMessaging,
|
||||
"Cellsynt": Cellsynt,
|
||||
"WPush": WPush,
|
||||
"SendGrid": SendGrid,
|
||||
serwersms: SerwerSMS,
|
||||
signal: Signal,
|
||||
SIGNL4: SIGNL4,
|
||||
SMSManager: SMSManager,
|
||||
SMSPartner: SMSPartner,
|
||||
slack: Slack,
|
||||
squadcast: Squadcast,
|
||||
SMSEagle: SMSEagle,
|
||||
smtp: STMP,
|
||||
stackfield: Stackfield,
|
||||
teams: Teams,
|
||||
telegram: Telegram,
|
||||
threema: Threema,
|
||||
twilio: Twilio,
|
||||
Splunk: Splunk,
|
||||
webhook: Webhook,
|
||||
WeCom: WeCom,
|
||||
GoAlert: GoAlert,
|
||||
ServerChan: ServerChan,
|
||||
ZohoCliq: ZohoCliq,
|
||||
SevenIO: SevenIO,
|
||||
whapi: Whapi,
|
||||
gtxmessaging: GtxMessaging,
|
||||
Cellsynt: Cellsynt,
|
||||
WPush: WPush,
|
||||
SendGrid: SendGrid,
|
||||
};
|
||||
|
||||
export default NotificationFormList;
|
||||
|
|
|
@ -429,6 +429,9 @@
|
|||
"trustProxyDescription": "Trust 'X-Forwarded-*' headers. If you want to get the correct client IP and your Uptime Kuma is behind a proxy such as Nginx or Apache, you should enable this.",
|
||||
"wayToGetLineNotifyToken": "You can get an access token from {0}",
|
||||
"Examples": "Examples",
|
||||
"supportBaleChatID": "Support Direct Chat / Group / Channel's Chat ID",
|
||||
"wayToGetBaleChatID": "You can get your chat ID by sending a message to the bot and going to this URL to view the chat_id:",
|
||||
"wayToGetBaleToken": "You can get a token from {0}.",
|
||||
"Home Assistant URL": "Home Assistant URL",
|
||||
"Long-Lived Access Token": "Long-Lived Access Token",
|
||||
"Long-Lived Access Token can be created by clicking on your profile name (bottom left) and scrolling to the bottom then click Create Token. ": "Long-Lived Access Token can be created by clicking on your profile name (bottom left) and scrolling to the bottom then click Create Token. ",
|
||||
|
|
Loading…
Add table
Reference in a new issue