Splunk Dev

Create a HTML form that post to a python script

splunkcvc
New Member

I have a html page with a form and want the the form to submit to a python script.

Questions:
Where under a custom app would you place the python script?
What url would I put in the form action to hit the script?

Tags (1)
0 Karma

LukeMurphey
Champion

I would use a SplunkWeb controller for this. Here is how you would make it:

Step 1: Make the controller binary

Make an executable in the app under the path: $SPLUNK_HOME/etc/apps//appserver/controllers/. If your controller was called my_custom_controller, it would be under: $SPLUNK_HOME/etc/apps/appserver/controllers/my_custom_controller.py.

See the following example of a Splunk controller: https://github.com/LukeMurphey/splunk-web-input/blob/master/src/appserver/controllers/web_input_cont...

Step 2: Expose the controller

Make a web.conf in the app under the path: $SPLUNK_HOME/etc/apps//default/web.conf. Add a line to this file that exposes your controller. Below is an example (assuming your controller is named called my_custom_controller.py):

[endpoint:my_custom_controller]

Restart Splunk for the controller to be visible. You can verify that your controller is recognized by navigating to /paths with your browser (e.g. http://mysplunkserver/paths); your controller should be listed if this worked (just search for your controller name, e.g. "my_custom_controller").

Step 3: Wire-up your HTML form

Your controller will be exposed under the path /custom//my_custom_controller. For example, if you declared a function called "do_something" within your controller called "my_custom_controller" which is included the in the "my_app" app, then you could access that function from an HTML form with the URL "/custom/my_app/my_custom_controller/do_something").

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...