Merge branch 'louislam:master' into master

This commit is contained in:
Philipp Dormann 2021-07-12 12:01:00 +02:00 committed by GitHub
commit 763d7f2683
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 6 deletions

View File

@ -42,7 +42,7 @@ npm run setup
# Option 1. Try it # Option 1. Try it
npm run start-server npm run start-server
# (Recommanded) # (Recommended)
# Option 2. Run in background using PM2 # Option 2. Run in background using PM2
# Install PM2 if you don't have: npm install pm2 -g # Install PM2 if you don't have: npm install pm2 -g
pm2 start npm --name uptime-kuma -- run start-server pm2 start npm --name uptime-kuma -- run start-server

View File

@ -71,7 +71,9 @@ class Monitor extends BeanModel {
try { try {
if (this.type === "http" || this.type === "keyword") { if (this.type === "http" || this.type === "keyword") {
let startTime = dayjs().valueOf(); let startTime = dayjs().valueOf();
let res = await axios.get(this.url) let res = await axios.get(this.url, {
headers: { 'User-Agent':'Uptime-Kuma' }
})
bean.msg = `${res.status} - ${res.statusText}` bean.msg = `${res.status} - ${res.statusText}`
bean.ping = dayjs().valueOf() - startTime; bean.ping = dayjs().valueOf() - startTime;
@ -79,7 +81,14 @@ class Monitor extends BeanModel {
bean.status = 1; bean.status = 1;
} else { } else {
if (res.data.includes(this.keyword)) { let data = res.data;
// Convert to string for object/array
if (typeof data !== "string") {
data = JSON.stringify(data)
}
if (data.includes(this.keyword)) {
bean.msg += ", keyword is found" bean.msg += ", keyword is found"
bean.status = 1; bean.status = 1;
} else { } else {

View File

@ -137,7 +137,7 @@ export default {
}, },
ping() { ping() {
if (this.lastHeartBeat.ping) { if (this.lastHeartBeat.ping || this.lastHeartBeat.ping === 0) {
return this.lastHeartBeat.ping; return this.lastHeartBeat.ping;
} else { } else {
return "N/A" return "N/A"
@ -145,7 +145,7 @@ export default {
}, },
avgPing() { avgPing() {
if (this.$root.avgPingList[this.monitor.id]) { if (this.$root.avgPingList[this.monitor.id] || this.$root.avgPingList[this.monitor.id] === 0) {
return this.$root.avgPingList[this.monitor.id]; return this.$root.avgPingList[this.monitor.id];
} else { } else {
return "N/A" return "N/A"

View File

@ -30,7 +30,7 @@
<div class="mb-3" v-if="monitor.type === 'keyword' "> <div class="mb-3" v-if="monitor.type === 'keyword' ">
<label for="keyword" class="form-label">Keyword</label> <label for="keyword" class="form-label">Keyword</label>
<input type="text" class="form-control" id="keyword" v-model="monitor.keyword" required> <input type="text" class="form-control" id="keyword" v-model="monitor.keyword" required>
<div class="form-text">Search keyword in plain html response and it is case-sensitive</div> <div class="form-text">Search keyword in plain html or JSON response and it is case-sensitive</div>
</div> </div>
<div class="mb-3" v-if="monitor.type === 'port' || monitor.type === 'ping' "> <div class="mb-3" v-if="monitor.type === 'port' || monitor.type === 'ping' ">