Splunk Search

Splunk DB Connect 1: Why running a dbquery search using a python script is not returning results?

srinathd
Contributor

I am trying to run a dbquery search using below python script, but it is not giving any results. i don't know what is the issue in the below script. Please check and let me know.

#!/bin/python

import urllib, urllib2
from xml.dom import minidom

base_url = 'https://localhost:8089'
username = 'test'
password = 'password'
search_query = '|dbquery ET_AMS limit=2 "select PartitionId,PartitionStartTime,Status from Partition'

# Login and get the session key
request = urllib2.Request(base_url + '/servicesNS/%s/search/auth/login' % (username),
    data = urllib.urlencode({'username': username, 'password': password}))
server_content = urllib2.urlopen(request)

session_key = minidom.parseString(server_content.read()).\
        getElementsByTagName('sessionKey')[0].childNodes[0].nodeValue
print "Session Key: %s" % session_key

# Perform a search
request = urllib2.Request(base_url + '/servicesNS/%s/search/search/jobs/export' % (username),
    data = urllib.urlencode({'search': search_query,'output_mode': 'csv'}),
    headers = { 'Authorization': ('Splunk %s' %session_key)})
search_results = urllib2.urlopen(request)
print search_results.read()
0 Karma
1 Solution

srinathd
Contributor

select statement not ended with " properly. After the modification it is working fine.
search_query = '|dbquery ET_AMS limit=2 "select PartitionId,PartitionStartTime,Status from Partition"'

View solution in original post

0 Karma

srinathd
Contributor

select statement not ended with " properly. After the modification it is working fine.
search_query = '|dbquery ET_AMS limit=2 "select PartitionId,PartitionStartTime,Status from Partition"'

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...