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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...