Splunk® Enterprise

Developing Dashboards, Views, and Apps for Splunk Web

Download manual as PDF

NOTE - Splunk version 4.x reached its End of Life on October 1, 2013. Please see the migration information.
This documentation does not apply to the most recent version of Splunk. Click here for the latest version.
Download topic as PDF

Setting up a scripted input

This section describes how to set up a scripted input for an app. To illustrate the setup, it uses an example script that polls a database and writes the results to a file. A more detailed version of this example is in Example script that polls a database. That topic provides details on the example, including code examples in Python and Java.

Note: You can write any number and types of scripts in various scripting languages that perform various functions. This example shows the framework for a commonly found script. Adapt this framework according to your needs.

Script to poll a database

This example script does the following:

  • Runs at a regular interval
  • Queries a database
  • Writes the output to a file in a format optimized for Splunk indexing
  • Splunk indexes the file containing the results of the queries.

Directory structure

Place scripts in the bin directory of your app:


Here is the directory structure of the example script for this example. The directory structure for your app might differ.

                           +  bin/
                           |     |
                           |     + last_eventid
                           |     |
                           |     + key
                           |     |
                           |     + output.txt
                           |     |
                           |     + starter_script.sh
                           |     |
                           |     + my_db_poll.py
                           |     |
                           |     + ip2int.py
                           +  default/
                           + inputs.conf
                           + app.conf
                           + . . .

Script files


This is the script that retrieves information from the database. This script does the following:

  • Queries the database and writes the query result to file
  • Defines the format of output data
  • Accesses a database using credentials stored in key
  • Reads last_eventid to determine the next event to read from the database
  • Queries the database at the next event and writes the output to a file


Wrapper script that calls the my_db_poll.py script. In this example, it calls my_db_poll.py with the arguments needed to query the database.

In $SPLUNK_HOME/etc/apps/<appName>/default/inputs.conf, create a stanza that references this wrapper script. In this example, the stanza specifies how often to call the starter script to poll the database.


A helper script to convert IP addresses from integer format to dotted format, and back. This is a type of helper script that formats data better for Splunk to index. You often have helper scripts that aid the main script.


Text file containing username and password encoded in base64 using the python function base64.b64encode(). The Splunk user has read and write access to this file.

Security for passwords is an issue when running scripts.


File containing a number for the last event received from the database. my_db_poll.py writes the last_eventid after querying the database. The Splunk user has read and write access to this file.


A single event from the script, for reference. my_db_poll.py writes the actual output from querying the database to another directory.


Configure scripted data input in $SPLUNK_HOME/etc/<appName>/default/inputs.conf. Use the local directory for the app to overwrite behavior defined in the default directory. Here is an example:

# change to false to start the input, requires restart
disabled = true 
# enter hostname 
host = 
index = main
# frequency to run the script
interval = 30 	
source = my_db
sourcetype = my_db_data


Configure properties for the script in the app's local directory props.conf:

TIME_PREFIX = ^[^\|]+\|
# look ahead 10 characters
# search time field extraction with transforms.conf
REPORT-fieldextraction = my_db_extractions


Define attributes for search time field extraction in transforms.conf:

DELIMS = "|"
FIELDS ="EventID","AlertTime","UserName",. . ."
Scripted inputs overview
Writing reliable scripts

This documentation applies to the following versions of Splunk® Enterprise: 4.3, 4.3.1, 4.3.2, 4.3.3, 4.3.4, 4.3.5, 4.3.6, 4.3.7

Was this documentation topic helpful?

Enter your email address, and someone from the documentation team will respond to you:

Please provide your comments here. Ask a question or make a suggestion.

You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters