Save your connection info

You can save your Splunk® Enterprise host, port, and scheme (HTTP or HTTPS) information—and even your login credentials—for examples and unit tests. This might make it easier to run them, since you will not need to specify this information every time you run a sample.

To connect to Splunk, the server-side 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.

Important: Storing user 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 prompt rather than saving them in the .splunkrc file.

To set up a .splunkrc file

  1. Create a new text file and name it .splunkrc.

    Windows might display an error when you try to name the file because ".splunkrc" looks like a nameless file with just an extension. You can use the Command Prompt window to create this file by going to the C:\Users\currentusername directory and entering the following at the prompt:


    Notepad.exe .splunkrc



    A dialog box appears, asking whether you want to create a new file. Click Yes, and then continue creating the file.

  2. In the new file, paste in the following. Update any lines that contain information that differs from your Splunk Enterprise instance. # 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
    # Splunk version number
    version=5.0
  3. Save the file in the current user's home directory.

    On OS X or Linux

    ~/.splunkrc

    On Windows

    C:\Users\currentusername\.splunkrc

The examples and unit tests are ready to run with no additional connection arguments required!

Notes

  • The version argument is required in Splunk 5.0 and later.
  • 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.