Splunk Search

How to read data from a CSV file and put into DB Connect’s query?

ritesh21aggarwa
Engager

Hi,

I want to pull data from a CSV file and put that all data in a SQL query.
For e.g.-
In CSV:
'ABC','DEF','GHI','JKL','MNO'
SQL QUERY:
SELECT emp_name FROM emp WHERE emp_name IN ('ABC','DEF','GHI','JKL','MNO')

I want these “emp_name” get into my SQL query form CSV automatically.

Please help me on this.

Regards,
Ritesh Aggarwal

Tags (1)

jcoates_splunk
Splunk Employee
Splunk Employee

try putting the database query command into a map command. I just messed around with this on DBX2, appears to work well:

state="WA" OR state="CA" | map search="|dbxquery query=\"SELECT%20*%20FROM%20%60northwind%60.%60employees%60%20WHERE%20Region%3D%22$state$%22\" connection=\"dbx-mysql\""

I used this page to url encode: http://meyerweb.com/eric/tools/dencoder/

Forgot to mention -- this will be wicked slow and may make your DBA angry because it's calling that sql command over and over again. If you're going to do this in production, you should just index or lookup your database table and then do the whole job in SPL.

0 Karma
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...