1313# under the License.
1414
1515from abc import ABCMeta , abstractmethod
16+ import sys
17+
18+ from splunklib .modularinput .event_writer import EventWriter
1619from splunklib .modularinput .input_definition import InputDefinition
1720from splunklib .modularinput .validation_definition import ValidationDefinition
18- from splunklib .modularinput .event_writer import EventWriter
19- import sys
2021
2122try :
2223 import xml .etree .cElementTree as ET
@@ -28,28 +29,32 @@ class Script(object):
2829 """An abstract base class for implementing modular inputs.
2930
3031 Subclasses should override get_scheme, stream_events,
31- and optional validate_input if the modular Input uses
32+ and optionally validate_input if the modular Input uses
3233 external validation.
3334
34- The important function is run, which is used to run modular inputs
35+ The run function is used to run modular inputs, it typically should
36+ not be overridden.
3537 """
3638 __metaclass__ = ABCMeta
3739
3840 def run (self , args ):
39- """This function is stable, call run to run a modular input
41+ """Run this modular input
4042
41- :param args: String[] args from Java
42- :return:
43+ :param args: list of command line arguments passed to this script
44+ :return: an integer to be used as the exit value of this program
4345 """
46+
47+ # call the run_script function, which handles the specifics of running
48+ # a modular input
4449 return self .run_script (args , EventWriter (), sys .stdin )
4550
4651 def run_script (self , args , event_writer , input_stream ):
4752 """Handles all the specifics of running a modular input
4853
49- :param args:
50- :param event_writer:
51- :param input_stream:
52- :return:
54+ :param args: list of command line arguments passed to this script
55+ :param event_writer: an EventWriter object for writing events
56+ :param input_stream: an input stream for reading inputs
57+ :return: an integer to be used as the exit value of this program
5358 """
5459
5560 try :
@@ -83,9 +88,9 @@ def run_script(self, args, event_writer, input_stream):
8388 event_writer .write_xml_document (root )
8489
8590 return 1
86-
87- err_string = "ERROR Invalid arguments to modular input script:" + ' ' .join (args )
88- event_writer ._err .write (err_string )
91+ else :
92+ err_string = "ERROR Invalid arguments to modular input script:" + ' ' .join (args )
93+ event_writer ._err .write (err_string )
8994
9095 except Exception as e :
9196 err_string = EventWriter .ERROR + e .message
@@ -112,6 +117,8 @@ def validate_input(self, definition):
112117
113118 :param definition: The parameters for the proposed input passed by splunkd
114119 """
120+ pass
121+
115122 @abstractmethod
116123 def stream_events (self , inputs , ew ):
117124 """The method called to stream events into Splunk. It should do all of its output via
@@ -120,4 +127,3 @@ def stream_events(self, inputs, ew):
120127 :param inputs: an InputDefinition object
121128 :param ew: an object with methods to write events and log messages to Splunk
122129 """
123- return
0 commit comments