Save your connection info (optional)

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 Enterprise, many of the SDK examples and unit tests take command-prompt arguments that specify values for the host, port, scheme, and login credentials. 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 prompt, 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 use a .splunkrc file:

  1. Create a new file named .splunkrc in the current user's home directory.

    On *nix or 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.

  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

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

Keep in mind that if you haven't configured a .splunkrc file, you may need to include host, port, username, password, and scheme arguments as key-value pairs when you run an example from the command line. You don't need to include any keys that take default values.