As our custom_endpoint.py stands right now it is simply using the hardcoded data in the file and using that to POST to our custom endpoint. Now we want to modify our custom_endpoint.py file to take the data we POST to it and return it so we can see the format the data is sent to our custom endpoint.
Feel free to follow along with the blog post and/or the screencast links that are included below and throughout the post.
Cleaning Our POST Data
You can view the related screencast here.
Part of the request that comes into Splunk when POSTing data to it is the payload. This is the data that we will be sending from our form. We can access this through our handle_POST method’s request like so:
Go ahead and open up the custom_endpoint.py script inside of your app’s bin folder. Modify your handle_POST method so it looks like this:
Here is what we are doing:
- Right now all we are interested in seeing that the script can handle the request and then provide a response by simply returning the data we send it.
- First define the payload.
- Then, write out the payload in a string format back to the browser. We will wait for this response on our dashboard.
- Once you make the changes save the file.
Go back to the dashboard, fill out the form and then click the Submit button. I entered ‘batman’ for my user and ‘admin’ for my role. In the console the response should look something like this: