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!

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...