Splunk Dev

Setup.xml: Is there a way to get the current session key in custom endpoint?

phoenixdigital
Builder

Hi All,

Working from this example
http://dev.splunk.com/view/webframework-developapps/SP-CAAAE9B

Is there any way to get the current session key in the custom endpoint MyApp_python_handler.py

I need to perform some calls against the REST interface and don't want to have to hardcode Splunk usernames and passwords in the python script.

I've tried

config_str = sys.stdin.read()
doc = xml.dom.minidom.parseString(config_str)
root = doc.documentElement
session_key = root.getElementsByTagName("sessionKey")[0].firstChild.data

And it throws an error

ERROR AdminManagerExternal - <class 'splunk.admin.UsageException'>: Received no serialized data via stdin (mode: setup). Will not continue.

However even though it throws that error it is pulling in the session key because I can see it by adding a print at the end

config_str = sys.stdin.read()
doc = xml.dom.minidom.parseString(config_str)
root = doc.documentElement
session_key = root.getElementsByTagName("sessionKey")[0].firstChild.data
print("type=readStdIn,session_key=%s" % session_key)

Error in splunkd which is to be expected because I shouldn't be printing this out. I tried using logging.info but that doesn't show up in logs.

01-19-2017 13:11:13.762 +1000 ERROR AdminManagerExternal - Unable to xml-parse the following data: %stype=readStdIn,session_key=jW3neEYMJ29lzdDyPm0OVW6g5XmTR_tVd0jErcj^T3cuEASlQAfs5F2xhFw_k3TMTwqF3uyYZTNQ2L9PLUYFRvYnnHYqqB9oeUP^zQ...  See splunkd.log for full data.
0 Karma
1 Solution

phoenixdigital
Builder

I may have found it

self.getSessionKey()

View solution in original post

0 Karma

phoenixdigital
Builder

I may have found it

self.getSessionKey()

0 Karma

christoffertoft
Communicator

@phoenixdigital what is the "self" object you are referring to here? I'm having issues getting session key in a scripted input running on windows, but it works in linux environments.


Best regarss

0 Karma
Get Updates on the Splunk Community!

Prove Your Splunk Prowess at .conf25—No Prereqs Required!

Your Next Big Security Credential: No Prerequisites Needed We know you’ve got the skills, and now, earning the ...

Splunk Observability Cloud's AI Assistant in Action Series: Observability as Code

This is the sixth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how to ...

Splunk Answers Content Calendar, July Edition I

Hello Community! Welcome to another month of Community Content Calendar series! For the month of July, we will ...