All Apps and Add-ons

How to retrieve session without passing hardcoded credentials in python script

Inayath_khan
Path Finder

Hi

i have used,
sessionKey = splunk.auth.getSessionKey(username,password)
credentials = getCredentials(sessionKey)
to get the credentials where i have passed hardcoded crentials in splunk.auth.

but i have to get credentials without passing the hardcoded credentials i have been tried doing

results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()
session_key = str(settings.get('sessionKey'))

unable to get the session can anybody help me in figuring out the issue.

0 Karma
1 Solution

Inayath_khan
Path Finder

I have executed below python script..

import sys, json
import splunk.Intersplunk
import splunklib.client as client

results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()

session_key = str(settings.get('sessionKey'))
splunkService = client.connect(token=session_key)
print session_key
~

I have tried this to get the session key.

View solution in original post

0 Karma

Inayath_khan
Path Finder

I have executed below python script..

import sys, json
import splunk.Intersplunk
import splunklib.client as client

results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()

session_key = str(settings.get('sessionKey'))
splunkService = client.connect(token=session_key)
print session_key
~

I have tried this to get the session key.

0 Karma

starcher
Influencer

Depending on how you are executing the script. If it's triggered from within Splunk maybe something in here will help you. http://www.georgestarcher.com/splunk-stored-encrypted-credentials/ If it's triggered from within Splunk such as an alert action, input etc you can get the active session key of the user that triggered the action.

0 Karma

Inayath_khan
Path Finder

Thanks for the reply starcher,

I have executed below python script..

import sys, json
import splunk.Intersplunk
import splunklib.client as client

results,dummyresults,settings = splunk.Intersplunk.getOrganizedResults()

session_key = str(settings.get('sessionKey'))
splunkService = client.connect(token=session_key)
print session_key
~

I have tried this to get the session key ...whether import splunk.Intersplunk works with splunk 7.0.1 version .. I have been tried executing this ..i didn't get output it's getting strucked at the point splunk.Intersplunk.getOrganizedResults(). And iam not using any splunk-python-SDK libraries to do this task.

Could please tell me is any other way of doing it.

0 Karma

BernardEAI
Communicator

I'm also working on getting this right. My script was also getting stuck at splunk.Intersplunk.getOrganizedResults(). The reason was that the search command I was calling the script from was not generating any results, and I believe getOrganizedResults() was waiting for results to be generated.

I fixed this by adding a generating command (GeneratingCommand) into my script before getOrganizedResults().

0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...