From 78ef79fcd9d87b33d822c609c065c785fc98cd20 Mon Sep 17 00:00:00 2001 From: kerry <48721345+homeautomaton@users.noreply.github.com> Date: Mon, 15 Jan 2024 08:24:30 -0600 Subject: [PATCH 1/6] Resolves #3278 - put child name in notification, also added count of add'l children --- server/model/monitor.js | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index b2fed86f57..7b0a619979 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -50,7 +50,7 @@ class Monitor extends BeanModel { id: this.id, name: this.name, sendUrl: this.sendUrl, - type: this.type, + type: this.type }; if (this.sendUrl) { @@ -383,6 +383,8 @@ class Monitor extends BeanModel { bean.msg = "Monitor under maintenance"; bean.status = MAINTENANCE; } else if (this.type === "group") { + let fail_child = ""; + let fail_count = 0; const children = await Monitor.getChildren(this.id); if (children.length > 0) { @@ -395,19 +397,26 @@ class Monitor extends BeanModel { } const lastBeat = await Monitor.getPreviousHeartbeat(child.id); - // Only change state if the monitor is in worse conditions then the ones before + // Only change state if the monitor is in worse conditions than the ones before // lastBeat.status could be null if (!lastBeat) { bean.status = PENDING; } else if (bean.status === UP && (lastBeat.status === PENDING || lastBeat.status === DOWN)) { bean.status = lastBeat.status; + fail_child = child.name; } else if (bean.status === PENDING && lastBeat.status === DOWN) { bean.status = lastBeat.status; + fail_child = child.name; } + if (lastBeat.status == DOWN) fail_count++; } if (bean.status !== UP) { - bean.msg = "Child inaccessible"; + if (fail_count <= 1) { + bean.msg = "Child '" + fail_child + "' inaccessible"; + } else { + bean.msg = "Child '" + fail_child + "' and " + (fail_count-1) + " others inaccessible"; + } } } else { // Set status pending if group is empty @@ -971,7 +980,13 @@ class Monitor extends BeanModel { } else if (bean.status === MAINTENANCE) { log.warn("monitor", `Monitor #${this.id} '${this.name}': Under Maintenance | Type: ${this.type}`); } else { - log.warn("monitor", `Monitor #${this.id} '${this.name}': Failing: ${bean.msg} | Interval: ${beatInterval} seconds | Type: ${this.type} | Down Count: ${bean.downCount} | Resend Interval: ${this.resendInterval}`); + let group_text = ''; + if (this.type != 'group' && this.parent != '') { + let parentName = await this.getParentName(); + group_text = ` under group '${parentName}'`; + } + + log.warn("monitor", `Monitor #${this.id} '${this.name}'${group_text}: Failing: ${bean.msg} | Interval: ${beatInterval} seconds | Type: ${this.type} | Down Count: ${bean.downCount} | Resend Interval: ${this.resendInterval}`); } // Calculate uptime @@ -1526,6 +1541,24 @@ class Monitor extends BeanModel { ]); } + /** + * Gets Parent name + * @returns {Promise} Name of this monitor's parent + */ + async getParentName() { + let name = ''; + + if (this.parent === null) { + return name; + } + + let parent = await Monitor.getParent(this.id); + name = `${parent.name}`; + + return name; + } + + /** * Gets Full Path-Name (Groups and Name) * @returns {Promise} Full path name of this monitor From 4e9afcf3577c5220f6c13df09589ea21033a93b4 Mon Sep 17 00:00:00 2001 From: kerry <48721345+homeautomaton@users.noreply.github.com> Date: Mon, 15 Jan 2024 08:40:00 -0600 Subject: [PATCH 2/6] eslint-recommended fixes --- server/model/monitor.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 7b0a619979..7f76bfd50e 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -383,8 +383,8 @@ class Monitor extends BeanModel { bean.msg = "Monitor under maintenance"; bean.status = MAINTENANCE; } else if (this.type === "group") { - let fail_child = ""; - let fail_count = 0; + let failChild = ""; + let failCount = 0; const children = await Monitor.getChildren(this.id); if (children.length > 0) { @@ -403,19 +403,21 @@ class Monitor extends BeanModel { bean.status = PENDING; } else if (bean.status === UP && (lastBeat.status === PENDING || lastBeat.status === DOWN)) { bean.status = lastBeat.status; - fail_child = child.name; + failChild = child.name; } else if (bean.status === PENDING && lastBeat.status === DOWN) { bean.status = lastBeat.status; - fail_child = child.name; + failChild = child.name; + } + if (lastBeat.status === DOWN) { + failCount++; } - if (lastBeat.status == DOWN) fail_count++; } if (bean.status !== UP) { - if (fail_count <= 1) { - bean.msg = "Child '" + fail_child + "' inaccessible"; + if (failCount <= 1) { + bean.msg = "Child '" + failChild + "' inaccessible"; } else { - bean.msg = "Child '" + fail_child + "' and " + (fail_count-1) + " others inaccessible"; + bean.msg = "Child '" + failChild + "' and " + (failCount - 1) + " others inaccessible"; } } } else { @@ -980,13 +982,13 @@ class Monitor extends BeanModel { } else if (bean.status === MAINTENANCE) { log.warn("monitor", `Monitor #${this.id} '${this.name}': Under Maintenance | Type: ${this.type}`); } else { - let group_text = ''; - if (this.type != 'group' && this.parent != '') { + let groupText = ""; + if (this.type !== "group" && this.parent !== "") { let parentName = await this.getParentName(); - group_text = ` under group '${parentName}'`; + groupText = ` under group '${parentName}'`; } - - log.warn("monitor", `Monitor #${this.id} '${this.name}'${group_text}: Failing: ${bean.msg} | Interval: ${beatInterval} seconds | Type: ${this.type} | Down Count: ${bean.downCount} | Resend Interval: ${this.resendInterval}`); + + log.warn("monitor", `Monitor #${this.id} '${this.name}'${groupText}: Failing: ${bean.msg} | Interval: ${beatInterval} seconds | Type: ${this.type} | Down Count: ${bean.downCount} | Resend Interval: ${this.resendInterval}`); } // Calculate uptime @@ -1546,7 +1548,7 @@ class Monitor extends BeanModel { * @returns {Promise} Name of this monitor's parent */ async getParentName() { - let name = ''; + let name = ""; if (this.parent === null) { return name; @@ -1558,7 +1560,6 @@ class Monitor extends BeanModel { return name; } - /** * Gets Full Path-Name (Groups and Name) * @returns {Promise} Full path name of this monitor From 59d5148c169e740f4a993a6ace68667b55e0aa4f Mon Sep 17 00:00:00 2001 From: homeautomaton <48721345+homeautomaton@users.noreply.github.com> Date: Mon, 15 Jan 2024 12:17:17 -0600 Subject: [PATCH 3/6] Update server/model/monitor.js Co-authored-by: Frank Elsinga --- server/model/monitor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 7f76bfd50e..c47cc57fdf 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -50,7 +50,7 @@ class Monitor extends BeanModel { id: this.id, name: this.name, sendUrl: this.sendUrl, - type: this.type + type: this.type, }; if (this.sendUrl) { From a1fbc6f7ca1ef42da60915d4e0fa1d7ff0941676 Mon Sep 17 00:00:00 2001 From: homeautomaton <48721345+homeautomaton@users.noreply.github.com> Date: Mon, 15 Jan 2024 12:17:29 -0600 Subject: [PATCH 4/6] Update server/model/monitor.js Co-authored-by: Frank Elsinga --- server/model/monitor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index c47cc57fdf..c9225dbc6f 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -415,9 +415,9 @@ class Monitor extends BeanModel { if (bean.status !== UP) { if (failCount <= 1) { - bean.msg = "Child '" + failChild + "' inaccessible"; + bean.msg = `Child '${failChild}' inaccessible`; } else { - bean.msg = "Child '" + failChild + "' and " + (failCount - 1) + " others inaccessible"; + bean.msg = `Child '${failChild}' and ${failCount - 1} others inaccessible`; } } } else { From 63a41cf44179fff01d56d275eadc615a34f90034 Mon Sep 17 00:00:00 2001 From: homeautomaton <48721345+homeautomaton@users.noreply.github.com> Date: Mon, 15 Jan 2024 12:48:20 -0600 Subject: [PATCH 5/6] Update server/model/monitor.js suggestion accepted Co-authored-by: Frank Elsinga --- server/model/monitor.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index c9225dbc6f..73ee3b45fb 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -1548,16 +1548,12 @@ class Monitor extends BeanModel { * @returns {Promise} Name of this monitor's parent */ async getParentName() { - let name = ""; - if (this.parent === null) { - return name; + return ""; } let parent = await Monitor.getParent(this.id); - name = `${parent.name}`; - - return name; + return parent.name; } /** From d3791571533c2e9f5f3dc8c2916e095c430f3952 Mon Sep 17 00:00:00 2001 From: kerry <48721345+homeautomaton@users.noreply.github.com> Date: Mon, 15 Jan 2024 12:49:45 -0600 Subject: [PATCH 6/6] variable name changes --- server/model/monitor.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 73ee3b45fb..b1b0232c3c 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -383,8 +383,8 @@ class Monitor extends BeanModel { bean.msg = "Monitor under maintenance"; bean.status = MAINTENANCE; } else if (this.type === "group") { - let failChild = ""; - let failCount = 0; + let downChildName = ""; + let failureCount = 0; const children = await Monitor.getChildren(this.id); if (children.length > 0) { @@ -403,21 +403,21 @@ class Monitor extends BeanModel { bean.status = PENDING; } else if (bean.status === UP && (lastBeat.status === PENDING || lastBeat.status === DOWN)) { bean.status = lastBeat.status; - failChild = child.name; + downChildName = child.name; } else if (bean.status === PENDING && lastBeat.status === DOWN) { bean.status = lastBeat.status; - failChild = child.name; + downChildName = child.name; } if (lastBeat.status === DOWN) { - failCount++; + failureCount++; } } if (bean.status !== UP) { - if (failCount <= 1) { - bean.msg = `Child '${failChild}' inaccessible`; + if (failureCount <= 1) { + bean.msg = `Child '${downChildName}' inaccessible`; } else { - bean.msg = `Child '${failChild}' and ${failCount - 1} others inaccessible`; + bean.msg = `Child '${downChildName}' and ${failureCount - 1} others inaccessible`; } } } else {