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!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...