diff --git a/server/model/monitor.js b/server/model/monitor.js index b2fed86f57..b1b0232c3c 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -383,6 +383,8 @@ class Monitor extends BeanModel { bean.msg = "Monitor under maintenance"; bean.status = MAINTENANCE; } else if (this.type === "group") { + let downChildName = ""; + let failureCount = 0; const children = await Monitor.getChildren(this.id); if (children.length > 0) { @@ -395,19 +397,28 @@ 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; + downChildName = child.name; } else if (bean.status === PENDING && lastBeat.status === DOWN) { bean.status = lastBeat.status; + downChildName = child.name; + } + if (lastBeat.status === DOWN) { + failureCount++; } } if (bean.status !== UP) { - bean.msg = "Child inaccessible"; + if (failureCount <= 1) { + bean.msg = `Child '${downChildName}' inaccessible`; + } else { + bean.msg = `Child '${downChildName}' and ${failureCount - 1} others inaccessible`; + } } } else { // Set status pending if group is empty @@ -971,7 +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 { - 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 groupText = ""; + if (this.type !== "group" && this.parent !== "") { + let parentName = await this.getParentName(); + groupText = ` under group '${parentName}'`; + } + + 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 @@ -1526,6 +1543,19 @@ class Monitor extends BeanModel { ]); } + /** + * Gets Parent name + * @returns {Promise} Name of this monitor's parent + */ + async getParentName() { + if (this.parent === null) { + return ""; + } + + let parent = await Monitor.getParent(this.id); + return parent.name; + } + /** * Gets Full Path-Name (Groups and Name) * @returns {Promise} Full path name of this monitor