Splunk Search

Use db results in splunk search

dfredell
Explorer

Hello, I want to use the results of my dbquery as search strings in the log files.

Currently I am running two different Splunk searches then copy find/replace and pasting the result from 1 to 2.
1:
|dbquery JiraDB "SELECT TOP 1000 [ID] FROM [jiraDB].[JIRA].[searchrequest] where [USERNAME] = 'dfredell'"

2:
sourcetype=access_log "14196" OR "17516" OR "17525" OR .....

The output from 1 has 300 items and looks like:

ID


14196

17516

17525

...

The data in access_log is a standard Apache Web Log and I am searching for the url to contain any of the ID values.

0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Try this:

sourcetype=access_log [dbquery JiraDB "SELECT TOP 1000 [ID] FROM [jiraDB].[JIRA].[searchrequest] where [USERNAME] = 'dfredell'" | return 1000 $ID]

That will turn the results from the dbquery into an OR'd list of your ID values and use it to filter the access_log search.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

Try this:

sourcetype=access_log [dbquery JiraDB "SELECT TOP 1000 [ID] FROM [jiraDB].[JIRA].[searchrequest] where [USERNAME] = 'dfredell'" | return 1000 $ID]

That will turn the results from the dbquery into an OR'd list of your ID values and use it to filter the access_log search.

martin_mueller
SplunkTrust
SplunkTrust

Without that $ it'll generate a filter like this:

( ( ID=value1 ) OR ( ID=value2 ) OR ... )

...which fails because you're looking for strings appearing somewhere in your events rather than values of a field called ID.

0 Karma

dfredell
Explorer

Wow that was perfect thank you! I had tried that before, I guess all I was missing was the '$' on ID.

0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...