TABLE OF CONTENTS
This script builds out a Splunk KVStore from a csv file.
More information about Splunk KVStore - how it differs from a simple lookup and when to use it, is explained thoroughly in Splunk's documentation.
Setup is pretty simple
- Use python >= 3.7, and install the modules in
requirements.txt
. - Set desired values in the configuration file. The file must be in the
*.ini
format that can be read by python'sconfigparser
. By default the script reads fromsplunk_kvstore.ini
. - The input file to create the kvstore from (specified in the configuration file) must be a valid
*.csv
file and located in same directory as the script
Other Requirements:
- Splunk user account with administrator privileges
- The splunk server, and your system, need to be configured to allow interaction with the REST API over port 8089. The REST API can be interacted with and tested using
curl
and making sure you can pull and push data. Below is an example command to pull a list of apps using the Splunk REST API.curl -k -u username:pass https://<SPLUNK_SERVER>:8089/services/apps/local
Run the script with
python3 csv2kvstore.py
WARNING: This script will make minor configuration changes to Splunk if needed to match settings in the configuration file.
The script will use the REST API to check for the KV Store collection on the splunk server, creating one if it does not exist. Collections are normally defined in collections.conf
at the location $SPLUNK_HOME/etc/apps/SPLUNK_APP_WITH_COLLECTION/local/collections.conf
.
The script will also check for the collection's stanza in limits.conf
and set the max_documents_per_batch_save
value, updating the configuration if needed to match the script's config file.
After verifying settings are correct the script reads the csv file and pushes it in chunks to the KV Store collection.
The script will write to the log file specified in the configuration (default is csv2splunk.log
).
To get verbose output to stdout, set DEBUG_MODE = 1
in the configuration file. Otherwise, the log file will contain all logging.
To use the KV Store, a lookup needs to be defined. This can be done through the Web UI, or with an entry like the below in transforms.conf
:
[LOOKUP_NAME]
external_type = kvstore
collection = COLLECTION_NAME
fields_list = <LIST_OF_FIELD_NAMES>
To view the kvstore-based lookup, type the following into the Splunk searchbar:
| inputlookup LOOKUP_NAME