Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding alert threshold

  • Loading branch information...
commit 7b91d259b72006d9db8fef24056e024067cb8908 1 parent 4d572cc
@greggythefly greggythefly authored committed
Showing with 19 additions and 17 deletions.
  1. +19 −17 models/check.js
View
36 models/check.js
@@ -12,8 +12,6 @@ var CheckMonthlyStat = require('../models/checkMonthlyStat');
var CheckYearlyStat = require('../models/checkYearlyStat');
var Tag = require('../models/tag');
-var statusCounter = 0;
-
// main model
var Check = new Schema({
name : String,
@@ -22,6 +20,7 @@ var Check = new Schema({
interval : { type: Number, default: 60000 }, // interval between two pings
maxTime : { type: Number, default: 1500 }, // time under which a ping is considered responsive
nbErrors : { type: Number, default: 1 }, // nb of errors from which to trigger a new CheckEvent
+ statusCounter : { type: Number, default: 4 }, // nb of errors from which to trigger a new CheckEvent
tags : [String],
lastChanged : Date,
firstTested : Date,
@@ -81,19 +80,26 @@ Check.methods.setLastTest = function(status, time, error) {
}
this.lastTested = now;
- // First down check or First up check
- if (this.isUp != status) {
-
- statusCounter = 1;
-
- // more up checks
- } else {
-
- statusCounter++;
-
+
+ if (!status && this.isUp != status) {
+ this.statusCounter = 1;
+ } else if(status && this.isUp != status && this.statusCounter >= this.nbErrors) {
+ this.statusCounter = this.nbErrors;
+ } else if(!status && this.statusCounter<(this.nbErrors+1)) {
+ this.statusCounter++;
}
+
+ if (this.isUp != status) {
+
+ this.lastChanged = now;
+ this.isUp = status;
+ this.uptime = 0;
+ this.downtime = 0;
+
+ }
- if (statusCounter>2) {
+ if(this.statusCounter == this.nbErrors) {
+ this.statusCounter = this.nbErrors + 1;
var event = new CheckEvent({
timestamp: now,
check: this,
@@ -106,10 +112,6 @@ Check.methods.setLastTest = function(status, time, error) {
event.downtime = now.getTime() - this.lastChanged.getTime();
}
event.save();
- this.lastChanged = now;
- this.isUp = status;
- this.uptime = 0;
- this.downtime = 0;
}
var durationSinceLastChange = now.getTime() - this.lastChanged.getTime();
if (status) {
Please sign in to comment.
Something went wrong with that request. Please try again.