Hello,
I'm quite new to splunk and I'm stuck somewhere...
My goal:
Sending data from a Splunk view (a webpage I created from the splunk web interface), process some fields in a custom REST endpoint and store them in the KV store.
What I have:
I already have the custom endpoint working, I can handle in py python script flat javascript value received but not enclosed objects.
Javascript (attached to a basic html form created in splunk interface):
...
data['name'] = aJsStringValue; // I can handle this in pyhton
data['list'][0] = aJsObject; // I failed
var service = mvc.createService();
service.post('/services/test', data, function(err, response) {
...
}
...
Python:
...
class test(splunk.rest.BaseRestHandler):
def handle_POST(self):
try:
...
name = ''
list = []
# parse the payload
payload = self.request['payload']
for el in payload.split('&'):
key, value = el.split('=')
if 'name' in key:
name = value
if 'list' in key:
# idk
...
My problem:
I want to send a list of dictionaries inside my javascript object but I don't know how to handle it in python.
I wanted to use Json and put a String directly as "params" value for the "service.post()" but it is obviously interpreted as an array.
I could do a workaround, use "JSON.stringify(data);" and place the string in a simple field "data" but I would like to know if a better way exists?
Note: I can change all the structure if needed.
Thanks.
... View more