Skip to content

Commit

Permalink
External plugins feature
Browse files Browse the repository at this point in the history
  • Loading branch information
chamerling committed Jan 14, 2014
1 parent 09eccae commit 2a7731d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -119,6 +119,27 @@ Some plugins are available out-of-the-box:

<img src="http://blog.bazoud.com/images/ssd8a.png" alt="">

External Plugins
================

You can develop independent plugins and load them into Status Dashboard by using the external plugin feature. A plugin example is available at [http://github.com/chamerling/sd-plugin-sample](http://github.com/chamerling/sd-plugin-sample).

Plugins can be installed using npm CLI (from the status-dashboard directory):

npm install sd-plugin-sample

Or by adding them as dependency in the status-dashboard package.json descriptor.

In order to activate plugins, you have to add them to the plugins.json file (\["sd-plugin-sample"\], \["my_plugin"\]) and turn on the external plugins feature in settings.js:

plugins : {
external: {
enable : true,
file : __dirname + '/plugins.json'
},
...
}

REST API
=======

Expand Down
26 changes: 26 additions & 0 deletions api.js
Expand Up @@ -51,6 +51,32 @@ module.exports.setup = function (settings) {
source = source.substr(0, source.length - 3);
sources[source] = require(__dirname + '/lib/sources/' + source).check;
});

if (settings.plugins.external.enable) {
var file = settings.plugins.external.file || __dirname + '/plugins.json';
log('Loading external plugins defined in ' + file + ' file');
var plugins;

try {
plugins = require(file);
} catch (err) {
log('Can not load external plugins file ' + err);
return err;
}

console.log(plugins)

_.each(plugins, function(item) {
try {
log('Loading external plugin ' + item);
require(item)({api : controller, settings : settings});
} catch (err) {
log('Can not load external plugin ' + item + ' : ' + err);
}
})
} else {
log('External plugins are not enabled, change value in settings.plugins.external.enable if needed');
}
};

/**
Expand Down
1 change: 1 addition & 0 deletions plugins.json
@@ -0,0 +1 @@
["sd-plugin-sample"]
4 changes: 4 additions & 0 deletions settings.js
Expand Up @@ -117,6 +117,10 @@ exports.create = function() {
}],
serviceInterval: 6000,
plugins : {
external: {
enable : false,
file : __dirname + '/plugins.json'
},
console : {
enable: false
},
Expand Down

0 comments on commit 2a7731d

Please sign in to comment.