From f84f7aca7515516964b6757ac993ad35f6c23e77 Mon Sep 17 00:00:00 2001 From: TheGuyDanish <5776313+TheGuyDanish@users.noreply.github.com> Date: Sun, 11 Jul 2021 21:01:34 +0100 Subject: [PATCH 1/4] Introduce custom user agent. Fixes #5 Quick and easy fix. Could be improved by adding a version number as well. Like `Uptime-Kuma/0.0.1`, for example. --- server/model/monitor.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 2735c378f..b8e8eb30c 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -71,7 +71,9 @@ class Monitor extends BeanModel { try { if (this.type === "http" || this.type === "keyword") { 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.ping = dayjs().valueOf() - startTime; From a9d19ae06ad5bec0b2a90ebf4ba729987cec7118 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Mon, 12 Jul 2021 10:52:41 +0800 Subject: [PATCH 2/4] support json for keyword type --- server/model/monitor.js | 9 ++++++++- src/pages/EditMonitor.vue | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index b8e8eb30c..162772875 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -81,7 +81,14 @@ class Monitor extends BeanModel { bean.status = 1; } 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.status = 1; } else { diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 7054d73ac..01af50610 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -30,7 +30,7 @@
-
Search keyword in plain html response and it is case-sensitive
+
Search keyword in plain html or JSON response and it is case-sensitive
From 56fcfc9369a4f57b4c593d440ce30bbaefb8992c Mon Sep 17 00:00:00 2001 From: LouisLam Date: Mon, 12 Jul 2021 11:20:18 +0800 Subject: [PATCH 3/4] fix show N/A if the ping is 0ms --- src/pages/Details.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/Details.vue b/src/pages/Details.vue index 0b031bfe6..f925c2849 100644 --- a/src/pages/Details.vue +++ b/src/pages/Details.vue @@ -137,7 +137,7 @@ export default { }, ping() { - if (this.lastHeartBeat.ping) { + if (this.lastHeartBeat.ping || this.lastHeartBeat.ping === 0) { return this.lastHeartBeat.ping; } else { return "N/A" @@ -145,7 +145,7 @@ export default { }, 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]; } else { return "N/A" From c436ef4e054c5647c89a602dbb8a7afebf62ee9d Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Mon, 12 Jul 2021 11:42:36 +0800 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b09048d74..31589e99f 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ npm run setup # Option 1. Try it npm run start-server -# (Recommanded) +# (Recommended) # Option 2. Run in background using PM2 # Install PM2 if you don't have: npm install pm2 -g pm2 start npm --name uptime-kuma -- run start-server