diff --git a/lib/core/engine.js b/lib/core/engine.js index 6d7af0fb..9b1795c3 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -30,7 +30,7 @@ class Engine { this.servicesMonitor = new ServicesMonitor({events: this.events, logger: this.logger}); this.servicesMonitor.addCheck('embarkVersion', function (cb) { - return cb({name: 'Embark ' + self.version, status: 'green'}); + return cb({name: 'Embark ' + self.version, status: 'on'}); }, 0); } @@ -166,7 +166,7 @@ class Engine { self.servicesMonitor.addCheck('Webserver', function (cb) { let devServer = 'Webserver (http://' + host + ':' + port + ')'; - return cb({name: devServer, status: 'green'}); + return cb({name: devServer, status: 'on'}); }); server.start(function () { @@ -190,24 +190,24 @@ class Engine { try { let parsed = JSON.parse(body); if (parsed.Version) { - return cb({name: ("IPFS " + parsed.Version), status: 'green'}); + return cb({name: ("IPFS " + parsed.Version), status: 'on'}); } else { - return cb({name: "IPFS ", status: 'green'}); + return cb({name: "IPFS ", status: 'on'}); } } catch (e) { - return cb({name: "IPFS ", status: 'red'}); + return cb({name: "IPFS ", status: 'off'}); } }); res.on('error', function (err) { self.logger.trace("Check IPFS version error: " + err); - return cb({name: "IPFS ", status: 'red'}); + return cb({name: "IPFS ", status: 'off'}); }); }); } else { - return cb({name: "IPFS ", status: 'red'}); + return cb({name: "IPFS ", status: 'off'}); } }); }); @@ -226,19 +226,19 @@ class Engine { if (self.web3.isConnected()) { return cb({ name: (self.web3.version.node.split("/")[0] + " " + self.web3.version.node.split("/")[1].split("-")[0] + " (Ethereum)"), - status: 'green' + status: 'on' }); } else { - return cb({name: "No Blockchain node found", status: 'red'}); + return cb({name: "No Blockchain node found", status: 'off'}); } }); self.servicesMonitor.addCheck('Whisper', function (cb) { self.web3.version.getWhisper(function (err, res) { if (err) { - return cb({name: 'Whisper', status: 'red'}); + return cb({name: 'Whisper', status: 'off'}); } else { - return cb({name: 'Whisper', status: 'green'}); + return cb({name: 'Whisper', status: 'on'}); } }); }); diff --git a/lib/core/services_monitor.js b/lib/core/services_monitor.js index a8ab2723..e0abfb1a 100644 --- a/lib/core/services_monitor.js +++ b/lib/core/services_monitor.js @@ -1,8 +1,5 @@ let async = require('../utils/async_extend.js'); -// TODO: need to separate colors from states -// i.e use status: /on|off|warn/ not /red|green/ -// it's up to the logger or console to determine the color class ServicesMonitor { constructor(options) { this.events = options.events; @@ -23,14 +20,13 @@ ServicesMonitor.prototype.initCheck = function (checkName) { } self.events.on('check:' + checkName, function (obj) { - // TODO: see todo above - if (check && check.status === 'red' && obj.status === 'green') { + if (check && check.status === 'off' && obj.status === 'on') { self.events.emit('check:backOnline:' + checkName); } - if (check && check.status === 'green' && obj.status === 'red') { + if (check && check.status === 'on' && obj.status === 'off') { self.events.emit('check:wentOffline:' + checkName); } - self.checkState[checkName] = obj.name[obj.status]; + self.checkState[checkName] = {name: obj.name, status: obj.status}; check.status = obj.status; self.events.emit("servicesState", self.checkState); }); diff --git a/lib/dashboard/monitor.js b/lib/dashboard/monitor.js index 15fa5698..0e0f1e5e 100644 --- a/lib/dashboard/monitor.js +++ b/lib/dashboard/monitor.js @@ -43,9 +43,16 @@ class Dashboard { availableServices(_services) { let services = []; - let checkName; - for (checkName in _services) { - services.push(_services[checkName]); + let check; + for (check in _services) { + let checkObj = _services[check]; + if (checkObj.status === 'on') { + services.push(checkObj.name.green); + } else if (checkObj.status === 'off') { + services.push(checkObj.name.red); + } else { + services.push(checkObj.name); + } } this.progress.setContent(services.join('\n')); diff --git a/test_app/extensions/embark-service/index.js b/test_app/extensions/embark-service/index.js index 27f58c84..1108dacb 100644 --- a/test_app/extensions/embark-service/index.js +++ b/test_app/extensions/embark-service/index.js @@ -1,5 +1,5 @@ module.exports = function(embark) { embark.registerServiceCheck('PluginService', function(cb) { - cb({name: "ServiceName", status: "green"}); + cb({name: "ServiceName", status: "on"}); }); };