From 1d64f643b1835d390d40133c5fc5556f5465e9cb Mon Sep 17 00:00:00 2001 From: LouisLam Date: Thu, 1 Jul 2021 17:19:28 +0800 Subject: [PATCH] implement keyword monitor --- server/model/monitor.js | 18 ++++++++++++++++-- server/server.js | 1 + src/pages/Details.vue | 6 +++++- src/pages/EditMonitor.vue | 7 ++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 3b19d2ff1..919b8362c 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -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); diff --git a/server/server.js b/server/server.js index dd053ed25..2f15b68c4 100644 --- a/server/server.js +++ b/server/server.js @@ -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) diff --git a/src/pages/Details.vue b/src/pages/Details.vue index 764a3f559..0b031bfe6 100644 --- a/src/pages/Details.vue +++ b/src/pages/Details.vue @@ -1,9 +1,13 @@