Getting Data In

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

dominiquevocat
Motivator

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
Motivator

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
Motivator

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!

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 ...