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!

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...

Splunk Up Your Game: Why It's Time to Embrace Python 3.9+ and OpenSSL 3.0

Did you know that for Splunk Enterprise 9.4, Python 3.9 is the default interpreter? This shift is not just a ...