This documentation does not apply to the most recent version of Splunk.
This documentation applies to the following versions of Splunk: 3.3 , 3.3.1 , 3.3.2 , 3.3.3 , 3.3.4 , 3.4 , 3.4.1 , 3.4.2 , 3.4.3 , 3.4.5 , 3.4.6 , 3.4.8 , 3.4.9 , 3.4.10 , 3.4.11 , 3.4.12 , 3.4.13
By configuring inputs.conf, Splunk can accept events from scripts. Scripted input is useful for command-line tools, such as vmstat, iostat, netstat, top, etc.
Note: Currently, scripted inputs do not get sent via the deployment server. In the future, Splunk will support this behavior. For now, use your preferred configuration automation tool to push your script directory to your server classes.
Note: On Windows platforms, use of text-based scripts such those in perl and python can be handled via the use of an intermediary window 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).
Configure inputs.conf, using the following attributes:
[script://$SCRIPT] interval = X index = <index> sourcetype = <iostat, vmstat, etc> OPTIONAL source = <iostat, vmstat, etc> OPTIONAL disabled = <true | false>
script is the fully-qualified path to the location of the script.
bin/ directory nearest the inputs.conf where 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/.
interval is in seconds.
index can be any index in your Splunk instance.
main.
disabled is a boolean value that can be set to true if you want to disable the input.
false.
sourcetype and source can be any value you'd like.
sourcetype= or source= fields.
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.
This example shows the use of the UNIX top command as a data input source.
scripts/:
$ mkdir $SPLUNK_HOME/etc/apps/scripts
bin/ directory inside your application directory:
$ mkdir $SPLUNK_HOME/etc/apps/scripts/bin
top.sh:
$ #!/bin/sh top -bn 1 # linux only - different OSes have different paramaters
chmod +x $SPLUNK_HOME/etc/apps/scripts/bin/top.sh
$SPLUNK_HOME/etc/apps/scripts/bin/top.sh
top output.
inputs.conf in $SPLUNK_HOME/etc/apps/scripts/default/:
[script:///opt/splunk/etc/apps/scripts/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
You may need to modify props.conf:
top entry into multiple events.
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