You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
uptime-kuma/src/pages/EditMonitor.vue

196 lines
7.2 KiB

3 years ago
<template>
3 years ago
<h1 class="mb-3">
{{ pageName }}
</h1>
3 years ago
<form @submit.prevent="submit">
3 years ago
<div class="shadow-box">
<div class="row">
<div class="col-md-6">
<h2>General</h2>
3 years ago
<div class="mb-3">
<label for="type" class="form-label">Monitor Type</label>
3 years ago
<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>
3 years ago
</select>
</div>
<div class="mb-3">
<label for="name" class="form-label">Friendly Name</label>
3 years ago
<input id="name" v-model="monitor.name" type="text" class="form-control" required>
3 years ago
</div>
3 years ago
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' " class="mb-3">
3 years ago
<label for="url" class="form-label">URL</label>
3 years ago
<input id="url" v-model="monitor.url" type="url" class="form-control" pattern="https?://.+" required>
3 years ago
</div>
3 years ago
<div v-if="monitor.type === 'keyword' " class="mb-3">
<label for="keyword" class="form-label">Keyword</label>
3 years ago
<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>
</div>
3 years ago
<div v-if="monitor.type === 'port' || monitor.type === 'ping' " class="mb-3">
<label for="hostname" class="form-label">Hostname</label>
3 years ago
<input id="hostname" v-model="monitor.hostname" type="text" class="form-control" required>
</div>
3 years ago
3 years ago
<div v-if="monitor.type === 'port' " class="mb-3">
<label for="port" class="form-label">Port</label>
3 years ago
<input id="port" v-model="monitor.port" type="number" class="form-control" required min="0" max="65535" step="1">
</div>
3 years ago
3 years ago
<div class="mb-3">
<label for="interval" class="form-label">Heartbeat Interval (Every {{ monitor.interval }} seconds)</label>
3 years ago
<input id="interval" v-model="monitor.interval" type="number" class="form-control" required min="20" step="1">
3 years ago
</div>
<div class="mb-3">
<label for="maxRetries" class="form-label">Retries</label>
3 years ago
<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>
</div>
3 years ago
<div>
3 years ago
<button class="btn btn-primary" type="submit" :disabled="processing">
Save
</button>
3 years ago
</div>
3 years ago
</div>
3 years ago
3 years ago
<div class="col-md-6">
<div v-if="$root.isMobile" class="mt-3" />
3 years ago
<h2>Notifications</h2>
<p v-if="$root.notificationList.length === 0">
Not available, please setup.
</p>
3 years ago
<div v-for="notification in $root.notificationList" :key="notification.id" class="form-check form-switch mb-3">
<input :id=" 'notification' + notification.id" v-model="monitor.notificationIDList[notification.id]" class="form-check-input" type="checkbox">
3 years ago
<label class="form-check-label" :for=" 'notification' + notification.id">
{{ notification.name }}
<a href="#" @click="$refs.notificationDialog.show(notification.id)">Edit</a>
</label>
</div>
3 years ago
<button class="btn btn-primary me-2" type="button" @click="$refs.notificationDialog.show()">
Setup Notification
</button>
</div>
3 years ago
</div>
</div>
</form>
3 years ago
<NotificationDialog ref="notificationDialog" />
3 years ago
</template>
<script>
3 years ago
import NotificationDialog from "../components/NotificationDialog.vue";
3 years ago
import { useToast } from "vue-toastification"
3 years ago
const toast = useToast()
export default {
components: {
3 years ago
NotificationDialog,
3 years ago
},
data() {
return {
processing: false,
monitor: {
notificationIDList: {},
},
3 years ago
}
},
computed: {
pageName() {
return (this.isAdd) ? "Add New Monitor" : "Edit"
},
isAdd() {
return this.$route.path === "/add";
3 years ago
},
isEdit() {
return this.$route.path.startsWith("/edit");
3 years ago
},
},
watch: {
"$route.fullPath" () {
this.init();
},
},
mounted() {
this.init();
3 years ago
},
methods: {
3 years ago
init() {
if (this.isAdd) {
console.log("??????")
this.monitor = {
type: "http",
name: "",
url: "https://",
interval: 60,
maxretries: 0,
notificationIDList: {},
3 years ago
}
} 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)
}
})
}
},
3 years ago
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 {
3 years ago
this.$root.getSocket().emit("editMonitor", this.monitor, (res) => {
this.processing = false;
this.$root.toastRes(res)
})
3 years ago
}
3 years ago
},
3 years ago
},
3 years ago
}
</script>
<style scoped>
.shadow-box {
padding: 20px;
}
</style>