Created
January 18, 2013 19:57
-
-
Save kvisle/4567941 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
We need to require the pupilplugin-creator | |
*/ | |
var http = require('http') | |
, pupilPlugin = require('../lib/pupilplugin') | |
, somehttpstuffthatreturnsjson = new pupilPlugin() | |
/* | |
setup is an optional function, that is used to configure the instanciated | |
version of the plugin. This is used to set configurational parameters. | |
*/ | |
somehttpstuffthatreturnsjson.prototype.setup = function (config) { | |
this._host = config.host; | |
this._port = config.port; | |
this._get = config.get; | |
return; | |
}; | |
/* | |
hasPlugin runs once at startup. This function is there to test if any | |
prerequisites for the plugin to run has been met - and should return an array | |
of any available sets of data. | |
*/ | |
somehttpstuffthatreturnsjson.prototype.test = function () { | |
return ['datasett1','datasett2']; | |
}; | |
/* | |
runPlugin runs once every second. It should call dispatch on its object to | |
send data off its way. | |
*/ | |
somehttpstuffthatreturnsjson.prototype.run = function () { | |
var self = this; | |
http.get({hostname: this._host, | |
port : this._port, | |
path : this._get, | |
agent:false}, | |
function (res) { | |
res.on('data', function (json) { | |
var o = JSON.parse(json); | |
self.dispatch('datasett1', { | |
type: 'gauge', | |
draw: 'stacked', | |
data: { | |
foo : o.foo, | |
bar : o.bar, | |
baz : o.baz | |
} | |
}); | |
self.dispatch('datasett2', { | |
type: 'counter', | |
draw: 'line', | |
data: { | |
hetti: o.hetti, | |
netti: o.netti, | |
letti: o.letti | |
} | |
}); | |
}); | |
}); | |
}; | |
module.exports = somehttpstuffthatreturnsjson; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment