
Setup screen example with user credentials
This example shows the steps needed to create a set up screen that accepts user/password credentials for a python script. The python script uses the credentials supplied in the setup screen.
- Create the block in your setup screen that accepts user credentials.
- Write a python script that uses the credentials
- Create a stanza in
inputs.conf
for your script.
1. Create a block in setup.xml that accepts user credentials
Add the following block to setup.xml
to create the User input fields for your scripts. Place the block between setup tags.
<setup> <block title="Add new credentials" endpoint="storage/passwords" entity="_new"> <input field="name"> <label>Username</label> <type>text</type> </input> <input field="password"> <label>Password</label> <type>password</type> </input> <!-- Remove the realm input field if your app is not using realm --> <input field="realm"> <label>Realm</label> <type>text</type> </input> </block> </setup>
2. Write a python script that uses credentials
Here is the path to the example script:
$SPLUNK_HOME/etc/apps/<MyApp>/default/bin/MyInputScript.py
MyInputScript.py
import splunk.entity as entity . . . # access the credentials in /servicesNS/nobody/<MyApp>/admin/passwords def getCredentials(sessionKey): myapp = 'name-of-your-app-here' try: # list all credentials entities = entity.getEntities(['admin', 'passwords'], namespace=myapp, owner='nobody', sessionKey=sessionKey) except Exception, e: raise Exception("Could not get %s credentials from splunk. Error: %s" % (myapp, str(e))) # return first set of credentials for i, c in entities.items(): return c['username'], c['clear_password'] raise Exception("No credentials have been found") def main(): # read session key sent from splunkd sessionKey = sys.stdin.readline().strip() if len(sessionKey) == 0: sys.stderr.write("Did not receive a session key from splunkd. " + "Please enable passAuth in inputs.conf for this " + "script\n") exit(2) # now get twitter credentials - might exit if no creds are available username, password = getCredentials(sessionKey) # use the credentials to access the data source . . .
3. Create a stanza in inputs.conf
Here is the path to inputs.conf
for the example:
$SPLUNK_HOME/etc/apps/<MyApp>/default/inputs.conf
Add the following stanza to inputs.conf
:
[script://./bin/MyInputScript.py] . . . passAuth = splunk-system-user
PREVIOUS Setup screen example using a custom endpoint |
NEXT How to restrict your users to one app |
This documentation applies to the following versions of Splunk® Enterprise: 6.3.0, 6.3.1, 6.3.2, 6.3.3, 6.3.4, 6.3.5, 6.3.6, 6.3.7, 6.3.8, 6.3.9, 6.3.10, 6.3.11, 6.3.12, 6.3.13, 6.3.14, 6.4.0, 6.4.1, 6.4.2, 6.4.3, 6.4.4, 6.4.5, 6.4.6, 6.4.7, 6.4.8, 6.4.9, 6.4.10, 6.4.11
Feedback submitted, thanks!