Permalink
Browse files

Code styling, add comments, add reference to how to start the webserv…

…er and the monitor in the same process
  • Loading branch information...
1 parent 5084926 commit e18af80312a8901aecedd6f8665bed4c1223d3b4 @iloire committed Jul 13, 2013
Showing with 24 additions and 8 deletions.
  1. +24 −8 server.js
View
@@ -1,16 +1,23 @@
var config = require('./config/general');
var email_service = require ('./lib/notifications/email/email');
-var storage_factory = require ('./lib/storage/storage_factory');
-var services = require ('./lib/services').load_services();
+var services = require('./lib/services').load_services();
-var WatchMen = require ('./lib/watchmen');
+//----------------------------------------------------
+// Fetch storage
+//----------------------------------------------------
+var storage_factory = require('./lib/storage/storage_factory');
var storage = storage_factory.get_storage_instance();
+
+//----------------------------------------------------
+// Create watchmen instance
+//----------------------------------------------------
+var WatchMen = require('./lib/watchmen');
var watchmen = new WatchMen(services, storage);
//----------------------------------------------------
// Subscribe to service events
//----------------------------------------------------
-watchmen.on('service_error', function(service, state){
+watchmen.on('service_error', function(service, state) {
/*
//Do here any additional stuff when you get an error
@@ -20,7 +27,7 @@ watchmen.on('service_error', function(service, state){
console.log (info);
- if (state.prev_state.status === 'success' && config.notifications.enabled){
+ if (state.prev_state.status === 'success' && config.notifications.enabled) {
email_service.sendEmail(
service.alert_to,
service.url_info + ' is down!',
@@ -29,7 +36,7 @@ watchmen.on('service_error', function(service, state){
}
});
-watchmen.on('service_warning', function(service, state){
+watchmen.on('service_warning', function(service, state) {
/*
//Do here any additional stuff when you get a warning
@@ -40,7 +47,7 @@ watchmen.on('service_warning', function(service, state){
});
-watchmen.on('service_back', function(service, state){
+watchmen.on('service_back', function(service, state) {
if (config.notifications.enabled){
email_service.sendEmail(
service.alert_to,
@@ -50,7 +57,7 @@ watchmen.on('service_back', function(service, state){
}
});
-watchmen.on('service_ok', function(service, state){
+watchmen.on('service_ok', function(service, state) {
/*
//Do here any additional stuff when you get a successful response
@@ -64,6 +71,15 @@ watchmen.on('service_ok', function(service, state){
//----------------------------------------------------
watchmen.start();
+//----------------------------------------------------
+// Web server
+//----------------------------------------------------
+// You can launch the webserver in a separate process by doing: node webserver/app.js
+// - or -
+// you can just uncomment the following line to launch both the monitor and the web server
+// in the same process:
+
+//require('./webserver/app');
//----------------------------------------------------
// Error handling

0 comments on commit e18af80

Please sign in to comment.