This section describes an optional utility you can use with the Splunk SDK for Python.
To connect to Splunk, all of the SDK examples and unit tests take command-line arguments that specify values for the host, port, and login credentials for Splunk. For convenience during development, you can store these arguments as key-value pairs in a text file named .splunkrc. Then, when you don't specify these arguments at the command line, the SDK examples and unit tests use the values from the .splunkrc file.
To set up a .splunkrc file
# Splunk host (default: localhost) host=localhost # Splunk admin port (default: 8089) port=8089 # Splunk username username=admin # Splunk password password=changeme # Access scheme (default: https) scheme=https # Your version of Splunk (default: 5.0) version=5.0
On Mac OS X
Save the file as:
~/.splunkrc
On Windows
Save the file as:
C:\Users\currentusername\.splunkrc
You might get errors in Windows when you try to name the file because ".splunkrc" looks like a nameless file with an extension. You can use the command line to create this file—go to the C:\Users\currentusername directory and enter the following command:
Notepad.exe .splunkrc
Click Yes, then continue creating the file.
Notes
- Storing login credentials in the .splunkrc file is only for convenience during development—this file isn't part of the Splunk platform and shouldn't be used for storing user credentials for production. And, if you're at all concerned about the security of your credentials, just enter them at the command line and don't bother using the .splunkrc file.
- The format of the .splunkrc file has changed between releases. If you are using a preview or beta version of the SDK, some of the newer fields might not be recognized and you might see errors while running the examples. You can either update to the latest version of the SDK, or comment out the app, owner, and version fields.
- The version field is only used by the Splunk SDK for JavaScript.
If you get this type of error:
HTTP 401 Unauthorized -- Login failed
It probably means the .splunkrc file is not set up correctly.
If you get this type of error:
error: no such option: --version
You might be using a preview or beta version of the SDK. The format of the .splunkrc file has changed between releases and some of the newer fields might not be recognized. You can either update to the latest version of the SDK, or comment out the app, owner, and version fields.