mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-30 10:14:03 +00:00
implement keyword monitor
This commit is contained in:
parent
ef028794ac
commit
1d64f643b1
4 changed files with 28 additions and 4 deletions
|
@ -28,6 +28,7 @@ class Monitor extends BeanModel {
|
|||
active: this.active,
|
||||
type: this.type,
|
||||
interval: this.interval,
|
||||
keyword: this.keyword,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -57,12 +58,25 @@ class Monitor extends BeanModel {
|
|||
}
|
||||
|
||||
try {
|
||||
if (this.type === "http") {
|
||||
if (this.type === "http" || this.type === "keyword") {
|
||||
let startTime = dayjs().valueOf();
|
||||
let res = await axios.get(this.url)
|
||||
bean.msg = `${res.status} - ${res.statusText}`
|
||||
bean.ping = dayjs().valueOf() - startTime;
|
||||
bean.status = 1;
|
||||
|
||||
if (this.type === "http") {
|
||||
bean.status = 1;
|
||||
} else {
|
||||
|
||||
if (res.data.includes(this.keyword)) {
|
||||
bean.msg += ", keyword is found"
|
||||
bean.status = 1;
|
||||
} else {
|
||||
throw new Error(bean.msg + ", but keyword is not found")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else if (this.type === "port") {
|
||||
bean.ping = await tcping(this.hostname, this.port);
|
||||
|
|
|
@ -147,6 +147,7 @@ let monitorList = {};
|
|||
bean.interval = monitor.interval
|
||||
bean.hostname = monitor.hostname;
|
||||
bean.port = monitor.port;
|
||||
bean.keyword = monitor.keyword;
|
||||
|
||||
await R.store(bean)
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
<template>
|
||||
<h1> {{ monitor.name }}</h1>
|
||||
<p class="url">
|
||||
<a :href="monitor.url" target="_blank" v-if="monitor.type === 'http'">{{ monitor.url }}</a>
|
||||
<a :href="monitor.url" target="_blank" v-if="monitor.type === 'http' || monitor.type === 'keyword' ">{{ monitor.url }}</a>
|
||||
<span v-if="monitor.type === 'port'">TCP Ping {{ monitor.hostname }}:{{ monitor.port }}</span>
|
||||
<span v-if="monitor.type === 'ping'">Ping: {{ monitor.hostname }}</span>
|
||||
<span v-if="monitor.type === 'keyword'">
|
||||
<br />
|
||||
<span>Keyword:</span> <span style="color: black">{{ monitor.keyword }}</span>
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<div class="functions">
|
||||
|
|
|
@ -22,11 +22,16 @@
|
|||
<input type="text" class="form-control" id="name" v-model="monitor.name" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3" v-if="monitor.type === 'http' ">
|
||||
<div class="mb-3" v-if="monitor.type === 'http' || monitor.type === 'keyword' ">
|
||||
<label for="url" class="form-label">URL</label>
|
||||
<input type="url" class="form-control" id="url" v-model="monitor.url" pattern="https?://.+" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3" v-if="monitor.type === 'keyword' ">
|
||||
<label for="keyword" class="form-label">Keyword <span style="color: #AAA">(search keyword in plain html response)</span></label>
|
||||
<input type="text" class="form-control" id="keyword" v-model="monitor.keyword" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3" v-if="monitor.type === 'port' || monitor.type === 'ping' ">
|
||||
<label for="hostname" class="form-label">Hostname</label>
|
||||
<input type="text" class="form-control" id="hostname" v-model="monitor.hostname" required>
|
||||
|
|
Loading…
Reference in a new issue