Getting Data In

is it possible to have a custom command return json to splunk?

dominiquevocat
SplunkTrust
SplunkTrust

I have a RESTful webservice which returns me a fairly complex json. I wish to pass it as-is to splunk and hope for splunk toparse it into key=value pairs.

What do i have to do? I can not seem to find a sample 😕

Tags (2)
0 Karma
1 Solution

dominiquevocat
SplunkTrust
SplunkTrust

Surprisingly simple....

url="https://xxx/wapi/xxx"
values={'ip_address' : ipfield}
data = urllib.urlencode(values)

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, USERNAME, PASSWORD)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
req = urllib2.Request(url, data)
pagehandle = urllib2.urlopen(req)

results=json.loads(pagehandle.read())
splunk.Intersplunk.outputResults( results )

View solution in original post

dominiquevocat
SplunkTrust
SplunkTrust

Surprisingly simple....

url="https://xxx/wapi/xxx"
values={'ip_address' : ipfield}
data = urllib.urlencode(values)

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, USERNAME, PASSWORD)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
req = urllib2.Request(url, data)
pagehandle = urllib2.urlopen(req)

results=json.loads(pagehandle.read())
splunk.Intersplunk.outputResults( results )
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...