diff --git a/docs/inputs/helper.md b/docs/inputs/helper.md index 438b025b7..502084586 100644 --- a/docs/inputs/helper.md +++ b/docs/inputs/helper.md @@ -37,7 +37,7 @@ The input script `example_input_one` will import this module and call its method The file must contain the following two functions: - `validate_input(definition: smi.ValidationDefinition)` -- `stream_events(inputs: smi.InputDefinition, event_writer: smi.EventWriter)` +- `stream_events(inputs: smi.InputDefinition, event_writer: smi.EventWriter, modular_input: smi.Script)` ```python from splunklib import modularinput as smi @@ -47,7 +47,7 @@ def validate_input(definition: smi.ValidationDefinition): ... -def stream_events(inputs: smi.InputDefinition, event_writer: smi.EventWriter): +def stream_events(inputs: smi.InputDefinition, event_writer: smi.EventWriter, modular_input: smi.Script): ... ``` diff --git a/splunk_add_on_ucc_framework/templates/input.module-template b/splunk_add_on_ucc_framework/templates/input.module-template index b660a323d..3f32da8f2 100644 --- a/splunk_add_on_ucc_framework/templates/input.module-template +++ b/splunk_add_on_ucc_framework/templates/input.module-template @@ -3,11 +3,11 @@ import json from splunklib import modularinput as smi -def validate_input(definition: smi.ValidationDefinition): +def validate_input(definition: smi.ValidationDefinition, modular_input: smi.Script): return -def stream_events(inputs: smi.InputDefinition, ew: smi.EventWriter): +def stream_events(inputs: smi.InputDefinition, ew: smi.EventWriter, modular_input: smi.Script): input_items = [{'count': len(inputs.inputs)}] for input_name, input_item in inputs.inputs.items(): input_item['name'] = input_name diff --git a/splunk_add_on_ucc_framework/templates/input.template b/splunk_add_on_ucc_framework/templates/input.template index 2b1b4f63c..025df8bb6 100644 --- a/splunk_add_on_ucc_framework/templates/input.template +++ b/splunk_add_on_ucc_framework/templates/input.template @@ -1,6 +1,8 @@ import import_declare_test -{% if not input_helper_module -%} +{% if input_helper_module -%} +import inspect +{% else -%} import json {% endif -%} import sys @@ -42,6 +44,9 @@ class {{class_name}}(smi.Script): def validate_input(self, definition: smi.ValidationDefinition): {%- if input_helper_module %} + validate_input_signature = inspect.signature(validate_input) + if len(validate_input_signature.parameters) == 2: + return validate_input(definition, self) return validate_input(definition) {%- else %} return @@ -49,6 +54,9 @@ class {{class_name}}(smi.Script): def stream_events(self, inputs: smi.InputDefinition, ew: smi.EventWriter): {%- if input_helper_module %} + stream_events_signature = inspect.signature(stream_events) + if len(stream_events_signature.parameters) == 3: + return stream_events(inputs, ew, self) return stream_events(inputs, ew) {%- else %} input_items = [{'count': len(inputs.inputs)}] diff --git a/tests/testdata/expected_addons/expected_addon_after_init/demo_addon_for_splunk/package/bin/demo_input.py b/tests/testdata/expected_addons/expected_addon_after_init/demo_addon_for_splunk/package/bin/demo_input.py index cbf8f7fd3..e4309bba5 100644 --- a/tests/testdata/expected_addons/expected_addon_after_init/demo_addon_for_splunk/package/bin/demo_input.py +++ b/tests/testdata/expected_addons/expected_addon_after_init/demo_addon_for_splunk/package/bin/demo_input.py @@ -28,10 +28,10 @@ def get_scheme(self): return scheme def validate_input(self, definition: smi.ValidationDefinition): - return validate_input(definition) + return validate_input(definition, self) def stream_events(self, inputs: smi.InputDefinition, ew: smi.EventWriter): - return stream_events(inputs, ew) + return stream_events(inputs, ew, self) if __name__ == '__main__': diff --git a/tests/testdata/expected_addons/expected_addon_after_init/demo_addon_for_splunk/package/bin/demo_input_helper.py b/tests/testdata/expected_addons/expected_addon_after_init/demo_addon_for_splunk/package/bin/demo_input_helper.py index 01e036155..f3c1ccb8d 100644 --- a/tests/testdata/expected_addons/expected_addon_after_init/demo_addon_for_splunk/package/bin/demo_input_helper.py +++ b/tests/testdata/expected_addons/expected_addon_after_init/demo_addon_for_splunk/package/bin/demo_input_helper.py @@ -40,7 +40,7 @@ def validate_input(definition: smi.ValidationDefinition): return -def stream_events(inputs: smi.InputDefinition, event_writer: smi.EventWriter): +def stream_events(inputs: smi.InputDefinition, event_writer: smi.EventWriter, modular_input: smi.Script): # inputs.inputs is a Python dictionary object like: # { # "demo_input://": { diff --git a/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/example_input_one.py b/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/example_input_one.py index 620cd317c..9fc48c187 100644 --- a/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/example_input_one.py +++ b/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/example_input_one.py @@ -118,10 +118,10 @@ def get_scheme(self): return scheme def validate_input(self, definition: smi.ValidationDefinition): - return validate_input(definition) + return validate_input(definition, self) def stream_events(self, inputs: smi.InputDefinition, ew: smi.EventWriter): - return stream_events(inputs, ew) + return stream_events(inputs, ew, self) if __name__ == '__main__': diff --git a/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/example_input_two.py b/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/example_input_two.py index f4efbe045..86e7b3e7a 100644 --- a/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/example_input_two.py +++ b/tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/example_input_two.py @@ -88,10 +88,10 @@ def get_scheme(self): return scheme def validate_input(self, definition: smi.ValidationDefinition): - return validate_input(definition) + return validate_input(definition, self) def stream_events(self, inputs: smi.InputDefinition, ew: smi.EventWriter): - return stream_events(inputs, ew) + return stream_events(inputs, ew, self) if __name__ == '__main__': diff --git a/tests/testdata/test_addons/package_global_config_everything/package/bin/example_input_three_helper.py b/tests/testdata/test_addons/package_global_config_everything/package/bin/example_input_three_helper.py index 35efccf55..7a3275026 100644 --- a/tests/testdata/test_addons/package_global_config_everything/package/bin/example_input_three_helper.py +++ b/tests/testdata/test_addons/package_global_config_everything/package/bin/example_input_three_helper.py @@ -7,7 +7,7 @@ def validate_input(definition: smi.ValidationDefinition): return -def stream_events(inputs: smi.InputDefinition, ew: smi.EventWriter): +def stream_events(inputs: smi.InputDefinition, ew: smi.EventWriter, modular_input: smi.Script): # INPUT 3 input_items = [{'count': len(inputs.inputs)}] for input_name, input_item in inputs.inputs.items(): diff --git a/tests/testdata/test_addons/package_global_config_everything/package/bin/helper_one.py b/tests/testdata/test_addons/package_global_config_everything/package/bin/helper_one.py index d9426a540..32a2a2716 100644 --- a/tests/testdata/test_addons/package_global_config_everything/package/bin/helper_one.py +++ b/tests/testdata/test_addons/package_global_config_everything/package/bin/helper_one.py @@ -7,7 +7,7 @@ def validate_input(definition: smi.ValidationDefinition): return -def stream_events(inputs: smi.InputDefinition, ew: smi.EventWriter): +def stream_events(inputs: smi.InputDefinition, ew: smi.EventWriter, modular_input: smi.Script): # INPUT 1 input_items = [{'count': len(inputs.inputs)}] for input_name, input_item in inputs.inputs.items(): diff --git a/tests/testdata/test_addons/package_global_config_everything/package/bin/helper_two.py b/tests/testdata/test_addons/package_global_config_everything/package/bin/helper_two.py index 1891465b8..42c1c5732 100644 --- a/tests/testdata/test_addons/package_global_config_everything/package/bin/helper_two.py +++ b/tests/testdata/test_addons/package_global_config_everything/package/bin/helper_two.py @@ -7,7 +7,7 @@ def validate_input(definition: smi.ValidationDefinition): return -def stream_events(inputs: smi.InputDefinition, ew: smi.EventWriter): +def stream_events(inputs: smi.InputDefinition, ew: smi.EventWriter, modular_input: smi.Script): # INPUT 2 input_items = [{'count': len(inputs.inputs)}] for input_name, input_item in inputs.inputs.items():