All Apps and Add-ons

How do I capture dbquery errors in python sdk

yelkey
Explorer

Hi,

I am trying to dispatch my savedsearch with dbquery and dboutput commands using rest api in a python script as given below and extracting the status such as count, isFailed, results, isDone etc.

  • Python Script

kwargs_params={"key1":"value1","key2":"value2"}
job = mysavedsearch.dispatch(**kwargs_params)

while True:
job.refresh()
stats = {"isDone": job["isDone"],
"isFailed":int(job["isFailed"]),
"doneProgress": float(job["doneProgress"])*100,
"scanCount": int(job["scanCount"]),
"eventCount": int(job["eventCount"]),
"resultCount": int(job["resultCount"])}
status = ("\r%(doneProgress)03.1f%% %(scanCount)d scanned "
"%(eventCount)d matched %(resultCount)d results %(isFailed)d failedstatus ") % stats

  • Actual query

index=ABC|mysearch| table a, b, c, d, e
|dboutput database=XXX type=sql "INSERT INTO xyz
(v,w,x,y,z)
VALUES
($$a$$, $$b$$, $$c$$, $$d$$, $$e$$)"

But I am not able to capture the error caused by the db statements. As an example,I am not able to capture dboutput error such as "unique constraints violated". When I look at the job log under "inspect job" in splunk GUI, the error is part of the raw log and not the "search job properties" which is returned by the rest api endpoints. is there a way to capture such errors?
Appreciate all the help! Thanks!

Tags (3)
0 Karma
1 Solution

yelkey
Explorer

Hi,

Found a fix. In addition to the stats mentioned above(isFailed, isDone, resultCount etc..), I was able to retrieve another key "messages",
stats={"messages":job["messages"]} which returns the error messages.

Thanks all!

View solution in original post

0 Karma

yelkey
Explorer

Hi,

Found a fix. In addition to the stats mentioned above(isFailed, isDone, resultCount etc..), I was able to retrieve another key "messages",
stats={"messages":job["messages"]} which returns the error messages.

Thanks all!

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...