2021-06-25 13:55:49 +00:00
|
|
|
<template>
|
2021-08-05 11:04:38 +00:00
|
|
|
<h1 class="my-3">
|
2021-07-27 17:47:13 +00:00
|
|
|
{{ pageName }}
|
|
|
|
</h1>
|
2021-06-25 13:55:49 +00:00
|
|
|
<form @submit.prevent="submit">
|
2021-07-27 17:47:13 +00:00
|
|
|
<div class="shadow-box">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6">
|
|
|
|
<h2>General</h2>
|
2021-06-25 13:55:49 +00:00
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div class="my-3">
|
2021-06-25 13:55:49 +00:00
|
|
|
<label for="type" class="form-label">Monitor Type</label>
|
2021-07-27 17:47:13 +00:00
|
|
|
<select id="type" v-model="monitor.type" class="form-select" aria-label="Default select example">
|
|
|
|
<option value="http">
|
|
|
|
HTTP(s)
|
|
|
|
</option>
|
|
|
|
<option value="port">
|
|
|
|
TCP Port
|
|
|
|
</option>
|
|
|
|
<option value="ping">
|
|
|
|
Ping
|
|
|
|
</option>
|
|
|
|
<option value="keyword">
|
|
|
|
HTTP(s) - Keyword
|
|
|
|
</option>
|
2021-06-25 13:55:49 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div class="my-3">
|
2021-06-25 13:55:49 +00:00
|
|
|
<label for="name" class="form-label">Friendly Name</label>
|
2021-07-27 17:47:13 +00:00
|
|
|
<input id="name" v-model="monitor.name" type="text" class="form-control" required>
|
2021-06-25 13:55:49 +00:00
|
|
|
</div>
|
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' " class="my-3">
|
2021-06-25 13:55:49 +00:00
|
|
|
<label for="url" class="form-label">URL</label>
|
2021-07-27 17:47:13 +00:00
|
|
|
<input id="url" v-model="monitor.url" type="url" class="form-control" pattern="https?://.+" required>
|
2021-06-25 13:55:49 +00:00
|
|
|
</div>
|
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div v-if="monitor.type === 'keyword' " class="my-3">
|
2021-07-11 06:20:31 +00:00
|
|
|
<label for="keyword" class="form-label">Keyword</label>
|
2021-07-27 17:47:13 +00:00
|
|
|
<input id="keyword" v-model="monitor.keyword" type="text" class="form-control" required>
|
|
|
|
<div class="form-text">
|
|
|
|
Search keyword in plain html or JSON response and it is case-sensitive
|
|
|
|
</div>
|
2021-07-11 06:20:31 +00:00
|
|
|
</div>
|
2021-07-01 09:19:28 +00:00
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div v-if="monitor.type === 'port' || monitor.type === 'ping' " class="my-3">
|
2021-07-01 09:00:23 +00:00
|
|
|
<label for="hostname" class="form-label">Hostname</label>
|
2021-07-27 17:47:13 +00:00
|
|
|
<input id="hostname" v-model="monitor.hostname" type="text" class="form-control" required>
|
2021-07-01 09:00:23 +00:00
|
|
|
</div>
|
2021-07-01 06:03:06 +00:00
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div v-if="monitor.type === 'port' " class="my-3">
|
2021-07-01 09:00:23 +00:00
|
|
|
<label for="port" class="form-label">Port</label>
|
2021-07-27 17:47:13 +00:00
|
|
|
<input id="port" v-model="monitor.port" type="number" class="form-control" required min="0" max="65535" step="1">
|
2021-07-01 09:00:23 +00:00
|
|
|
</div>
|
2021-07-01 06:03:06 +00:00
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div class="my-3">
|
2021-06-25 13:55:49 +00:00
|
|
|
<label for="interval" class="form-label">Heartbeat Interval (Every {{ monitor.interval }} seconds)</label>
|
2021-07-27 17:47:13 +00:00
|
|
|
<input id="interval" v-model="monitor.interval" type="number" class="form-control" required min="20" step="1">
|
2021-06-25 13:55:49 +00:00
|
|
|
</div>
|
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div class="my-3">
|
2021-07-22 11:02:44 +00:00
|
|
|
<label for="maxRetries" class="form-label">Retries</label>
|
2021-07-27 17:47:13 +00:00
|
|
|
<input id="maxRetries" v-model="monitor.maxretries" type="number" class="form-control" required min="0" step="1">
|
|
|
|
<div class="form-text">
|
|
|
|
Maximum retries before the service is marked as down and a notification is sent
|
|
|
|
</div>
|
2021-07-19 16:23:06 +00:00
|
|
|
</div>
|
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<h2 class="my-3">Advanced</h2>
|
2021-07-29 17:09:14 +00:00
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' " class="my-3 form-check">
|
2021-07-29 17:09:14 +00:00
|
|
|
<input id="ignore-tls" v-model="monitor.ignoreTls" class="form-check-input" type="checkbox" value="">
|
|
|
|
<label class="form-check-label" for="ignore-tls">
|
|
|
|
Ignore TLS/SSL error for HTTPS websites
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div class="my-3 form-check">
|
2021-07-29 17:09:14 +00:00
|
|
|
<input id="upside-down" v-model="monitor.upsideDown" class="form-check-input" type="checkbox">
|
|
|
|
<label class="form-check-label" for="upside-down">
|
|
|
|
Upside Down Mode
|
|
|
|
</label>
|
|
|
|
<div class="form-text">
|
|
|
|
Flip the status upside down. If the service is reachable, it is DOWN.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div class="my-3">
|
|
|
|
<label for="maxRedirects" class="form-label">Max. Redirects</label>
|
|
|
|
<input id="maxRedirects" v-model="monitor.maxredirects" type="number" class="form-control" required min="0" step="1">
|
|
|
|
<div class="form-text">
|
|
|
|
Maximum number of redirects to follow. Set to 0 to disable redirects.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="my-3">
|
|
|
|
<label for="acceptedStatusCodes" class="form-label">Accepted Status Codes</label>
|
|
|
|
<VueMultiselect id="acceptedStatusCodes" v-model="monitor.accepted_statuscodes" :options="acceptedStatusCodeOptions" :multiple="true" :close-on-select="false" :clear-on-select="false" :preserve-search="true" placeholder="Pick Accepted Status Codes..." :preselect-first="false">
|
|
|
|
<template #selection="{ values, isOpen }"><span v-if="values.length && !isOpen" class="multiselect__single">{{ values.length }} options selected</span></template>
|
|
|
|
</VueMultiselect>
|
|
|
|
<div class="form-text">
|
|
|
|
Select status codes which are considered as a successful response.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-06-25 13:55:49 +00:00
|
|
|
<div>
|
2021-07-27 17:47:13 +00:00
|
|
|
<button class="btn btn-primary" type="submit" :disabled="processing">
|
|
|
|
Save
|
|
|
|
</button>
|
2021-06-25 13:55:49 +00:00
|
|
|
</div>
|
2021-07-27 17:47:13 +00:00
|
|
|
</div>
|
2021-06-25 13:55:49 +00:00
|
|
|
|
2021-07-27 17:47:13 +00:00
|
|
|
<div class="col-md-6">
|
|
|
|
<div v-if="$root.isMobile" class="mt-3" />
|
2021-07-11 07:23:28 +00:00
|
|
|
|
2021-07-27 17:47:13 +00:00
|
|
|
<h2>Notifications</h2>
|
|
|
|
<p v-if="$root.notificationList.length === 0">
|
|
|
|
Not available, please setup.
|
|
|
|
</p>
|
2021-07-11 07:23:28 +00:00
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<div v-for="notification in $root.notificationList" :key="notification.id" class="form-check form-switch my-3">
|
2021-07-27 17:47:13 +00:00
|
|
|
<input :id=" 'notification' + notification.id" v-model="monitor.notificationIDList[notification.id]" class="form-check-input" type="checkbox">
|
2021-07-09 06:14:03 +00:00
|
|
|
|
2021-07-27 17:47:13 +00:00
|
|
|
<label class="form-check-label" :for=" 'notification' + notification.id">
|
|
|
|
{{ notification.name }}
|
|
|
|
<a href="#" @click="$refs.notificationDialog.show(notification.id)">Edit</a>
|
|
|
|
</label>
|
|
|
|
</div>
|
2021-07-09 09:55:48 +00:00
|
|
|
|
2021-07-27 17:47:13 +00:00
|
|
|
<button class="btn btn-primary me-2" type="button" @click="$refs.notificationDialog.show()">
|
|
|
|
Setup Notification
|
|
|
|
</button>
|
2021-07-09 06:14:03 +00:00
|
|
|
</div>
|
2021-06-25 13:55:49 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
2021-06-29 08:06:20 +00:00
|
|
|
<NotificationDialog ref="notificationDialog" />
|
2021-06-25 13:55:49 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-06-29 08:06:20 +00:00
|
|
|
import NotificationDialog from "../components/NotificationDialog.vue";
|
2021-07-27 17:47:13 +00:00
|
|
|
import { useToast } from "vue-toastification"
|
2021-08-05 11:04:38 +00:00
|
|
|
import VueMultiselect from "vue-multiselect"
|
2021-06-25 13:55:49 +00:00
|
|
|
const toast = useToast()
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2021-07-27 17:47:13 +00:00
|
|
|
NotificationDialog,
|
2021-08-05 11:04:38 +00:00
|
|
|
VueMultiselect
|
2021-06-25 13:55:49 +00:00
|
|
|
},
|
|
|
|
data() {
|
2021-08-05 11:04:38 +00:00
|
|
|
let acceptedStatusCodeOptions = [
|
|
|
|
"100-199",
|
|
|
|
"200-299",
|
|
|
|
"300-399",
|
|
|
|
"400-499",
|
|
|
|
"500-599",
|
|
|
|
];
|
|
|
|
for (let i = 100; i <= 999; i++) {
|
|
|
|
acceptedStatusCodeOptions.push(i.toString());
|
|
|
|
}
|
2021-06-25 13:55:49 +00:00
|
|
|
return {
|
|
|
|
processing: false,
|
2021-07-09 09:55:48 +00:00
|
|
|
monitor: {
|
|
|
|
notificationIDList: {},
|
|
|
|
},
|
2021-08-05 11:04:38 +00:00
|
|
|
acceptedStatusCodeOptions,
|
2021-06-25 13:55:49 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
pageName() {
|
|
|
|
return (this.isAdd) ? "Add New Monitor" : "Edit"
|
|
|
|
},
|
|
|
|
isAdd() {
|
|
|
|
return this.$route.path === "/add";
|
2021-06-27 08:10:55 +00:00
|
|
|
},
|
|
|
|
isEdit() {
|
|
|
|
return this.$route.path.startsWith("/edit");
|
2021-07-27 17:47:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
"$route.fullPath" () {
|
|
|
|
this.init();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.init();
|
2021-06-25 13:55:49 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2021-06-27 08:10:55 +00:00
|
|
|
init() {
|
|
|
|
if (this.isAdd) {
|
|
|
|
console.log("??????")
|
|
|
|
this.monitor = {
|
|
|
|
type: "http",
|
|
|
|
name: "",
|
|
|
|
url: "https://",
|
|
|
|
interval: 60,
|
2021-07-22 09:34:41 +00:00
|
|
|
maxretries: 0,
|
2021-07-09 09:55:48 +00:00
|
|
|
notificationIDList: {},
|
2021-07-30 11:18:26 +00:00
|
|
|
ignoreTls: false,
|
2021-07-29 17:09:14 +00:00
|
|
|
upsideDown: false,
|
2021-08-05 11:04:38 +00:00
|
|
|
maxredirects: 10,
|
|
|
|
accepted_statuscodes: ["200-299"],
|
2021-06-27 08:10:55 +00:00
|
|
|
}
|
|
|
|
} else if (this.isEdit) {
|
|
|
|
this.$root.getSocket().emit("getMonitor", this.$route.params.id, (res) => {
|
|
|
|
if (res.ok) {
|
|
|
|
this.monitor = res.monitor;
|
|
|
|
} else {
|
|
|
|
toast.error(res.msg)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2021-06-25 13:55:49 +00:00
|
|
|
submit() {
|
|
|
|
this.processing = true;
|
|
|
|
|
|
|
|
if (this.isAdd) {
|
|
|
|
this.$root.add(this.monitor, (res) => {
|
|
|
|
this.processing = false;
|
|
|
|
|
|
|
|
if (res.ok) {
|
|
|
|
toast.success(res.msg);
|
|
|
|
this.$router.push("/dashboard/" + res.monitorID)
|
|
|
|
} else {
|
|
|
|
toast.error(res.msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
} else {
|
2021-06-27 08:10:55 +00:00
|
|
|
this.$root.getSocket().emit("editMonitor", this.monitor, (res) => {
|
|
|
|
this.processing = false;
|
|
|
|
this.$root.toastRes(res)
|
|
|
|
})
|
2021-06-25 13:55:49 +00:00
|
|
|
}
|
2021-07-27 17:47:13 +00:00
|
|
|
},
|
2021-06-27 08:10:55 +00:00
|
|
|
},
|
2021-06-25 13:55:49 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-08-05 11:04:38 +00:00
|
|
|
<style src="vue-multiselect/dist/vue-multiselect.css"></style>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.multiselect__tags {
|
|
|
|
border-radius: 2rem;
|
|
|
|
border: 1px solid #ced4da;
|
|
|
|
}
|
|
|
|
.multiselect--active .multiselect__tags {
|
|
|
|
border-radius: 1rem;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2021-06-25 13:55:49 +00:00
|
|
|
<style scoped>
|
|
|
|
.shadow-box {
|
|
|
|
padding: 20px;
|
|
|
|
}
|
|
|
|
</style>
|