Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convert tab based identation to a 2 spaces based one.

  • Loading branch information...
commit 5d92b9f510b077367cd45ffdb47ad236bd9a3a9a 1 parent bd1795a
@iloire authored
View
16 config/general.js
@@ -1,10 +1,10 @@
module.exports = {
- 'notifications' : {
- enabled: false, //if disabled, no notifications will be sent
- to: ['ivan@iloire.com'], //default notification list if no alert_to is specified for host or url
- postmark : {
- from: 'ivan@iloire.com',
- api_key : 'your-postmark-key-here'
- }
- }
+ 'notifications' : {
+ enabled: false, //if disabled, no notifications will be sent
+ to: ['ivan@iloire.com'], //default notification list if no alert_to is specified for host or url
+ postmark : {
+ from: 'ivan@iloire.com',
+ api_key : 'your-postmark-key-here'
+ }
+ }
};
View
842 config/hosts.js
@@ -3,425 +3,425 @@ var one_tick = 20; //seconds
//service name must be unique for a certain host.
//host name must be unique
module.exports =
- [
- {
- name: 'iloire smtp',
- host: 'mail.iloire.com',
- port: 25,
- ping_service_name: 'smtp',
- timeout:10000,
- ping_interval: one_tick, //seconds
- failed_ping_interval: one_tick / 3, //minutes
- enabled: true,
- alert_to: ['ivan@iloire.com'],
- warning_if_takes_more_than: 1500, //miliseconds
- services : [
- {
- name: 'mail server'
- }
- ]
- } ,
+ [
+ {
+ name: 'iloire smtp',
+ host: 'mail.iloire.com',
+ port: 25,
+ ping_service_name: 'smtp',
+ timeout:10000,
+ ping_interval: one_tick, //seconds
+ failed_ping_interval: one_tick / 3, //minutes
+ enabled: true,
+ alert_to: ['ivan@iloire.com'],
+ warning_if_takes_more_than: 1500, //miliseconds
+ services : [
+ {
+ name: 'mail server'
+ }
+ ]
+ } ,
- {
- name:'Apple HTTPS',
- host: 'www.apple.com',
- port:443,
- protocol: 'https',
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick, //seconds
- failed_ping_interval: one_tick / 3, //minutes
- enabled: true,
- alert_to: ['ivan@iloire.com'],
- warning_if_takes_more_than: 1500, //miliseconds
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'Apple Inc'}
- }
- ]
- } ,
- {
- name:'VitaminasDev',
- host: 'www.vitaminasdev.com',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick, //seconds
- failed_ping_interval: one_tick / 3, //minutes
- enabled: true,
- alert_to: ['ivan@iloire.com'],
- warning_if_takes_more_than: 1500, //miliseconds
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'noticias'}
- },
- {
- name: 'contact page',
- method: 'get',
- url : '/Home/Contacto',
- expected: {statuscode: 200, contains: 'encantados'},
- ping_interval:200, //overwrite ping and retry intervals for this url
- failed_ping_interval: one_tick / 3
- }
- ]
- } ,
- {
- name:'iloire.com',
- host: 'www.iloire.com',
- port:80,
- ping_service_name: 'http',
- timeout:5000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- warning_if_takes_more_than: 1500, //miliseconds
- enabled: true,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'vitaminas'}
- },
- {
- name: 'english version',
- method: 'get',
- url : '/en',
- expected: {statuscode: 200, contains: 'Freelance'}
- }
- ]
- } ,
- {
- name:'ASP Photo Gallery',
- host: 'www.aspphotogallery.net',
- port:80,
- ping_service_name: 'http',
- timeout:5000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- warning_if_takes_more_than: 1300, //miliseconds
- enabled: true,
- alert_to: ['ajax@aspphotogallery.net'], //you can include a different email recipient per host
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 302}
- },
- {
- name: 'mvcphotogallery',
- method: 'get',
- url : '/mvcphotogallery',
- warning_if_takes_more_than: 800,
- expected: {statuscode: 200, contains: 'Knockout'}
- },
- {
- name: 'demomvc',
- method: 'get',
- enabled: true,
- url : '/demomvc',
- expected: {statuscode: 200, contains: 'Simple, sexy, FAST, ASP.NET MVC photo gallery'}
- }
- ]
- } ,
- {
- name:'CachiruloValley',
- host: 'cachirulovalley.com',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- warning_if_takes_more_than: 3000, //miliseconds
- enabled: true,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: ''}
- }
- ]
- } ,
- {
- name:'Directorio CachiruloValley',
- host: 'directorio.cachirulovalley.com',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: 3 * one_tick,
- failed_ping_interval: one_tick / 3,
- warning_if_takes_more_than: 3000, //miliseconds
- enabled: true,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: ''}
- } ,
- {
- name: 'directory',
- method: 'get',
- url : '/directory',
- expected: {statuscode: 200, contains: ''}
- }
- ]
- } ,
- {
- name:'letsnode.com',
- host: 'letsnode.com',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- enabled: true,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'A blog about node.js and express.js'}
- }
- ]
- } ,
- {
- name:'letsnode.com frelancer service',
- host: 'letsnode.com',
- port:8080,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- enabled: false,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'journey'}
- }
- ]
- } ,
- {
- name:'mathrace demo',
- host: 'letsnode.com',
- port:8090,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- enabled: true,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'Race'}
- }
- ]
- } ,
- {
- name:'google.com',
- host: 'www.google.com',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- enabled: false,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 302, contains: ''}
- }
- ]
- } ,
- {
- name:'localhost test',
- host: '127.0.0.1',
- port:8080,
- ping_service_name: 'http',
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- alert_to: ['ivan@iloire.com'],
- enabled: false,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: ''}
- }
- ]
- } ,
- {
- name:'Idibay direct',
- host: 'direct.idibay.com',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- warning_if_takes_more_than: 4000, //miliseconds
- enabled: true,
- alert_to:['ivan@iloire.com'],
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'Mundo Idibay'}
- }
- ]
- } ,
- {
- name:'Idibay',
- host: 'www.idibay.com',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- warning_if_takes_more_than: 4000, //miliseconds
- enabled: true,
- alert_to:['ivan@iloire.com'],
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'Mundo Idibay'}
- }
- ]
- } ,
- {
- name:'Cuéntica',
- host: 'www.cuentica.com',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- enabled: true,
- warning_if_takes_more_than: 1500, //miliseconds
- alert_to:['ivan@iloire.com'],
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'Cuéntica'}
- }
- ]
- } ,
- {
- name:'form post test',
- host: 'hroch486.icpf.cas.cz',
- port:80,
- ping_service_name: 'http',
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- enabled: true,
- services : [
- {
- name: 'post',
- method: 'get',
- url : '/formpost.html',
- expected: {statuscode: 200, contains: 'Test Form -- POST method'}
- },
- {
- name: 'post with data',
- method: 'post',
- input_data : 'your_name=Ivan&fruit=Banana',
- content_type : 'application/x-www-form-urlencoded', // application/json
- url : '/cgi-bin/echo.pl',
- expected: {statuscode: 200, contains: 'your_name = Ivan'}
- }
- ]
- } ,
- {
- name:'Menéame',
- host: 'www.meneame.net',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- warning_if_takes_more_than: 2000,
- enabled: true,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'Menéame'}
- }
- ]
- } ,
- {
- name:'node js',
- host: 'nodejs.org',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- warning_if_takes_more_than: 1500,
- enabled: true,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'Node'}
- }
- ]
- } ,
- {
- name:'redis',
- host: 'redis.io',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- warning_if_takes_more_than: 1500,
- enabled: true,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'Redis'}
- }
- ]
- } ,
- {
- name:'express',
- host: 'expressjs.com',
- port:80,
- ping_service_name: 'http',
- timeout:10000,
- ping_interval: one_tick,
- failed_ping_interval: one_tick / 3,
- enabled: true,
- services : [
- {
- name: 'home',
- method: 'get',
- url : '/',
- expected: {statuscode: 200, contains: 'web application framework'}
- }
- ]
- }
- ];
+ {
+ name:'Apple HTTPS',
+ host: 'www.apple.com',
+ port:443,
+ protocol: 'https',
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick, //seconds
+ failed_ping_interval: one_tick / 3, //minutes
+ enabled: true,
+ alert_to: ['ivan@iloire.com'],
+ warning_if_takes_more_than: 1500, //miliseconds
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'Apple Inc'}
+ }
+ ]
+ } ,
+ {
+ name:'VitaminasDev',
+ host: 'www.vitaminasdev.com',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick, //seconds
+ failed_ping_interval: one_tick / 3, //minutes
+ enabled: true,
+ alert_to: ['ivan@iloire.com'],
+ warning_if_takes_more_than: 1500, //miliseconds
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'noticias'}
+ },
+ {
+ name: 'contact page',
+ method: 'get',
+ url : '/Home/Contacto',
+ expected: {statuscode: 200, contains: 'encantados'},
+ ping_interval:200, //overwrite ping and retry intervals for this url
+ failed_ping_interval: one_tick / 3
+ }
+ ]
+ } ,
+ {
+ name:'iloire.com',
+ host: 'www.iloire.com',
+ port:80,
+ ping_service_name: 'http',
+ timeout:5000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ warning_if_takes_more_than: 1500, //miliseconds
+ enabled: true,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'vitaminas'}
+ },
+ {
+ name: 'english version',
+ method: 'get',
+ url : '/en',
+ expected: {statuscode: 200, contains: 'Freelance'}
+ }
+ ]
+ } ,
+ {
+ name:'ASP Photo Gallery',
+ host: 'www.aspphotogallery.net',
+ port:80,
+ ping_service_name: 'http',
+ timeout:5000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ warning_if_takes_more_than: 1300, //miliseconds
+ enabled: true,
+ alert_to: ['ajax@aspphotogallery.net'], //you can include a different email recipient per host
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 302}
+ },
+ {
+ name: 'mvcphotogallery',
+ method: 'get',
+ url : '/mvcphotogallery',
+ warning_if_takes_more_than: 800,
+ expected: {statuscode: 200, contains: 'Knockout'}
+ },
+ {
+ name: 'demomvc',
+ method: 'get',
+ enabled: true,
+ url : '/demomvc',
+ expected: {statuscode: 200, contains: 'Simple, sexy, FAST, ASP.NET MVC photo gallery'}
+ }
+ ]
+ } ,
+ {
+ name:'CachiruloValley',
+ host: 'cachirulovalley.com',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ warning_if_takes_more_than: 3000, //miliseconds
+ enabled: true,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: ''}
+ }
+ ]
+ } ,
+ {
+ name:'Directorio CachiruloValley',
+ host: 'directorio.cachirulovalley.com',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: 3 * one_tick,
+ failed_ping_interval: one_tick / 3,
+ warning_if_takes_more_than: 3000, //miliseconds
+ enabled: true,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: ''}
+ } ,
+ {
+ name: 'directory',
+ method: 'get',
+ url : '/directory',
+ expected: {statuscode: 200, contains: ''}
+ }
+ ]
+ } ,
+ {
+ name:'letsnode.com',
+ host: 'letsnode.com',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ enabled: true,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'A blog about node.js and express.js'}
+ }
+ ]
+ } ,
+ {
+ name:'letsnode.com frelancer service',
+ host: 'letsnode.com',
+ port:8080,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ enabled: false,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'journey'}
+ }
+ ]
+ } ,
+ {
+ name:'mathrace demo',
+ host: 'letsnode.com',
+ port:8090,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ enabled: true,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'Race'}
+ }
+ ]
+ } ,
+ {
+ name:'google.com',
+ host: 'www.google.com',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ enabled: false,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 302, contains: ''}
+ }
+ ]
+ } ,
+ {
+ name:'localhost test',
+ host: '127.0.0.1',
+ port:8080,
+ ping_service_name: 'http',
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ alert_to: ['ivan@iloire.com'],
+ enabled: false,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: ''}
+ }
+ ]
+ } ,
+ {
+ name:'Idibay direct',
+ host: 'direct.idibay.com',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ warning_if_takes_more_than: 4000, //miliseconds
+ enabled: true,
+ alert_to:['ivan@iloire.com'],
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'Mundo Idibay'}
+ }
+ ]
+ } ,
+ {
+ name:'Idibay',
+ host: 'www.idibay.com',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ warning_if_takes_more_than: 4000, //miliseconds
+ enabled: true,
+ alert_to:['ivan@iloire.com'],
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'Mundo Idibay'}
+ }
+ ]
+ } ,
+ {
+ name:'Cuéntica',
+ host: 'www.cuentica.com',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ enabled: true,
+ warning_if_takes_more_than: 1500, //miliseconds
+ alert_to:['ivan@iloire.com'],
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'Cuéntica'}
+ }
+ ]
+ } ,
+ {
+ name:'form post test',
+ host: 'hroch486.icpf.cas.cz',
+ port:80,
+ ping_service_name: 'http',
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ enabled: true,
+ services : [
+ {
+ name: 'post',
+ method: 'get',
+ url : '/formpost.html',
+ expected: {statuscode: 200, contains: 'Test Form -- POST method'}
+ },
+ {
+ name: 'post with data',
+ method: 'post',
+ input_data : 'your_name=Ivan&fruit=Banana',
+ content_type : 'application/x-www-form-urlencoded', // application/json
+ url : '/cgi-bin/echo.pl',
+ expected: {statuscode: 200, contains: 'your_name = Ivan'}
+ }
+ ]
+ } ,
+ {
+ name:'Menéame',
+ host: 'www.meneame.net',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ warning_if_takes_more_than: 2000,
+ enabled: true,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'Menéame'}
+ }
+ ]
+ } ,
+ {
+ name:'node js',
+ host: 'nodejs.org',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ warning_if_takes_more_than: 1500,
+ enabled: true,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'Node'}
+ }
+ ]
+ } ,
+ {
+ name:'redis',
+ host: 'redis.io',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ warning_if_takes_more_than: 1500,
+ enabled: true,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'Redis'}
+ }
+ ]
+ } ,
+ {
+ name:'express',
+ host: 'expressjs.com',
+ port:80,
+ ping_service_name: 'http',
+ timeout:10000,
+ ping_interval: one_tick,
+ failed_ping_interval: one_tick / 3,
+ enabled: true,
+ services : [
+ {
+ name: 'home',
+ method: 'get',
+ url : '/',
+ expected: {statuscode: 200, contains: 'web application framework'}
+ }
+ ]
+ }
+ ];
View
30 config/storage.js
@@ -1,20 +1,20 @@
module.exports = {
- //---------------------------
- // Select storage provider.
- // Supported providers: 'redis'
- //---------------------------
- provider : 'redis',
+ //---------------------------
+ // Select storage provider.
+ // Supported providers: 'redis'
+ //---------------------------
+ provider : 'redis',
- options : {
+ options : {
- //---------------------------
- // redis configuration
- //---------------------------
- 'redis' : {
- port: 1216,
- host: '127.0.0.1',
- db: 1
- }
- }
+ //---------------------------
+ // redis configuration
+ //---------------------------
+ 'redis' : {
+ port: 1216,
+ host: '127.0.0.1',
+ db: 1
+ }
+ }
};
View
24 lib/notifications/email/email.js
@@ -2,16 +2,16 @@ var postmark = require ('./postmark');
var config = require ('../../../config/general');
exports.sendEmail = function (to_list, subject, body, callback){
- postmark.sendEmail({
- 'From' : config.notifications.postmark.from,
- 'To': to_list.join(','),
- 'Subject': subject,
- 'TextBody': body }, config.notifications.postmark.api_key, function(err, data) {
- if (err) {
- console.error (err);
- if (callback) callback (err, null);
- } else {
- if (callback) callback (null,'Email sent successfully to ' + to_list.join(','));
- }
- });
+ postmark.sendEmail({
+ 'From' : config.notifications.postmark.from,
+ 'To': to_list.join(','),
+ 'Subject': subject,
+ 'TextBody': body }, config.notifications.postmark.api_key, function(err, data) {
+ if (err) {
+ console.error (err);
+ if (callback) callback (err, null);
+ } else {
+ if (callback) callback (null,'Email sent successfully to ' + to_list.join(','));
+ }
+ });
};
View
97 lib/notifications/email/postmark.js
@@ -1,53 +1,54 @@
var http = require("http")
- , util = require("util")
+ , util = require("util");
function sendEmail (message, api_key, callback){
-
- var messageStr = JSON.stringify(message)
-
- postmark_headers = {
- "Accept": "application/json",
- "Content-Type": "application/json",
- "X-Postmark-Server-Token": api_key,
- "Content-Length " : messageStr.length
- }
-
- var req = http.request({
- host: "api.postmarkapp.com",
- path: "/email",
- method: "POST",
- headers: postmark_headers,
- port: 80 //ssl en 443
- }, function(res) {
-
- res.setEncoding('utf8')
- var data = ''
-
- res.on('data', function (chunk) {
- data += chunk
- })
-
- res.on('end', function() {
- try {
- //http://developer.postmarkapp.com/developer-build.html
- var json = JSON.parse(data)
- if (res.statusCode==200) { //ok
- callback(null, json)
- }
- else{ //error
- callback (json,null)
- }
- } catch(e) {
- callback(e.message, null)
- }
- })
- })
-
- req.on('error', function(e) {
- callback(e.message, null)
- })
- req.write(messageStr, 'utf8')
- req.end()
+
+ var messageStr = JSON.stringify(message);
+
+ postmark_headers = {
+ "Accept": "application/json",
+ "Content-Type": "application/json",
+ "X-Postmark-Server-Token": api_key,
+ "Content-Length " : messageStr.length
+ };
+
+ var req = http.request({
+ host: "api.postmarkapp.com",
+ path: "/email",
+ method: "POST",
+ headers: postmark_headers,
+ port: 80 //ssl en 443
+ }, function(res) {
+
+ res.setEncoding('utf8');
+ var data = '';
+
+ res.on('data', function (chunk) {
+ data += chunk;
+ });
+
+ res.on('end', function() {
+ try {
+ //http://developer.postmarkapp.com/developer-build.html
+ var json = JSON.parse(data);
+ if (res.statusCode==200) { //ok
+ callback(null, json);
+ }
+ else{ //error
+ callback (json,null);
+ }
+ } catch(e) {
+ callback(e.message, null);
+ }
+ });
+ });
+
+ req.on('error', function(e) {
+ callback(e.message, null);
+ });
+
+ req.write(messageStr, 'utf8');
+ req.end();
}
-exports.sendEmail = sendEmail
+exports.sendEmail = sendEmail;
View
164 lib/ping_services/http.js
@@ -25,88 +25,88 @@ function validate_http_response (service, body, res){
function ping (service, callback){
- // record start time
- var startTime = new Date();
-
- var headers = {
- 'Host': service.host.host
- };
-
- if (service.method == 'post'){
- headers['Content-Type'] = service.content_type;
- headers['Content-Length'] = JSON.stringify(service.input_data || '').length;
- }
-
- var method = service.method;
- if (!service.expected || !service.expected.contains){
- method = "HEAD";
- }
-
- var options = {
- port: service.host.port,
- host: service.host.host,
- path: service.url,
- method: method,
- agent:false
- };
-
- var request;
- if(service.host.protocol === "https") {
- request = https.request(options);
- https.globalAgent.maxSockets=500;
- } else {
- request = http.request(options);
- http.globalAgent.maxSockets=500;
- }
-
- var handled_callback = false;
- var error = null;
-
- request.setTimeout(service.timeout || 10000, function(){
- if (!handled_callback){
- handled_callback = true;
- callback('Timeout');
- }
- });
-
- request.addListener('error', function(connectionException){
- error = connectionException.errno || 'Error establishing connection';
- if (!handled_callback){
- handled_callback = true;
- callback(error);
- }
- });
-
- request.on('response', function(response) {
- response.setEncoding('utf-8');
- var body = '';
-
- response.on('data', function(chunk) {
- body += chunk;
- });
-
- response.on('end', function() {
- var timeDiff = (new Date() - startTime);
- if (!handled_callback){
- handled_callback = true;
- callback(validate_http_response(service, body, response), body, response, timeDiff);
- }
- });
-
- response.on('error', function(e) {
- error = e.message;
- });
- });
-
- request.on('error', function(e) {
- if (!handled_callback){
- handled_callback = true;
- callback(e.message + '. Details :' + service.host.host + service.url);
- }
- });
-
- request.write(JSON.stringify(service.input_data) || '');
- request.end();
+ // record start time
+ var startTime = new Date();
+
+ var headers = {
+ 'Host': service.host.host
+ };
+
+ if (service.method == 'post'){
+ headers['Content-Type'] = service.content_type;
+ headers['Content-Length'] = JSON.stringify(service.input_data || '').length;
+ }
+
+ var method = service.method;
+ if (!service.expected || !service.expected.contains){
+ method = "HEAD";
+ }
+
+ var options = {
+ port: service.host.port,
+ host: service.host.host,
+ path: service.url,
+ method: method,
+ agent:false
+ };
+
+ var request;
+ if(service.host.protocol === "https") {
+ request = https.request(options);
+ https.globalAgent.maxSockets=500;
+ } else {
+ request = http.request(options);
+ http.globalAgent.maxSockets=500;
+ }
+
+ var handled_callback = false;
+ var error = null;
+
+ request.setTimeout(service.timeout || 10000, function(){
+ if (!handled_callback){
+ handled_callback = true;
+ callback('Timeout');
+ }
+ });
+
+ request.addListener('error', function(connectionException){
+ error = connectionException.errno || 'Error establishing connection';
+ if (!handled_callback){
+ handled_callback = true;
+ callback(error);
+ }
+ });
+
+ request.on('response', function(response) {
+ response.setEncoding('utf-8');
+ var body = '';
+
+ response.on('data', function(chunk) {
+ body += chunk;
+ });
+
+ response.on('end', function() {
+ var timeDiff = (new Date() - startTime);
+ if (!handled_callback){
+ handled_callback = true;
+ callback(validate_http_response(service, body, response), body, response, timeDiff);
+ }
+ });
+
+ response.on('error', function(e) {
+ error = e.message;
+ });
+ });
+
+ request.on('error', function(e) {
+ if (!handled_callback){
+ handled_callback = true;
+ callback(e.message + '. Details :' + service.host.host + service.url);
+ }
+ });
+
+ request.write(JSON.stringify(service.input_data) || '');
+ request.end();
}
module.exports.ping = ping;
View
20 lib/ping_services/smtp.js
@@ -2,18 +2,18 @@ var net = require('net');
function ping (service, callback){
- var startTime = new Date();
- var socket = net.createConnection(service.host.port, service.host.host);
+ var startTime = new Date();
+ var socket = net.createConnection(service.host.port, service.host.host);
- //TODO: implement logic to validate and actual SMTP server (here we are just checking that ir responds)
- socket.on("data", function (c) {
- socket.end("bye!");
- });
+ //TODO: implement logic to validate and actual SMTP server (here we are just checking that ir responds)
+ socket.on("data", function (c) {
+ socket.end("bye!");
+ });
- socket.on("end", function () {
- var timeDiff = (new Date() - startTime);
- callback(null, null, null, timeDiff);
- });
+ socket.on("end", function () {
+ var timeDiff = (new Date() - startTime);
+ callback(null, null, null, timeDiff);
+ });
}
module.exports.ping = ping;
View
68 lib/services.js
@@ -6,52 +6,52 @@ var services = null;
module.exports.load_services = function (){
- if (services){ //cache services collection
- return services;
- }
+ if (services){ //cache services collection
+ return services;
+ }
- services = [];
+ services = [];
- hosts.forEach (function(host){
+ hosts.forEach (function(host){
- host.protocol = host.protocol || 'http';
+ host.protocol = host.protocol || 'http';
- host.services.forEach(function(service){
- service.host = host;
- delete service.host.services; //avoid circular references
+ host.services.forEach(function(service){
+ service.host = host;
+ delete service.host.services; //avoid circular references
- //friendly display of this service
- service.url_info = host.name + ' - ' + host.host + ':'+ host.port + ' / ' + service.name;
+ //friendly display of this service
+ service.url_info = host.name + ' - ' + host.host + ':'+ host.port + ' / ' + service.name;
- //config response time limit
- service.warning_if_takes_more_than = service.warning_if_takes_more_than || host.warning_if_takes_more_than;
+ //config response time limit
+ service.warning_if_takes_more_than = service.warning_if_takes_more_than || host.warning_if_takes_more_than;
- //config ping interval
- service.ping_interval = service.ping_interval || host.ping_interval || 60;
+ //config ping interval
+ service.ping_interval = service.ping_interval || host.ping_interval || 60;
- //config failed ping interval
- service.failed_ping_interval = service.failed_ping_interval || host.failed_ping_interval || 70;
+ //config failed ping interval
+ service.failed_ping_interval = service.failed_ping_interval || host.failed_ping_interval || 70;
- //config alert notifications
- service.alert_to = service.alert_to || host.alert_to || config.notifications.to;
+ //config alert notifications
+ service.alert_to = service.alert_to || host.alert_to || config.notifications.to;
- //resolve ping service name value
- service.ping_service_name = (service.ping_service_name || host.ping_service_name || 'http');
+ //resolve ping service name value
+ service.ping_service_name = (service.ping_service_name || host.ping_service_name || 'http');
- //resolve ping service for this service instance
- service.ping_service = require('./ping_services/' + service.ping_service_name);
+ //resolve ping service for this service instance
+ service.ping_service = require('./ping_services/' + service.ping_service_name);
- //resolve if service is enabled
- if (service.enabled === undefined){ //no enabled config found for service
- service.enabled = host.enabled;
- }
- if (service.enabled === undefined){ //no enabled config found for host
- service.enabled = true;
- }
+ //resolve if service is enabled
+ if (service.enabled === undefined){ //no enabled config found for service
+ service.enabled = host.enabled;
+ }
+ if (service.enabled === undefined){ //no enabled config found for host
+ service.enabled = true;
+ }
- services.push (service);
- });
- });
+ services.push (service);
+ });
+ });
- return services;
+ return services;
};
View
10 lib/storage/base.js
@@ -1,26 +1,26 @@
function StorageBase (){ }
StorageBase.prototype._get_key = function (service, callback){
- return service.host.host + service.host.port + service.url;
+ return service.host.host + service.host.port + service.url;
};
StorageBase.prototype.get_status = function (service, callback){
- callback(null, null);
+ callback(null, null);
};
StorageBase.prototype.update_status = function (service, status, callback){
- callback(null);
+ callback(null);
};
//----------------------------------------------
// Reporting
//----------------------------------------------
StorageBase.prototype.report_all = function (callback){
- callback(null, null);
+ callback(null, null);
};
StorageBase.prototype.report_one = function (service, callback){
- callback(null, null);
+ callback(null, null);
};
StorageBase.prototype.quit = function (callback){
View
86 lib/storage/providers/redis.js
@@ -1,38 +1,38 @@
var util = require ('util');
function StorageRedis(options){
- this.options = options || {};
- this.redis = require("redis").createClient(this.options.port || 6379, this.options.host || '127.0.0.1');
- this.redis.select (this.options.db || 0);
+ this.options = options || {};
+ this.redis = require("redis").createClient(this.options.port || 6379, this.options.host || '127.0.0.1');
+ this.redis.select (this.options.db || 0);
}
util.inherits(StorageRedis, require ('../base'));
StorageRedis.prototype.get_status = function (service, callback){
- this.redis.get(this._get_key(service), function(err, data){
- callback(err, err ? null : JSON.parse(data));
- });
+ this.redis.get(this._get_key(service), function(err, data){
+ callback(err, err ? null : JSON.parse(data));
+ });
};
StorageRedis.prototype.update_status = function (service, status, callback){
- var self = this;
- var multi = this.redis.multi();
+ var self = this;
+ var multi = this.redis.multi();
- //1. save events
- if (status.events && status.events.length){
- status.events.forEach(function(ev){
- multi.zadd(self._get_key(service)+ ':events', status.timestamp, JSON.stringify(ev));
- });
- }
+ //1. save events
+ if (status.events && status.events.length){
+ status.events.forEach(function(ev){
+ multi.zadd(self._get_key(service)+ ':events', status.timestamp, JSON.stringify(ev));
+ });
+ }
- //2. save status
- delete status.events; //already saved in sorted set
- multi.set(this._get_key(service), JSON.stringify(status));
+ //2. save status
+ delete status.events; //already saved in sorted set
+ multi.set(this._get_key(service), JSON.stringify(status));
- multi.exec(function(err, replies) {
- callback(err);
- });
+ multi.exec(function(err, replies) {
+ callback(err);
+ });
};
//----------------------------------------------
@@ -40,45 +40,45 @@ StorageRedis.prototype.update_status = function (service, status, callback){
//----------------------------------------------
StorageRedis.prototype.report_all = function (services, callback){
- var self = this;
+ var self = this;
- var multi = this.redis.multi();
+ var multi = this.redis.multi();
- for (var i = 0, l = services.length; i < l ; i++) {
- multi.get(self._get_key(services[i]));
- }
+ for (var i = 0, l = services.length; i < l ; i++) {
+ multi.get(self._get_key(services[i]));
+ }
- multi.exec(function(err, replies) {
- for (var i = 0, l = services.length; i < l ; i++) {
- services[i].data = JSON.parse(replies[i]);
- }
- callback(err, {services: services});
- });
+ multi.exec(function(err, replies) {
+ for (var i = 0, l = services.length; i < l ; i++) {
+ services[i].data = JSON.parse(replies[i]);
+ }
+ callback(err, {services: services});
+ });
};
StorageRedis.prototype.report_one = function (service, callback){
- var multi = this.redis.multi();
+ var multi = this.redis.multi();
- multi.get(this._get_key(service));
- multi.zrevrange(this._get_key(service) + ':events',0, -1);
+ multi.get(this._get_key(service));
+ multi.zrevrange(this._get_key(service) + ':events',0, -1);
- multi.exec(function(err, replies) {
- if (replies[0]){
- service.data = JSON.parse(replies[0]);
- service.data.events = replies[1].map(function(ev){return JSON.parse(ev);}); //parse each entry
- }
- callback(err, service);
- });
+ multi.exec(function(err, replies) {
+ if (replies[0]){
+ service.data = JSON.parse(replies[0]);
+ service.data.events = replies[1].map(function(ev){return JSON.parse(ev);}); //parse each entry
+ }
+ callback(err, service);
+ });
};
//available on redis
StorageRedis.prototype.flush_database = function (callback){
- this.redis.flushdb(callback);
+ this.redis.flushdb(callback);
};
StorageRedis.prototype.quit = function (callback){
- this.redis.quit();
+ this.redis.quit();
};
module.exports = StorageRedis;
View
10 lib/storage/storage_factory.js
@@ -2,9 +2,9 @@
var provider_name = require ('../../config/storage').provider;
module.exports = {
- get_storage_instance : function (){
- var options = require ('../../config/storage').options[provider_name];
- var provider = require ('./providers/' + provider_name);
- return new provider(options);
- }
+ get_storage_instance : function (){
+ var options = require ('../../config/storage').options[provider_name];
+ var provider = require ('./providers/' + provider_name);
+ return new provider(options);
+ }
};
View
72 server.js
@@ -12,50 +12,50 @@ var watchmen = new WatchMen(services, storage);
//----------------------------------------------------
watchmen.on('service_error', function(service, state){
- /*
- //Do here any additional stuff when you get an error
- */
- var info = service.url_info + ' down!. Error: ' + state.error + '. Retrying in ' +
- (parseInt(state.next_attempt_secs, 10) / 60) + ' minute(s)..';
-
- console.log (info);
-
- if (state.prev_state.status === 'success' && config.notifications.enabled){
- email_service.sendEmail(
- service.alert_to,
- service.url_info + ' is down!',
- service.url_info + ' is down!. Reason: ' + state.error
- );
- }
+ /*
+ //Do here any additional stuff when you get an error
+ */
+ var info = service.url_info + ' down!. Error: ' + state.error + '. Retrying in ' +
+ (parseInt(state.next_attempt_secs, 10) / 60) + ' minute(s)..';
+
+ console.log (info);
+
+ if (state.prev_state.status === 'success' && config.notifications.enabled){
+ email_service.sendEmail(
+ service.alert_to,
+ service.url_info + ' is down!',
+ service.url_info + ' is down!. Reason: ' + state.error
+ );
+ }
});
watchmen.on('service_warning', function(service, state){
- /*
- //Do here any additional stuff when you get a warning
+ /*
+ //Do here any additional stuff when you get a warning
- console.log (service.url_info + ' WARNING (' + state.elapsed_time + ' ms, avg: '
- + state.avg_response_time + ') ## ' + state.warnings + ' warnings');
- */
+ console.log (service.url_info + ' WARNING (' + state.elapsed_time + ' ms, avg: '
+ + state.avg_response_time + ') ## ' + state.warnings + ' warnings');
+ */
});
watchmen.on('service_back', function(service, state){
- if (config.notifications.enabled){
- email_service.sendEmail(
- service.alert_to,
- service.url_info + ' is back!',
- service.url_info + ' ' + service.msg
- );
- }
+ if (config.notifications.enabled){
+ email_service.sendEmail(
+ service.alert_to,
+ service.url_info + ' is back!',
+ service.url_info + ' ' + service.msg
+ );
+ }
});
watchmen.on('service_ok', function(service, state){
- /*
- //Do here any additional stuff when you get a successful response
+ /*
+ //Do here any additional stuff when you get a successful response
- console.log (service.url_info + ' responded OK! (' + state.elapsed_time + ' milliseconds, avg: '
- + state.avg_response_time + ')');
+ console.log (service.url_info + ' responded OK! (' + state.elapsed_time + ' milliseconds, avg: '
+ + state.avg_response_time + ')');
*/
});
@@ -69,12 +69,12 @@ watchmen.start();
// Error handling
//----------------------------------------------------
process.on('uncaughtException', function(err) {
- console.error('uncaughtException:');
- console.error(err);
+ console.error('uncaughtException:');
+ console.error(err);
});
process.on('SIGINT', function () {
- console.log('stopping watchmen..');
- storage.quit();
- process.exit(0);
+ console.log('stopping watchmen..');
+ storage.quit();
+ process.exit(0);
});
View
4 test/lib/mock/request_mocked.js
@@ -1,6 +1,6 @@
module.exports.mocked_response = {};
module.exports.ping = function (service, callback) {
- var res = exports.mocked_response;
- callback(res.error, res.body, res.response, res.timeDiff);
+ var res = exports.mocked_response;
+ callback(res.error, res.body, res.response, res.timeDiff);
};
View
4 test/lib/mock/storage_mocked.js
@@ -1,13 +1,13 @@
var util = require ('util');
function StorageMocked(mocked_status){
- this.status = mocked_status;
+ this.status = mocked_status;
}
util.inherits(StorageMocked, require ('../../../lib/storage/base'));
StorageMocked.prototype.get_status = function (service, callback){
- callback(null, this.status);
+ callback(null, this.status);
};
module.exports = StorageMocked;
View
678 test/ping.mocha
@@ -1,345 +1,345 @@
var watchmen = require ('../lib/watchmen');
-var assert = require ('assert');
+var assert = require ('assert');
var storage_mocked = require ('./lib/mock/storage_mocked');
describe('ping service', function(){
- var temp_status = null;
- var temp_last_outage = null;
-
- var failed_request_timestamp = null;
- var correct_request_timestamp = null;
- var warning_request_timestamp = null;
-
- var service = {
- host : {host: 'www.correcthost.com', port:'80', name : 'test'},
- url : '/',
- ping_interval: 4,
- failed_ping_interval: 5,
- warning_if_takes_more_than: 1500, //miliseconds
- method : 'get',
- expected : {statuscode: 200, contains: ''}
- };
-
- var mocked_ping_service = require ('./lib/mock/request_mocked');
- service.ping_service = mocked_ping_service;
-
- describe('bad request', function(){
-
- var _watchmen = null;
-
- before(function(done){
- failed_request_timestamp = +new Date();
- mocked_ping_service.mocked_response = {error: 'mocked error', body : null, response : null, timeDiff : 0};
- _watchmen = new watchmen(null, new storage_mocked(null));
- done();
- });
-
- it('should emit error', function(done){
- _watchmen.on('service_ok', function (service, status){
- done('error. bad response - dns request');
- });
-
- _watchmen.on('service_error', function (service, status){
- temp_status = status;
- done(null);
- });
-
- _watchmen.ping({service:service, timestamp: failed_request_timestamp}, function(err, request_status){
- assert.ifError(err);
- });
- });
-
- it('should have last_check property', function(done){
- assert.equal (temp_status.last_check, failed_request_timestamp);
- done();
- });
-
- it('should have running_since property', function(done){
- assert.equal (temp_status.running_since, failed_request_timestamp);
- done();
- });
-
- it('should have right status error', function(done){
- assert.equal (temp_status.status, "error");
- done();
- });
-
- it('should have last_outage', function(done){
- assert.ok (temp_status.last_outage);
- temp_last_outage = temp_status.last_outage; //save for next test
- done();
- });
-
- it('should have right delay for next attempt', function(done){
- assert.equal (temp_status.next_attempt_secs, service.failed_ping_interval);
- done();
- });
-
- it('should have an error event', function(done){
- assert.equal (temp_status.events[0].status, 'error');
- done();
- });
-
- it('should have a down_timestamp value', function(done){
- assert.equal (temp_status.down_timestamp, failed_request_timestamp);
- done();
- });
-
- it('should NOT have a downtime value yet', function(done){
- assert.ok (!temp_status.down_time_last_request);
- done();
- });
-
- it('should NOT have a prev_state yet', function(done){
- assert.equal (JSON.stringify(temp_status.prev_state),'{}');
- done();
- });
-
- it('should have a running_since value', function(done){
- assert.equal (temp_status.running_since, failed_request_timestamp);
- done();
- });
-
- it('should have 1 outage', function(done){
- assert.equal (temp_status.outages, 1);
- done();
- });
-
- it('should NOT have a up_since value yet', function(done){
- assert.ok (!temp_status.up_since);
- done();
- });
-
- it('should have zero uptime', function(done){
- assert.equal (temp_status.uptime, 0);
- done();
- });
-
- it('should NOT have ok_responses', function(done){
- assert.equal (temp_status.ok_responses_count, 0);
- done();
- });
-
- it('should NOT have avg_response_time value', function(done){
- assert.ok (!temp_status.avg_response_time);
- done();
- });
- });
-
- describe('correct (service back) request', function(){
-
- var _watchmen = null;
-
- before(function(done){
- correct_request_timestamp = failed_request_timestamp + 60*1000; //one minute later
- mocked_ping_service.mocked_response = {error: null, body : 'ok', response : {body: 'ok', statusCode: 200}, timeDiff : 300};
- _watchmen = new watchmen(null, new storage_mocked(temp_status));
- done();
- });
-
- it('should emit service_back', function(done){
- _watchmen.on('service_back', function (service, status){
- temp_status = status;
- done(null);
- });
-
- _watchmen.on('service_error', function (service, status){
- done('error. bad response');
- });
-
- _watchmen.ping({service:service, timestamp: correct_request_timestamp}, function(err, request_status){
- assert.ifError(err);
- });
- });
-
- it('should have last_check', function(done){
- assert.equal (temp_status.last_check, correct_request_timestamp);
- done();
- });
-
- it('should have running_since property', function(done){
- assert.equal (temp_status.running_since, failed_request_timestamp);
- done();
- });
-
- it('should have prev_state', function(done){
- assert.ok (temp_status.prev_state);
- done();
- });
-
- it('should not have a nested prev_state property', function(done){
- assert.ok (!temp_status.prev_state.prev_state);
- done();
- });
-
- it('should have right status', function(done){
- assert.equal (temp_status.status, "success");
- done();
- });
-
- it('should have last_outage', function(done){
- assert.equal (temp_status.last_outage, temp_last_outage);
- done();
- });
-
- it('should have right delay for next attempt', function(done){
- assert.equal (temp_status.next_attempt_secs, service.ping_interval);
- done();
- });
-
- it('should have service_back event', function(done){
- assert.equal (temp_status.events.length, 1);
- done();
- });
-
- it('should NOT have a down_timestamp value', function(done){
- assert.ok (!temp_status.down_timestamp);
- done();
- });
-
- it('should have a up_since value', function(done){
- assert.equal (temp_status.up_since, correct_request_timestamp);
- done();
- });
-
- it('should have a downtime value', function(done){
- //corresponding to the last failed request
- assert.equal (temp_status.down_time_last_request, (correct_request_timestamp-failed_request_timestamp)/1000); //in seconds
- done();
- });
-
- it('should have an accumulated downtime value', function(done){
- assert.equal (temp_status.down_time_acc, (correct_request_timestamp-failed_request_timestamp)/1000); //in seconds
- done();
- });
-
- it('should have 1 outage from last invalid request', function(done){
- assert.equal (temp_status.outages, 1);
- done();
- });
-
- it('should have zero uptime', function(done){
- assert.equal (temp_status.uptime, 0);
- done();
- });
-
- it('should have 1 successful response', function(done){
- assert.equal (temp_status.ok_responses_count, 1);
- done();
- });
-
- it('should have avg_response_time value', function(done){
- assert.equal (temp_status.avg_response_time, 300);
- done();
- });
- });
-
-
- describe('warning request', function(){
-
- var _watchmen = null;
-
- before(function(done){
- warning_request_timestamp = failed_request_timestamp + 2 * 60 * 1000; //one minute later
- mocked_ping_service.mocked_response = {error: null, body : 'ok', response : {body: 'ok', statusCode: 200}, timeDiff : 22300};
- _watchmen = new watchmen(null, new storage_mocked(temp_status));
- done();
- });
-
- it('should emit service_back', function(done){
- _watchmen.on('service_warning', function (service, status){
- temp_status = status;
- done(null);
- });
-
- _watchmen.on('service_error', function (service, status){
- done('error. bad response');
- });
-
- _watchmen.ping({service:service, timestamp: warning_request_timestamp}, function(err, request_status){
- assert.ifError(err);
- });
- });
-
- it('should have last_check', function(done){
- assert.equal (temp_status.last_check, warning_request_timestamp);
- done();
- });
-
- it('should have running_since property', function(done){
- assert.equal (temp_status.running_since, failed_request_timestamp);
- done();
- });
-
- it('should have prev_state', function(done){
- assert.ok (temp_status.prev_state);
- done();
- });
-
- it('should not have a nested prev_state property', function(done){
- assert.ok (!temp_status.prev_state.prev_state);
- done();
- });
-
- it('should have right status', function(done){
- assert.equal (temp_status.status, "success");
- done();
- });
-
- it('should have last_outage', function(done){
- assert.equal (temp_status.last_outage, temp_last_outage);
- done();
- });
-
- it('should have right delay for next attempt', function(done){
- assert.equal (temp_status.next_attempt_secs, service.ping_interval);
- done();
- });
-
- it('should have service_back event', function(done){
- assert.equal (temp_status.events.length, 1);
- done();
- });
-
- it('should have NOT a down_timestamp value', function(done){
- assert.ok (!temp_status.down_timestamp);
- done();
- });
-
- it('should have NOT a downtime value', function(done){
- assert.ok (!temp_status.down_time_last_request);
- done();
- });
-
- it('should have an accumulated downtime value', function(done){
- assert.equal (temp_status.down_time_acc, (correct_request_timestamp-failed_request_timestamp)/1000); //in seconds
- done();
- });
-
- it('should have a up_since value', function(done){
- assert.equal (temp_status.up_since, correct_request_timestamp);
- done();
- });
-
- it('should have 1 outage from last invalid request', function(done){
- assert.equal (temp_status.outages, 1);
- done();
- });
-
- it('should have more than zero uptime', function(done){
- assert.equal (temp_status.uptime, 50);
- done();
- });
-
- it('should have 2 successful responses', function(done){
- assert.equal (temp_status.ok_responses_count, 2);
- done();
- });
-
- it('should have avg_response_time value', function(done){
- assert.equal (temp_status.avg_response_time, 11300);
- done();
- });
- });
+ var temp_status = null;
+ var temp_last_outage = null;
+
+ var failed_request_timestamp = null;
+ var correct_request_timestamp = null;
+ var warning_request_timestamp = null;
+
+ var service = {
+ host : {host: 'www.correcthost.com', port:'80', name : 'test'},
+ url : '/',
+ ping_interval: 4,
+ failed_ping_interval: 5,
+ warning_if_takes_more_than: 1500, //miliseconds
+ method : 'get',
+ expected : {statuscode: 200, contains: ''}
+ };
+
+ var mocked_ping_service = require ('./lib/mock/request_mocked');
+ service.ping_service = mocked_ping_service;
+
+ describe('bad request', function(){
+
+ var _watchmen = null;
+
+ before(function(done){
+ failed_request_timestamp = +new Date();
+ mocked_ping_service.mocked_response = {error: 'mocked error', body : null, response : null, timeDiff : 0};
+ _watchmen = new watchmen(null, new storage_mocked(null));
+ done();
+ });
+
+ it('should emit error', function(done){
+ _watchmen.on('service_ok', function (service, status){
+ done('error. bad response - dns request');
+ });
+
+ _watchmen.on('service_error', function (service, status){
+ temp_status = status;
+ done(null);
+ });
+
+ _watchmen.ping({service:service, timestamp: failed_request_timestamp}, function(err, request_status){
+ assert.ifError(err);
+ });
+ });
+
+ it('should have last_check property', function(done){
+ assert.equal (temp_status.last_check, failed_request_timestamp);
+ done();
+ });
+
+ it('should have running_since property', function(done){
+ assert.equal (temp_status.running_since, failed_request_timestamp);
+ done();
+ });
+
+ it('should have right status error', function(done){
+ assert.equal (temp_status.status, "error");
+ done();
+ });
+
+ it('should have last_outage', function(done){
+ assert.ok (temp_status.last_outage);
+ temp_last_outage = temp_status.last_outage; //save for next test
+ done();
+ });
+
+ it('should have right delay for next attempt', function(done){
+ assert.equal (temp_status.next_attempt_secs, service.failed_ping_interval);
+ done();
+ });
+
+ it('should have an error event', function(done){
+ assert.equal (temp_status.events[0].status, 'error');
+ done();
+ });
+
+ it('should have a down_timestamp value', function(done){
+ assert.equal (temp_status.down_timestamp, failed_request_timestamp);
+ done();
+ });
+
+ it('should NOT have a downtime value yet', function(done){
+ assert.ok (!temp_status.down_time_last_request);
+ done();
+ });
+
+ it('should NOT have a prev_state yet', function(done){
+ assert.equal (JSON.stringify(temp_status.prev_state),'{}');
+ done();
+ });
+
+ it('should have a running_since value', function(done){
+ assert.equal (temp_status.running_since, failed_request_timestamp);
+ done();
+ });
+
+ it('should have 1 outage', function(done){
+ assert.equal (temp_status.outages, 1);
+ done();
+ });
+
+ it('should NOT have a up_since value yet', function(done){
+ assert.ok (!temp_status.up_since);
+ done();
+ });
+
+ it('should have zero uptime', function(done){
+ assert.equal (temp_status.uptime, 0);
+ done();
+ });
+
+ it('should NOT have ok_responses', function(done){
+ assert.equal (temp_status.ok_responses_count, 0);
+ done();
+ });
+
+ it('should NOT have avg_response_time value', function(done){
+ assert.ok (!temp_status.avg_response_time);
+ done();
+ });
+ });
+
+ describe('correct (service back) request', function(){
+
+ var _watchmen = null;
+
+ before(function(done){
+ correct_request_timestamp = failed_request_timestamp + 60*1000; //one minute later
+ mocked_ping_service.mocked_response = {error: null, body : 'ok', response : {body: 'ok', statusCode: 200}, timeDiff : 300};
+ _watchmen = new watchmen(null, new storage_mocked(temp_status));
+ done();
+ });
+
+ it('should emit service_back', function(done){
+ _watchmen.on('service_back', function (service, status){
+ temp_status = status;
+ done(null);
+ });
+
+ _watchmen.on('service_error', function (service, status){
+ done('error. bad response');
+ });
+
+ _watchmen.ping({service:service, timestamp: correct_request_timestamp}, function(err, request_status){
+ assert.ifError(err);
+ });
+ });
+
+ it('should have last_check', function(done){
+ assert.equal (temp_status.last_check, correct_request_timestamp);
+ done();
+ });
+
+ it('should have running_since property', function(done){
+ assert.equal (temp_status.running_since, failed_request_timestamp);
+ done();
+ });
+
+ it('should have prev_state', function(done){
+ assert.ok (temp_status.prev_state);
+ done();
+ });
+
+ it('should not have a nested prev_state property', function(done){
+ assert.ok (!temp_status.prev_state.prev_state);
+ done();
+ });
+
+ it('should have right status', function(done){
+ assert.equal (temp_status.status, "success");
+ done();
+ });
+
+ it('should have last_outage', function(done){
+ assert.equal (temp_status.last_outage, temp_last_outage);
+ done();
+ });
+
+ it('should have right delay for next attempt', function(done){
+ assert.equal (temp_status.next_attempt_secs, service.ping_interval);
+ done();
+ });
+
+ it('should have service_back event', function(done){
+ assert.equal (temp_status.events.length, 1);
+ done();
+ });
+
+ it('should NOT have a down_timestamp value', function(done){
+ assert.ok (!temp_status.down_timestamp);
+ done();
+ });
+
+ it('should have a up_since value', function(done){
+ assert.equal (temp_status.up_since, correct_request_timestamp);
+ done();
+ });
+
+ it('should have a downtime value', function(done){
+ //corresponding to the last failed request
+ assert.equal (temp_status.down_time_last_request, (correct_request_timestamp-failed_request_timestamp)/1000); //in seconds
+ done();
+ });
+
+ it('should have an accumulated downtime value', function(done){
+ assert.equal (temp_status.down_time_acc, (correct_request_timestamp-failed_request_timestamp)/1000); //in seconds
+ done();
+ });
+
+ it('should have 1 outage from last invalid request', function(done){
+ assert.equal (temp_status.outages, 1);
+ done();
+ });
+
+ it('should have zero uptime', function(done){
+ assert.equal (temp_status.uptime, 0);
+ done();
+ });
+
+ it('should have 1 successful response', function(done){
+ assert.equal (temp_status.ok_responses_count, 1);
+ done();
+ });
+
+ it('should have avg_response_time value', function(done){
+ assert.equal (temp_status.avg_response_time, 300);
+ done();
+ });
+ });
+
+
+ describe('warning request', function(){
+
+ var _watchmen = null;
+
+ before(function(done){
+ warning_request_timestamp = failed_request_timestamp + 2 * 60 * 1000; //one minute later
+ mocked_ping_service.mocked_response = {error: null, body : 'ok', response : {body: 'ok', statusCode: 200}, timeDiff : 22300};
+ _watchmen = new watchmen(null, new storage_mocked(temp_status));
+ done();
+ });
+
+ it('should emit service_back', function(done){
+ _watchmen.on('service_warning', function (service, status){
+ temp_status = status;
+ done(null);
+ });
+
+ _watchmen.on('service_error', function (service, status){
+ done('error. bad response');
+ });
+
+ _watchmen.ping({service:service, timestamp: warning_request_timestamp}, function(err, request_status){
+ assert.ifError(err);
+ });
+ });
+
+ it('should have last_check', function(done){
+ assert.equal (temp_status.last_check, warning_request_timestamp);
+ done();
+ });
+
+ it('should have running_since property', function(done){
+ assert.equal (temp_status.running_since, failed_request_timestamp);
+ done();
+ });
+
+ it('should have prev_state', function(done){
+ assert.ok (temp_status.prev_state);
+ done();
+ });
+
+ it('should not have a nested prev_state property', function(done){
+ assert.ok (!temp_status.prev_state.prev_state);
+ done();
+ });
+
+ it('should have right status', function(done){
+ assert.equal (temp_status.status, "success");
+ done();
+ });
+