Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass modular input script as parameter to input helper stream_e… #1342

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions splunk_add_on_ucc_framework/templates/input.module-template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 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 @@ -42,13 +44,19 @@ 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
{%- endif %}

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 @@ -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__':
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 @@ -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__':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
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