-
-
Save VirtueMe/9145428 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
| //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); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry for the sidetrack.