diff --git a/Server/models/Check.js b/Server/models/Check.js index d57030202..7e46f418d 100644 --- a/Server/models/Check.js +++ b/Server/models/Check.js @@ -31,4 +31,21 @@ const CheckSchema = mongoose.Schema( } ); +CheckSchema.pre("save", async function (next) { + const monitor = await mongoose.model("Monitor").findById(this.monitorId); + + if (monitor.status === true && this.status === false) { + console.log("Monitor went down"); + } + + if (monitor.status === false && this.status === true) { + console.log("Monitor went up"); + } + + monitor.status = this.status; + await monitor.save(); + + next; +}); + module.exports = mongoose.model("Check", CheckSchema); diff --git a/Server/models/Monitor.js b/Server/models/Monitor.js index 8455aa312..4b3bd7c63 100644 --- a/Server/models/Monitor.js +++ b/Server/models/Monitor.js @@ -14,6 +14,10 @@ const MonitorSchema = mongoose.Schema( description: { type: String, }, + status: { + type: Boolean, + default: true, + }, type: { type: String, required: true,