Reporting

Splunk DB Connect 1: Can I run dbquery with a variable?

stepheneardley
Explorer

I need to schedule a report which runs dbquery, but I need that report to run with a variable in the query e.g.

| eval myVar=stuff
| dbquery source "select * from table where timestamp >= '".myVar."'"

Or something like that, but of course this doesn't work since dbquery must be the first command of a search.

Has anyone come across this before or found a way around it?

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

You can try like this (using map command)

| gentimes start=-1 | eval myVar=stuff | map search="| dbquery source \"select * from tble where timestamp >= $myVar$ \" "

View solution in original post

0 Karma

somesoni2
SplunkTrust
SplunkTrust

You can try like this (using map command)

| gentimes start=-1 | eval myVar=stuff | map search="| dbquery source \"select * from tble where timestamp >= $myVar$ \" "
0 Karma

stepheneardley
Explorer

Worked a treat. Thanks. I can't figure out what gentimes is used for though.

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 ...