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!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...