Splunk Search

Iterate through dbxquery (SQL) results?

lukenorthern
Engager

Hello

I have a search which is gathering 8 columns from a table. (below)

I want to make col1 available to query against later in the SPL. I tried to access via "rename query.col1 as col1" for example but the data does not seem to appear, almost as if query.col1 is not valid? Can't find any info on how to remedy this elsewhere on the site, apologies if this has been asked before. The query returns 1 row.

 

 

 

 

 

 

| dbxquery query="Select col1,col2,col3,col4,col5,col6,col7,col8 from JuiceTable
where col1 = 'special value'" connection="Juice-Prod"
| stats count as total
| eval Status=case(total=0,"Healthy",total > 0, "Critical")

 

 

 

 

 

 




0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| eval Description=col1." - This alert monitors Juice"

If you real col1 contains special characters, then wrap it in single (not double) quotes

| eval Description='col1'." - This alert monitors Juice"

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

The field names are the same as the column names.  No rename is needed.  In this example, it's just "col1".

"query" is the name of an argument to the dbxquery command.  It's not an object.

---
If this reply helps you, Karma would be appreciated.

ITWhisperer
SplunkTrust
SplunkTrust

The stats command will reduce the event pipeline to a single event with one field (total). If you want more fields, you will have to modify the stats command

| stats count as total by col1

However, this will give you an event (row) for each value of col1, not the total number of events.

Alternatively, you could filter the events before the stats command

| where col1="some value"
| stats count as total

lukenorthern
Engager

Thanks for taking the time to respond @ITWhisperer  !

Great, and if I wanted to take that col1 value and say, include it in an evaluated field called description, how would I compile that?

e.g. below just produces col1 as plain text, rather than the actual value from the query

| eval Description="col1"." - "."This alert monitors Juice"

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| eval Description=col1." - This alert monitors Juice"

If you real col1 contains special characters, then wrap it in single (not double) quotes

| eval Description='col1'." - This alert monitors Juice"
Get Updates on the Splunk Community!

Uncovering Multi-Account Fraud with Splunk Banking Analytics

Last month, I met with a Senior Fraud Analyst at a nationally recognized bank to discuss their recent success ...

Secure Your Future: A Deep Dive into the Compliance and Security Enhancements for the ...

What has been announced?  In the blog, “Preparing your Splunk Environment for OpensSSL3,”we announced the ...

New This Month in Splunk Observability Cloud - Synthetic Monitoring updates, UI ...

This month, we’re delivering several platform, infrastructure, application and digital experience monitoring ...