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!

Splunk Observability Cloud's AI Assistant in Action Series: Auditing Compliance and ...

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

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...