-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f7968c
commit 7208e06
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var config = require('config').mongodb; | ||
var mongoose = require('mongoose'); | ||
var Schema = mongoose.Schema; | ||
|
||
var CheckEvent = new Schema({ | ||
timestamp : { type: Date, default: Date.now }, | ||
check : { type: Schema.ObjectId, ref: 'Check' }, | ||
tags : [String], | ||
message : String, | ||
isGoDown : Boolean, | ||
details : String, | ||
// for error events, more details need to be persisted | ||
downtime : Number | ||
}); | ||
|
||
mongoose.model('CheckEvent', CheckEvent); | ||
|
||
mongoose.connect('mongodb://' + config.user + ':' + config.password + '@' + config.server +'/' + config.database); | ||
mongoose.connection.on('error', function (err) { | ||
console.error('MongoDB error: ' + err.message); | ||
console.error('Make sure a mongoDB server is running and accessible by this application') | ||
}); | ||
|
||
var Event = mongoose.model('CheckEvent'); | ||
Event.find({ message: { $exists: false }}).each(function(err, event) { | ||
if (err) { | ||
console.log(err.message); | ||
return; | ||
} | ||
if (!event) process.exit(); | ||
event.message = event.isGoDown ? 'down' : 'up'; | ||
event.save(); | ||
}) |