-
-
Save VirtueMe/9145773 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 = { | |
| name: 'Random Numbers', | |
| description: 'Streams events containing a random number' | |
| arguments: [ | |
| { | |
| name: 'min', | |
| desc: 'Minimum random number to be produced by this input.', | |
| type: DataType.number, | |
| requiredOnCreate: true | |
| }, | |
| { | |
| name: 'max', | |
| desc: 'Minimum random number to be produced by this input.', | |
| type: DataType.number, | |
| requiredOnCreate: true | |
| } | |
| ] | |
| }; | |
| return scheme; | |
| } | |
| exports.validateInput(definition) { | |
| var min = parseFloat(definition.min); | |
| var max = parseFloat(defintiion.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); | |
| } |
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 | |
| //this variant introduces an Argument class to make the syntax terser. | |
| var splunk = require('splunk-sdk'); | |
| var DataType = splunk.modularInput.DataType; | |
| var RequiredOnCreate = splunk.modularInput.Argument.RequiredOnCreate; | |
| exports.getScheme = function() { | |
| var scheme = { | |
| name: 'Random Numbers', | |
| desc: 'Streams events containing a random number' | |
| args: [ | |
| // this part seems to screem ** let us make a tool that autogenerates the initialization part of it ** | |
| new RequiredOnCreate('min', 'Minimum random number to be produced by this input.', DataType.number), | |
| new RequiredOnCreate('max', 'Maximum random number to be produced by this input', DataType.number) | |
| ] | |
| }; | |
| 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); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment