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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...