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?
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):
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):
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')
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):
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
Modules are created in Javascript, not Python. What Python module are you referring to? What are you trying to achieve?