Skip to content

Commit

Permalink
feat: pass modular input script as parameter to input helper stream_e…
Browse files Browse the repository at this point in the history
…vents
  • Loading branch information
Benni0 committed Sep 16, 2024
1 parent bc6a36b commit 3411ff2
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/inputs/helper.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
...
```

Expand Down
7 changes: 6 additions & 1 deletion splunk_add_on_ucc_framework/templates/input.template
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -49,6 +51,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)}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def validate_input(self, definition: smi.ValidationDefinition):
return validate_input(definition)

def stream_events(self, inputs: smi.InputDefinition, ew: smi.EventWriter):
return stream_events(inputs, ew)
return stream_events(inputs, ew, self)


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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://<input_name>": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def validate_input(self, definition: smi.ValidationDefinition):
return validate_input(definition)

def stream_events(self, inputs: smi.InputDefinition, ew: smi.EventWriter):
return stream_events(inputs, ew)
return stream_events(inputs, ew, self)


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def validate_input(self, definition: smi.ValidationDefinition):
return validate_input(definition)

def stream_events(self, inputs: smi.InputDefinition, ew: smi.EventWriter):
return stream_events(inputs, ew)
return stream_events(inputs, ew, self)


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 3411ff2

Please sign in to comment.