Splunk Dev

pass xml param to python module

Benomran
Explorer

In the documentations, it shows how you can send param value to your java script (js) file but it does not show how to send to python file within the same module. I tried playing around with generateResults but got nowhere. Unless I missed something, I am lost.

Examples 7 had something like this, but is limited to only 4 arguments:

def generateResults(self, host_app, client_app, sid, count=1000, offset=0, entity_name='results'):

I already included my param in the conf file:

[param:startsize]
required = False
default = 8
label = This parameter defines start scale size.

[param:endsize]
required = False
default = 70
label = This parameter defines end scale size.

What is the proper way to pull the parameter value into python?

0 Karma
1 Solution

ziegfried
Influencer

The parameters the python endpoint receives are sent by the javascript part of the module. You can override the generation of this parameter list:

<app>/appserver/module/MyFunkyModule/MyFunkyModule.js

Splunk.Module.MyFunkyModule = $.klass(Splunk.Module.DispatchingModule, {
   ...
    getResultParams: function($super) {
        var params = $super();
        params['startsize'] = this.getParam('startsize');
        params['endsize'] = this.getParam('endsize');
        return params;
    }
   ...
}

then you'll be able to use it in python:

<app>/appserver/module/MyFunkyModule/MyFunkyModule.py

def generateResults(self, host_app, client_app, sid, count=1000, offset=0, entity_name='results', startsize, endsize):

View solution in original post

ziegfried
Influencer

The parameters the python endpoint receives are sent by the javascript part of the module. You can override the generation of this parameter list:

<app>/appserver/module/MyFunkyModule/MyFunkyModule.js

Splunk.Module.MyFunkyModule = $.klass(Splunk.Module.DispatchingModule, {
   ...
    getResultParams: function($super) {
        var params = $super();
        params['startsize'] = this.getParam('startsize');
        params['endsize'] = this.getParam('endsize');
        return params;
    }
   ...
}

then you'll be able to use it in python:

<app>/appserver/module/MyFunkyModule/MyFunkyModule.py

def generateResults(self, host_app, client_app, sid, count=1000, offset=0, entity_name='results', startsize, endsize):

jleduc
Explorer

you have to set your parameters before the ones that have a default value: count, offset...

otherwise you won't be able to start the web service:
with this error:
def generateResults(self, host_app, client_app, sid, count=1000,
SyntaxError: non-default argument follows default argument

So here is what you should use now:
def generateResults(self, host_app, client_app, sid, startsize, endsize, count=1000, offset=0, entity_name='results')

0 Karma

Benomran
Explorer

Thank you! I Got it to work with minor adjustment. 😉

For those who may run into this I am including additional information I encountered;
Error: [non-default argument follows default argument]
Fix: Set defaults...

def generateResults(self, host_app, client_app, sid, count=1000, offset=0, entity_name='results', startsize=8, endsize=70):

0 Karma

Benomran
Explorer

Sorry was not clear; like many modules (example 6), they contain a python file which renders the output. My python displays a div tag and calls in a third-party JavaScript. While calling the JavaScript, I would like to modify size value from my XML file which will pass it on to my python file.

Hope that explains what I am trying to achieve!

Thank you

0 Karma

Ayn
Legend

Modules are created in Javascript, not Python. What Python module are you referring to? What are you trying to achieve?

0 Karma
Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Enhance Security Operations with Automated Threat Analysis in the Splunk EcosystemAre you leveraging ...

Splunk Developers: Go Beyond the Dashboard with These .Conf25 Sessions

  Whether you’re building custom apps, diving into SPL2, or integrating AI and machine learning into your ...

Index This | How do you write 23 only using the number 2?

July 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...