Skip to content

Commit 0b1d678

Browse files
author
Shakeel Mohamed
committed
More code cleanup
1 parent 47bbfde commit 0b1d678

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

splunklib/modularinput/argument.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,14 @@ def add_to_document(self, parent):
8484
if self.validation is not None:
8585
ET.SubElement(arg, "validation").text = self.validation
8686

87-
ET.SubElement(arg, "data_type").text = self.data_type.lower()
88-
ET.SubElement(arg, "required_on_edit").text = str(self.required_on_edit).lower()
89-
ET.SubElement(arg, "required_on_create").text = str(self.required_on_create).lower()
87+
# add all other subelements to this Argument, represented by (tag, text)
88+
subelements = [
89+
("data_type", self.data_type),
90+
("required_on_edit", self.required_on_edit),
91+
("required_on_create", self.required_on_create)
92+
]
93+
94+
for name, value in subelements:
95+
ET.SubElement(arg, name).text = str(value).lower()
9096

9197
return arg

splunklib/modularinput/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def write_to(self, stream):
8888
if self.time is not None:
8989
ET.SubElement(event, "time").text = str(self.time)
9090

91-
# add all other subelements to this event, represented by (tag, text)
91+
# add all other subelements to this Event, represented by (tag, text)
9292
subelements = [
9393
("source", self.source),
9494
("sourceType", self.sourceType),

splunklib/modularinput/event_writer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15-
from splunklib.modularinput.event import ET
1615
import sys
1716

17+
from splunklib.modularinput.event import ET
18+
1819
try:
1920
from cStringIO import StringIO
2021
except ImportError:

splunklib/modularinput/input_definition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import xml.etree.cElementTree as ET
1515
except ImportError as ie:
1616
import xml.etree.ElementTree as ET
17+
1718
from utils import parse_xml_data
1819

1920
class InputDefinition:

splunklib/modularinput/scheme.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ def to_xml(self):
6464
if self.description is not None:
6565
ET.SubElement(root, "description").text = self.description
6666

67-
# add other subelements; represented by (tag, text)
67+
# add all other subelements to this Scheme, represented by (tag, text)
6868
subelements = [
69-
("use_external_validation", str(self.use_external_validation).lower()),
70-
("use_single_instance", str(self.use_single_instance).lower()),
71-
("streaming_mode", self.streaming_mode.lower())
69+
("use_external_validation", self.use_external_validation),
70+
("use_single_instance", self.use_single_instance),
71+
("streaming_mode", self.streaming_mode)
7272
]
7373
for name, value in subelements:
74-
ET.SubElement(root, name).text = value
74+
ET.SubElement(root, name).text = str(value).lower()
7575

7676
endpoint = ET.SubElement(root, "endpoint")
7777

splunklib/modularinput/script.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
# under the License.
1414

1515
from abc import ABCMeta, abstractmethod
16+
import sys
17+
18+
from splunklib.modularinput.event_writer import EventWriter
1619
from splunklib.modularinput.input_definition import InputDefinition
1720
from splunklib.modularinput.validation_definition import ValidationDefinition
18-
from splunklib.modularinput.event_writer import EventWriter
19-
import sys
2021

2122
try:
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

splunklib/modularinput/validation_definition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import xml.etree.cElementTree as ET
1818
except ImportError as ie:
1919
import xml.etree.ElementTree as ET
20+
2021
from utils import parse_xml_data
2122

2223
class ValidationDefinition(object):

0 commit comments

Comments
 (0)