Skip to content

Instantly share code, notes, and snippets.

@VirtueMe
Forked from glennblock/modInput_1.js
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save VirtueMe/9145428 to your computer and use it in GitHub Desktop.

Select an option

Save VirtueMe/9145428 to your computer and use it in GitHub Desktop.
//modinput.js
var splunk = require('splunk-sdk');
var DataType = splunk.modularInput.DataType;
exports.getScheme = function() {
var scheme = {
'Random Numbers',
'Streams events containing a random number',
['name', 'description', 'type', 'requiredOnCreate'],
[
[
'min',
'Minimum random number to be produced by this input.',
DataType.number,
true
],
[
'max',
'Minimum random number to be produced by this input.',
DataType.number,
true
]
]
};
return scheme;
}
exports.validateInput(definition) {
var min = parseFloat(definition.min);
var max = parseFloat(definition.max);
if (min < max)
throw sprintf('min must be less than max; found min=%f, max=%f', min, max);
}
//we will invoke this for each input so a developer does not have to write boilerplate looping code.
//they can check the inputName if they are supporting multiple instances.
exports.streamEvents = function(inputName, inputItem, ew) {
var min = parseFloat(inputItem.min);
var max = parseFloat(inputItem.max);
event = {
stanza: inputName,
data: sprintf('number=%s', Math.floor((Math.random()*max)+min));
}
ew.write(event);
}
@VirtueMe
Copy link
Author

Sorry for the sidetrack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment