Skip to content

Commit

Permalink
adding alert threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
greggythefly authored and fzaninotto committed Jan 20, 2013
1 parent 4d572cc commit 7b91d25
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions models/check.js
Expand Up @@ -12,8 +12,6 @@ var CheckMonthlyStat = require('../models/checkMonthlyStat');
var CheckYearlyStat = require('../models/checkYearlyStat'); var CheckYearlyStat = require('../models/checkYearlyStat');
var Tag = require('../models/tag'); var Tag = require('../models/tag');


var statusCounter = 0;

// main model // main model
var Check = new Schema({ var Check = new Schema({
name : String, name : String,
Expand All @@ -22,6 +20,7 @@ var Check = new Schema({
interval : { type: Number, default: 60000 }, // interval between two pings interval : { type: Number, default: 60000 }, // interval between two pings
maxTime : { type: Number, default: 1500 }, // time under which a ping is considered responsive 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 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], tags : [String],
lastChanged : Date, lastChanged : Date,
firstTested : Date, firstTested : Date,
Expand Down Expand Up @@ -81,19 +80,26 @@ Check.methods.setLastTest = function(status, time, error) {
} }
this.lastTested = now; this.lastTested = now;


// First down check or First up check
if (this.isUp != status) { if (!status && this.isUp != status) {

this.statusCounter = 1;
statusCounter = 1; } else if(status && this.isUp != status && this.statusCounter >= this.nbErrors) {

this.statusCounter = this.nbErrors;
// more up checks } else if(!status && this.statusCounter<(this.nbErrors+1)) {
} else { this.statusCounter++;

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({ var event = new CheckEvent({
timestamp: now, timestamp: now,
check: this, check: this,
Expand All @@ -106,10 +112,6 @@ Check.methods.setLastTest = function(status, time, error) {
event.downtime = now.getTime() - this.lastChanged.getTime(); event.downtime = now.getTime() - this.lastChanged.getTime();
} }
event.save(); event.save();
this.lastChanged = now;
this.isUp = status;
this.uptime = 0;
this.downtime = 0;
} }
var durationSinceLastChange = now.getTime() - this.lastChanged.getTime(); var durationSinceLastChange = now.getTime() - this.lastChanged.getTime();
if (status) { if (status) {
Expand Down

0 comments on commit 7b91d25

Please sign in to comment.