Set up custom (scripted) inputs
This documentation does not apply to the most recent version of Splunk. Click here for the latest version.
Contents
Set up custom (scripted) inputs
Splunk can accept events from scripts that you provide. Scripted input is useful for command-line tools, such as vmstat, iostat, netstat, top, etc. Get data from APIs and other remote data interfaces and message queues and generate metrics and status data from exercising system and app status commands like vmstat, iostat, etc. Lots of apps on Splunkbase provide scripted inputs for specific applications as well--you can find them on the Browse more apps tab in the Launcher.
You can configure custom scripted inputs from Splunk Manager in Splunk Web, or by editing inputs.conf.
Note: On Windows platforms, you can enable text-based scripts such those in perl and python with an intermediary Windows batch (.bat) file.
Caution: Scripted input-launched scripts inherit Splunk's environment, so be sure to clear environment variables which may affect your script's operation. The only environment variable that's likely to cause problems is the library path (most commonly known as LD_LIBRARY_PATH on linux/solaris/freebsd).
Add a scripted input in Splunk Web
To add a scripted input in Splunk Web:
1. Click Manager in the upper right-hand corner of Splunk Web.
2. Under System configurations, click Data Inputs.
3. Click Scripts.
4. Click New to add an input.
5. Provide the path to the script and the interval in seconds between script runtimes.
6. Optionally, set the Source Type. Source type is a default field added to events. Source type is used to determine processing characteristics such as timestamps and event boundaries. If you set this to automatic, Splunk will classify and assign sourcetype automatically. Unknown sourcetypes will be given a placeholder name.
7. Optionally, set the destination index for the data from this source. If you leave this set to default, the data will be sent to the main index.
Add a scripted input via inputs.conf
Configure inputs.conf using the following attributes:
[script://$SCRIPT] interval = <integer>|<cron schedule> index = <index> sourcetype = <iostat, vmstat, etc> OPTIONAL source = <iostat, vmstat, etc> OPTIONAL disabled = <true | false>
-
scriptis the path to the location of the script.- As a best practice, put your script in the
bin/directory nearest theinputs.confwhere your script is specified. So if you are configuring$SPLUNK_HOME/etc/system/local/inputs.conf, place your script in$SPLUNK_HOME/etc/system/bin/. If you're working on an application in$SPLUNK_HOME/etc/apps/$APPLICATION/, put your script in$SPLUNK_HOME/etc/apps/$APPLICATION/bin/. - The path to the script must be either fully-qualified from the root directory, or it must begin with
./bin. If it is neither, it will be treated as if it were relative to root directory. If it is in./binit will be treated as relative to$SPLUNK_HOME/etc/apps/$APPLICATION. If it begins with./bin, it cannot reference directories above./bin; that is, the path cannot contain a../component or it will be ignored.
- As a best practice, put your script in the
-
intervalindicates how often to execute the specified command. Specify either an integer value representing seconds or a valid cron schedule.- Defaults to 60 seconds.
- When a cron schedule is specified, the script is not executed on start up.
- Splunk keeps one invocation of a script per instance. Intervals are based on when the script completes. So if you have a script configured to run every 10 minutes and the script takes 20 minutes to complete, the next run will occur 30 minutes after the first run.
- For constant data streams, enter 1 (or a value smaller than the script's interval).
- For one-shot data streams, enter -1. Setting
intervalto -1 will cause the script to run each time the splunk daemon restarts.
-
indexcan be any index in your Splunk instance.- Default is
main.
- Default is
-
disabledis a boolean value that can be set to true if you want to disable the input.- Defaults to
false.
- Defaults to
-
sourcetypeandsourcecan be any value you'd like.- The value you specify is appended to data coming from your script in the
sourcetype=orsource=fields. - These are optional settings.
- The value you specify is appended to data coming from your script in the
If you want the script to run continuously, write the script to never exit and set it on a short interval. This helps to ensure that if there is a problem the script gets restarted. Splunk keeps track of scripts it has spawned and will shut them down upon exit.
Example using inputs.conf
This example shows the use of the UNIX top command as a data input source.
- Start by creating a new application directory. This example uses
scripts/:
$ mkdir $SPLUNK_HOME/etc/apps/scripts
- All scripts should be run out of a
bin/directory inside your application directory: -
$ mkdir $SPLUNK_HOME/etc/apps/scripts/bin - This example uses a small shell script
top.sh:
$ #!/bin/sh top -bn 1 # linux only - different OSes have different paramaters
- Make sure the script is executable:
chmod +x $SPLUNK_HOME/etc/apps/scripts/bin/top.sh
- Test that the script works by running it via the shell:
$SPLUNK_HOME/etc/apps/scripts/bin/top.sh
- The script should have sent one
topoutput. - Add the script entry to
inputs.confin$SPLUNK_HOME/etc/apps/scripts/default/:
[script://./bin/top.sh] interval = 5 # run every 5 seconds sourcetype = top # set sourcetype to top source = script://./bin/top.sh # set source to name of script
props.conf
You may need to modify props.conf:
- By default Splunk breaks the single
topentry into multiple events. - The easiest way to fix this problem is to tell the Splunk server to break only before something that does not exist in the output.
For example, adding the following to $SPLUNK_HOME/etc/apps/scripts/default/props.conf forces all lines into a single event:
[top] BREAK_ONLY_BEFORE = <stuff>
Since there is no timestamp in the top output we need to tell Splunk to use the current time. This is done in props.conf by setting:
DATETIME_CONFIG = CURRENT
This documentation applies to the following versions of Splunk: 4.0 , 4.0.1 , 4.0.2 , 4.0.3 , 4.0.4 , 4.0.5 , 4.0.6 , 4.0.7 , 4.0.8 , 4.0.9 , 4.0.10 , 4.0.11 View the Article History for its revisions.