Developing for Splunk Enterprise

Create a HTML form that post to a python script

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

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
Don’t Miss Global Splunk
User Groups Week!

Free LIVE events worldwide 2/8-2/12
Connect, learn, and collect rad prizes
and swag!