Find file
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (56 sloc) 2.33 KB
Credentials Stored in Splunk Credentials Class file
class credential:
""" Credential object:
app: the Splunk app storing the credential
realm: the system needing the credential
username: the username for the credential
password: the credential's password or key
access the credentials in /servicesNS/nobody/<myapp>/storage/passwords
def __init__(self, app, realm, username): = app
self.realm = realm
self.username = username
self.password = ""
def __str__(self):
"""Function Override: Print credential object
return 'App:%s Realm:%s Username:%s Password:%s\r\n'% (,self.realm,self.username,self.password)
def getPassword(self, sessionkey):
import splunk.entity as entity
import urllib
if len(sessionkey) == 0:
raise Exception, "No session key provided"
if len(self.username) == 0:
raise Exception, "No username provided"
if len( == 0:
raise Exception, "No app provided"
# list all credentials
entities = entity.getEntities(['admin', 'passwords'],, owner='nobody', sessionKey=sessionkey)
except Exception, e:
raise Exception, "Could not get %s credentials from splunk. Error: %s" % (, str(e))
for i, c in entities.items():
if (c['realm'] == self.realm and c['username'] == self.username):
self.password = c['clear_password']
raise Exception, "No credentials have been found"
def main():
import os
import sys
sessionKey = 'test'
realm = 'googledocs'
app = 'myadmin'
username = 'googleusername'
splunkCredential = credential(app,realm,username)
print splunkCredential
if __name__ == "__main__":
"""You will get an error on importing the Splunk entity class if not run via the Splunk context
try $SPLUNK_PATH/bin/splunk cmd python
You will still get an error without a valid session key so just expect an error when testing by hand