2021-06-29 08:06:20 +00:00
|
|
|
<template>
|
2021-07-09 06:14:03 +00:00
|
|
|
<form @submit.prevent="submit">
|
2024-02-13 01:24:42 +00:00
|
|
|
<div ref="modal" class="modal fade" tabindex="-1" data-bs-backdrop="static">
|
2021-07-09 06:14:03 +00:00
|
|
|
<div class="modal-dialog">
|
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
2021-07-27 17:47:13 +00:00
|
|
|
<h5 id="exampleModalLabel" class="modal-title">
|
2021-08-24 10:26:44 +00:00
|
|
|
{{ $t("Setup Notification") }}
|
2021-07-27 17:47:13 +00:00
|
|
|
</h5>
|
2024-02-13 01:24:42 +00:00
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" />
|
2021-07-09 06:14:03 +00:00
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
2021-07-18 10:51:58 +00:00
|
|
|
<div class="mb-3">
|
2024-02-13 01:24:42 +00:00
|
|
|
<label for="notification-type" class="form-label">{{ $t("Notification Type") }}</label>
|
|
|
|
<select id="notification-type" v-model="notification.type" class="form-select">
|
|
|
|
<option v-for="(name, type) in notificationNameList.regularList" :key="type" :value="type">{{ name }}</option>
|
2023-02-23 10:01:42 +00:00
|
|
|
<optgroup :label="$t('notificationRegional')">
|
2024-02-13 01:24:42 +00:00
|
|
|
<option v-for="(name, type) in notificationNameList.regionalList" :key="type" :value="type">{{ name }}</option>
|
2023-02-23 10:01:42 +00:00
|
|
|
</optgroup>
|
2021-07-18 10:51:58 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mb-3">
|
2024-02-13 01:24:42 +00:00
|
|
|
<label for="notification-name" class="form-label">{{ $t("Friendly Name") }}</label>
|
|
|
|
<input id="notification-name" v-model="notification.name" type="text" class="form-control" required>
|
2021-07-18 10:51:58 +00:00
|
|
|
</div>
|
|
|
|
|
2021-09-17 08:07:03 +00:00
|
|
|
<!-- form body -->
|
|
|
|
<component :is="currentForm" />
|
2021-09-12 17:46:59 +00:00
|
|
|
|
2021-09-08 17:13:09 +00:00
|
|
|
<div class="mb-3 mt-4">
|
2024-02-13 01:24:42 +00:00
|
|
|
<hr class="dropdown-divider mb-4">
|
2021-09-05 21:23:06 +00:00
|
|
|
|
|
|
|
<div class="form-check form-switch">
|
2024-02-13 01:24:42 +00:00
|
|
|
<input v-model="notification.isDefault" class="form-check-input" type="checkbox">
|
|
|
|
<label class="form-check-label">{{ $t("Default enabled") }}</label>
|
2021-09-05 21:23:06 +00:00
|
|
|
</div>
|
|
|
|
<div class="form-text">
|
|
|
|
{{ $t("enableDefaultNotificationDescription") }}
|
|
|
|
</div>
|
|
|
|
|
2024-02-13 01:24:42 +00:00
|
|
|
<br>
|
2021-09-05 21:23:06 +00:00
|
|
|
|
|
|
|
<div class="form-check form-switch">
|
2024-02-13 01:24:42 +00:00
|
|
|
<input v-model="notification.applyExisting" class="form-check-input" type="checkbox">
|
|
|
|
<label class="form-check-label">{{ $t("Apply on all existing monitors") }}</label>
|
2021-09-05 21:23:06 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-09 06:14:03 +00:00
|
|
|
</div>
|
2021-09-08 17:13:09 +00:00
|
|
|
|
2021-07-09 06:14:03 +00:00
|
|
|
<div class="modal-footer">
|
2024-02-13 01:24:42 +00:00
|
|
|
<button v-if="id" type="button" class="btn btn-danger" :disabled="processing" @click="deleteConfirm">
|
2021-08-24 10:26:44 +00:00
|
|
|
{{ $t("Delete") }}
|
2021-07-27 17:47:13 +00:00
|
|
|
</button>
|
2024-02-13 01:24:42 +00:00
|
|
|
<button type="button" class="btn btn-warning" :disabled="processing" @click="test">
|
2021-08-24 10:26:44 +00:00
|
|
|
{{ $t("Test") }}
|
2021-07-27 17:47:13 +00:00
|
|
|
</button>
|
2024-02-13 01:24:42 +00:00
|
|
|
<button type="submit" class="btn btn-primary" :disabled="processing">
|
|
|
|
<div v-if="processing" class="spinner-border spinner-border-sm me-1"></div>
|
2021-08-24 10:26:44 +00:00
|
|
|
{{ $t("Save") }}
|
2021-07-27 17:47:13 +00:00
|
|
|
</button>
|
2021-07-09 06:14:03 +00:00
|
|
|
</div>
|
2021-06-29 08:06:20 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-07-09 06:14:03 +00:00
|
|
|
</form>
|
2021-07-09 09:55:48 +00:00
|
|
|
|
2024-02-13 01:24:42 +00:00
|
|
|
<Confirm ref="confirmDelete" btn-style="btn-danger" :yes-text="$t('Yes')" :no-text="$t('No')" @yes="deleteNotification">
|
2021-08-26 00:43:26 +00:00
|
|
|
{{ $t("deleteNotificationMsg") }}
|
2021-07-27 17:47:13 +00:00
|
|
|
</Confirm>
|
2021-06-29 08:06:20 +00:00
|
|
|
</template>
|
|
|
|
|
2023-02-21 20:27:12 +00:00
|
|
|
<script>
|
2021-09-30 11:48:24 +00:00
|
|
|
import { Modal } from "bootstrap";
|
2021-09-07 15:32:05 +00:00
|
|
|
|
2021-07-09 09:55:48 +00:00
|
|
|
import Confirm from "./Confirm.vue";
|
2021-09-30 11:48:24 +00:00
|
|
|
import NotificationFormList from "./notifications";
|
2021-06-29 08:06:20 +00:00
|
|
|
|
|
|
|
export default {
|
2021-07-27 17:47:13 +00:00
|
|
|
components: {
|
|
|
|
Confirm,
|
2021-06-29 08:06:20 +00:00
|
|
|
},
|
2021-07-27 17:47:13 +00:00
|
|
|
props: {},
|
2022-04-17 07:27:35 +00:00
|
|
|
emits: [ "added" ],
|
2021-06-29 08:06:20 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
model: null,
|
2021-07-09 06:14:03 +00:00
|
|
|
processing: false,
|
|
|
|
id: null,
|
2022-03-04 13:48:35 +00:00
|
|
|
notificationTypes: Object.keys(NotificationFormList).sort((a, b) => {
|
|
|
|
return a.toLowerCase().localeCompare(b.toLowerCase());
|
|
|
|
}),
|
2021-07-09 06:14:03 +00:00
|
|
|
notification: {
|
|
|
|
name: "",
|
2021-09-17 12:40:57 +00:00
|
|
|
/** @type { null | keyof NotificationFormList } */
|
2021-07-09 06:14:03 +00:00
|
|
|
type: null,
|
2021-09-07 23:03:24 +00:00
|
|
|
isDefault: false,
|
2021-09-08 17:13:09 +00:00
|
|
|
// Do not set default value here, please scroll to show()
|
2021-09-17 08:54:50 +00:00
|
|
|
}
|
2021-09-30 11:48:24 +00:00
|
|
|
};
|
2021-06-29 08:06:20 +00:00
|
|
|
},
|
2021-07-27 17:47:13 +00:00
|
|
|
|
2021-09-17 08:07:03 +00:00
|
|
|
computed: {
|
|
|
|
currentForm() {
|
|
|
|
if (!this.notification.type) {
|
2021-09-30 11:48:24 +00:00
|
|
|
return null;
|
2021-09-17 08:07:03 +00:00
|
|
|
}
|
2021-09-30 11:48:24 +00:00
|
|
|
return NotificationFormList[this.notification.type];
|
2023-02-21 20:27:12 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
notificationNameList() {
|
2023-02-23 10:01:42 +00:00
|
|
|
let regularList = {
|
2023-02-21 20:27:12 +00:00
|
|
|
"alerta": "Alerta",
|
|
|
|
"AlertNow": "AlertNow",
|
|
|
|
"apprise": this.$t("apprise"),
|
|
|
|
"Bark": "Bark",
|
|
|
|
"clicksendsms": "ClickSend SMS",
|
2024-04-02 19:39:45 +00:00
|
|
|
"CallMeBot": "CallMeBot (WhatsApp, Telegram Call, Facebook Messanger)",
|
2023-02-21 20:27:12 +00:00
|
|
|
"discord": "Discord",
|
|
|
|
"GoogleChat": "Google Chat (Google Workspace)",
|
|
|
|
"gorush": "Gorush",
|
|
|
|
"gotify": "Gotify",
|
2023-10-19 11:32:42 +00:00
|
|
|
"GrafanaOncall": "Grafana Oncall",
|
2024-02-13 01:48:53 +00:00
|
|
|
"HeiiOnCall": "Heii On-Call",
|
2023-02-21 20:27:12 +00:00
|
|
|
"HomeAssistant": "Home Assistant",
|
2024-04-30 14:17:34 +00:00
|
|
|
"Keep": "Keep",
|
2023-02-21 20:27:12 +00:00
|
|
|
"Kook": "Kook",
|
|
|
|
"line": "LINE Messenger",
|
|
|
|
"LineNotify": "LINE Notify",
|
|
|
|
"lunasea": "LunaSea",
|
|
|
|
"matrix": "Matrix",
|
|
|
|
"mattermost": "Mattermost",
|
2023-07-31 09:24:45 +00:00
|
|
|
"nostr": "Nostr",
|
2023-02-21 20:27:12 +00:00
|
|
|
"ntfy": "Ntfy",
|
|
|
|
"octopush": "Octopush",
|
|
|
|
"OneBot": "OneBot",
|
2023-03-21 18:29:37 +00:00
|
|
|
"Opsgenie": "Opsgenie",
|
2023-02-21 20:27:12 +00:00
|
|
|
"PagerDuty": "PagerDuty",
|
2023-05-11 06:54:00 +00:00
|
|
|
"PagerTree": "PagerTree",
|
2023-02-21 20:27:12 +00:00
|
|
|
"pushbullet": "Pushbullet",
|
|
|
|
"PushByTechulus": "Push by Techulus",
|
|
|
|
"pushover": "Pushover",
|
|
|
|
"pushy": "Pushy",
|
|
|
|
"rocket.chat": "Rocket.Chat",
|
|
|
|
"signal": "Signal",
|
|
|
|
"slack": "Slack",
|
|
|
|
"squadcast": "SquadCast",
|
|
|
|
"SMSEagle": "SMSEagle",
|
|
|
|
"smtp": this.$t("smtp"),
|
|
|
|
"stackfield": "Stackfield",
|
|
|
|
"teams": "Microsoft Teams",
|
|
|
|
"telegram": "Telegram",
|
2023-03-25 16:56:01 +00:00
|
|
|
"twilio": "Twilio",
|
2023-02-21 20:27:12 +00:00
|
|
|
"Splunk": "Splunk",
|
|
|
|
"webhook": "Webhook",
|
|
|
|
"GoAlert": "GoAlert",
|
2024-03-26 22:59:09 +00:00
|
|
|
"ZohoCliq": "ZohoCliq",
|
2024-04-27 21:40:59 +00:00
|
|
|
"SevenIO": "SevenIO",
|
2024-04-03 00:22:01 +00:00
|
|
|
"whapi": "WhatsApp (Whapi)",
|
2024-03-29 15:27:54 +00:00
|
|
|
"gtxmessaging": "GtxMessaging",
|
2024-04-03 00:22:01 +00:00
|
|
|
"Cellsynt": "Cellsynt",
|
2023-02-21 20:27:12 +00:00
|
|
|
};
|
|
|
|
|
2023-02-23 10:01:42 +00:00
|
|
|
// Put notifications here if it's not supported in most regions or its documentation is not in English
|
|
|
|
let regionalList = {
|
|
|
|
"AliyunSMS": "AliyunSMS (阿里云短信服务)",
|
|
|
|
"DingDing": "DingDing (钉钉自定义机器人)",
|
|
|
|
"Feishu": "Feishu (飞书)",
|
2023-07-31 18:13:04 +00:00
|
|
|
"FlashDuty": "FlashDuty (快猫星云)",
|
2023-02-23 10:01:42 +00:00
|
|
|
"FreeMobile": "FreeMobile (mobile.free.fr)",
|
|
|
|
"PushDeer": "PushDeer",
|
|
|
|
"promosms": "PromoSMS",
|
|
|
|
"serwersms": "SerwerSMS.pl",
|
|
|
|
"SMSManager": "SmsManager (smsmanager.cz)",
|
|
|
|
"WeCom": "WeCom (企业微信群机器人)",
|
|
|
|
"ServerChan": "ServerChan (Server酱)",
|
2023-07-14 06:29:35 +00:00
|
|
|
"smsc": "SMSC",
|
2023-02-23 10:01:42 +00:00
|
|
|
};
|
|
|
|
|
2023-02-21 20:27:12 +00:00
|
|
|
// Sort by notification name
|
|
|
|
// No idea how, but it works
|
|
|
|
// https://stackoverflow.com/questions/1069666/sorting-object-property-by-values
|
2023-02-23 10:01:42 +00:00
|
|
|
let sort = (list2) => {
|
|
|
|
return Object.entries(list2)
|
|
|
|
.sort(([ , a ], [ , b ]) => a.localeCompare(b))
|
|
|
|
.reduce((r, [ k, v ]) => ({
|
|
|
|
...r,
|
|
|
|
[k]: v
|
|
|
|
}), {});
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
regularList: sort(regularList),
|
|
|
|
regionalList: sort(regionalList),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
notificationFullNameList() {
|
|
|
|
let list = {};
|
|
|
|
for (let [ key, value ] of Object.entries(this.notificationNameList.regularList)) {
|
|
|
|
list[key] = value;
|
|
|
|
}
|
|
|
|
for (let [ key, value ] of Object.entries(this.notificationNameList.regionalList)) {
|
|
|
|
list[key] = value;
|
|
|
|
}
|
|
|
|
return list;
|
2023-02-21 20:27:12 +00:00
|
|
|
},
|
2021-09-17 08:07:03 +00:00
|
|
|
},
|
|
|
|
|
2021-07-27 17:47:13 +00:00
|
|
|
watch: {
|
|
|
|
"notification.type"(to, from) {
|
|
|
|
let oldName;
|
|
|
|
if (from) {
|
2021-09-21 09:25:54 +00:00
|
|
|
oldName = this.getUniqueDefaultName(from);
|
2021-07-27 17:47:13 +00:00
|
|
|
} else {
|
|
|
|
oldName = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! this.notification.name || this.notification.name === oldName) {
|
2021-09-21 09:25:54 +00:00
|
|
|
this.notification.name = this.getUniqueDefaultName(to);
|
2021-07-27 17:47:13 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2021-06-29 08:06:20 +00:00
|
|
|
mounted() {
|
2021-09-30 11:48:24 +00:00
|
|
|
this.modal = new Modal(this.$refs.modal);
|
2021-06-29 08:06:20 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2021-07-09 06:14:03 +00:00
|
|
|
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* Show dialog to confirm deletion
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-07-09 09:55:48 +00:00
|
|
|
deleteConfirm() {
|
|
|
|
this.modal.hide();
|
2021-09-30 11:48:24 +00:00
|
|
|
this.$refs.confirmDelete.show();
|
2021-07-09 09:55:48 +00:00
|
|
|
},
|
|
|
|
|
2022-06-01 23:32:05 +00:00
|
|
|
/**
|
|
|
|
* Show settings for specified notification
|
|
|
|
* @param {number} notificationID ID of notification to show
|
2023-08-11 07:46:41 +00:00
|
|
|
* @returns {void}
|
2022-06-01 23:32:05 +00:00
|
|
|
*/
|
2021-07-09 06:14:03 +00:00
|
|
|
show(notificationID) {
|
|
|
|
if (notificationID) {
|
|
|
|
this.id = notificationID;
|
|
|
|
|
|
|
|
for (let n of this.$root.notificationList) {
|
|
|
|
if (n.id === notificationID) {
|
|
|
|
this.notification = JSON.parse(n.config);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.id = null;
|
|
|
|
this.notification = {
|
|
|
|
name: "",
|
2022-03-07 07:52:17 +00:00
|
|
|
type: "telegram",
|
2021-09-07 23:03:24 +00:00
|
|
|
isDefault: false,
|
2021-09-30 11:48:24 +00:00
|
|
|
};
|
2021-07-09 06:14:03 +00:00
|
|
|
}
|
|
|
|
|
2021-09-30 11:48:24 +00:00
|
|
|
this.modal.show();
|
2021-06-29 08:06:20 +00:00
|
|
|
},
|
2021-07-09 06:14:03 +00:00
|
|
|
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* Submit the form to the server
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-06-29 08:06:20 +00:00
|
|
|
submit() {
|
2021-07-09 06:14:03 +00:00
|
|
|
this.processing = true;
|
|
|
|
this.$root.getSocket().emit("addNotification", this.notification, this.id, (res) => {
|
2021-09-30 11:48:24 +00:00
|
|
|
this.$root.toastRes(res);
|
2021-07-09 06:14:03 +00:00
|
|
|
this.processing = false;
|
2021-06-29 08:06:20 +00:00
|
|
|
|
2021-07-09 06:14:03 +00:00
|
|
|
if (res.ok) {
|
2021-09-09 13:24:29 +00:00
|
|
|
this.modal.hide();
|
|
|
|
|
|
|
|
// Emit added event, doesn't emit edit.
|
|
|
|
if (! this.id) {
|
|
|
|
this.$emit("added", res.id);
|
|
|
|
}
|
|
|
|
|
2021-07-09 06:14:03 +00:00
|
|
|
}
|
2021-09-30 11:48:24 +00:00
|
|
|
});
|
2021-07-09 06:14:03 +00:00
|
|
|
},
|
|
|
|
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* Test the notification endpoint
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-07-09 06:14:03 +00:00
|
|
|
test() {
|
|
|
|
this.processing = true;
|
|
|
|
this.$root.getSocket().emit("testNotification", this.notification, (res) => {
|
2021-09-30 11:48:24 +00:00
|
|
|
this.$root.toastRes(res);
|
2021-07-09 06:14:03 +00:00
|
|
|
this.processing = false;
|
2021-09-30 11:48:24 +00:00
|
|
|
});
|
2021-07-09 06:14:03 +00:00
|
|
|
},
|
|
|
|
|
2023-08-11 07:46:41 +00:00
|
|
|
/**
|
|
|
|
* Delete the notification endpoint
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2021-07-09 06:14:03 +00:00
|
|
|
deleteNotification() {
|
|
|
|
this.processing = true;
|
|
|
|
this.$root.getSocket().emit("deleteNotification", this.id, (res) => {
|
2021-09-30 11:48:24 +00:00
|
|
|
this.$root.toastRes(res);
|
2021-07-09 06:14:03 +00:00
|
|
|
this.processing = false;
|
|
|
|
|
|
|
|
if (res.ok) {
|
2021-09-30 11:48:24 +00:00
|
|
|
this.modal.hide();
|
2021-07-09 06:14:03 +00:00
|
|
|
}
|
2021-09-30 11:48:24 +00:00
|
|
|
});
|
2021-07-09 06:14:03 +00:00
|
|
|
},
|
2021-09-21 09:25:54 +00:00
|
|
|
/**
|
2022-06-01 23:32:05 +00:00
|
|
|
* Get a unique default name for the notification
|
2021-09-22 08:13:23 +00:00
|
|
|
* @param {keyof NotificationFormList} notificationKey
|
2023-08-11 07:46:41 +00:00
|
|
|
* Notification to retrieve
|
|
|
|
* @returns {string} Default name
|
2021-09-21 09:25:54 +00:00
|
|
|
*/
|
|
|
|
getUniqueDefaultName(notificationKey) {
|
2023-02-21 20:29:43 +00:00
|
|
|
|
2021-09-30 11:48:24 +00:00
|
|
|
let index = 1;
|
|
|
|
let name = "";
|
2021-09-21 09:25:54 +00:00
|
|
|
do {
|
2021-09-30 11:48:24 +00:00
|
|
|
name = this.$t("defaultNotificationName", {
|
2023-02-23 10:01:42 +00:00
|
|
|
notification: this.notificationFullNameList[notificationKey].replace(/\(.+\)/, "").trim(),
|
2021-09-30 11:48:24 +00:00
|
|
|
number: index++
|
|
|
|
});
|
|
|
|
} while (this.$root.notificationList.find(it => it.name === name));
|
2023-02-21 20:29:43 +00:00
|
|
|
return name;
|
2021-09-21 09:25:54 +00:00
|
|
|
}
|
2021-07-09 06:14:03 +00:00
|
|
|
},
|
2021-09-30 11:48:24 +00:00
|
|
|
};
|
2021-06-29 08:06:20 +00:00
|
|
|
</script>
|
2021-08-08 05:47:29 +00:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import "../assets/vars.scss";
|
|
|
|
|
|
|
|
.dark {
|
2024-02-13 01:24:42 +00:00
|
|
|
.modal-dialog .form-text, .modal-dialog p {
|
2021-08-08 05:47:29 +00:00
|
|
|
color: $dark-font-color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|