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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...