Skip to content

Commit

Permalink
Add basic way to guess check type from url
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Apr 10, 2012
1 parent d390e3c commit 1f847d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/dashboard/app.js
Expand Up @@ -43,6 +43,7 @@ app.post('/check', function(req, res) {
var check = new Check(req.body.check);
check.tags = Check.convertTags(req.body.check.tags);
check.interval = req.body.check.interval * 1000;
check.type = Check.guessType(check.url);
check.save(function(err) {
req.flash('info', 'New check has been created');
res.redirect('/check/' + check._id);
Expand All @@ -61,6 +62,7 @@ app.put('/check/:id', function(req, res, next) {
var check = req.body.check;
check.tags = Check.convertTags(check.tags);
check.interval = req.body.check.interval * 1000;
check.type = Check.guessType(check.url);
Check.update({ _id: req.params.id }, { $set: check }, { upsert: true }, function(err) {
if (err) return next(err);
req.flash('info', 'Changes have been saved');
Expand Down
10 changes: 10 additions & 0 deletions models/check.js
Expand Up @@ -13,6 +13,7 @@ var CheckMonthlyStat = require('../models/checkMonthlyStat');
// main model
var Check = new Schema({
name : String
, type : String
, url : String
, interval : { type: Number, default: 60000 } // interval between two pings
, maxTime : { type: Number, default: 1500 } // time under which a ping is considered responsive
Expand Down Expand Up @@ -231,6 +232,15 @@ Check.statics.convertTags = function(tags) {
return tags;
}

Check.statics.guessType = function(url) {
if (url.search(/^http:\/\//) != -1) {
return 'http';
}
if (url.search(/^https:\/\//) != -1) {
return 'https';
}
}

/**
* Calls a function for all checks that need to be polled.
*
Expand Down

0 comments on commit 1f847d2

Please sign in to comment.