Splunk Search

DBQUERY correlation -- How to join results from DB

shangshin
Builder

Hi,
I get the user_id info from web log and would like to enrich data from the connected DB in Splunk. I tried the search query below but it didn't work. Can anyone provide the right syntax?

index=web_access_log | table user_id | RENAME user_id AS web_user_id [ search dbquery USER_SQL_DB "select web_user_id, user_type, user_email, user_phone from user_profile_view_all where web_user_id=$web_user_id$ "]
1 Solution

somesoni2
Revered Legend

Try this (using map command)

index=web_access_log | table user_id | map maxsearches=100 search="| dbquery USER_SQL_DB \"select web_user_id, user_type, user_email, user_phone from user_profile_view_all where web_user_id=$user_id$ \""

martin_mueller
SplunkTrust
SplunkTrust

You can use any number of field names you like.

Did you look at database lookups? It seems to me as if you're reimplementing those.

0 Karma

shangshin
Builder

It's working after adding the single quote for the variable. Is it possible to get more than one field value from the first query in the final result e.g. url?

e.g.

index=web_access_log | table user_id, url | map maxsearches=100 search="| dbquery USER_SQL_DB \"select web_user_id, user_type, user_email, user_phone from user_profile_view_all where web_user_id='$user_id$' \""

0 Karma

shangshin
Builder

Thanks for the response. I gave it a try and I can see s few events returned from the first query but no result is returned in the end.
I suspect the syntax needs to be polished up.....

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk, and empower your SOC to reach new heights! Duration: 1 hour  Prepare to ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...